Skip to content

Commit b673b23

Browse files
committed
Merge pull request #612 from jccazeaux/nested-if-dont-correctly-rebind
Set bound to false when unbinding 'if' binder
2 parents 666c56a + 89bc2c3 commit b673b23

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

spec/rivets/binders.js

+18
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ describe("Rivets.binders", function() {
199199
// 1 for the comment placeholder
200200
Should(fragment.childNodes.length).be.exactly(1);
201201
});
202+
203+
it("rebindes nested if", function() {
204+
var nestedEl = document.createElement("div")
205+
nestedEl.setAttribute("rv-if", "data.showNested");
206+
nestedEl.innerHTML = "{ data.countNested }";
207+
el.appendChild(nestedEl);
208+
209+
var view = rivets.bind(fragment, model);
210+
211+
model.data.countNested = "1";
212+
model.data.showNested = true;
213+
Should(nestedEl.innerHTML).be.exactly("1");
214+
model.data.show = false;
215+
model.data.show = true;
216+
model.data.countNested = "42";
217+
218+
Should(nestedEl.innerHTML).be.exactly("42");
219+
});
202220
});
203221

204222
describe("Custom binder with no attribute value", function() {

src/binders.coffee

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ Rivets.public.binders.if =
111111
el.parentNode.removeChild el
112112

113113
unbind: ->
114-
@nested?.unbind()
114+
if @nested
115+
@nested.unbind()
116+
@bound = false
115117

116118
routine: (el, value) ->
117119
if !!value is not @bound

0 commit comments

Comments
 (0)