Skip to content

Commit

Permalink
Report fix for mikeric#650
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Christophe Cazeaux committed Oct 10, 2016
1 parent 784a5f4 commit 88eec5a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
59 changes: 56 additions & 3 deletions spec/rivets/binders.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ describe("Rivets.binders", function() {
nestedEl.setAttribute("rv-if", "data.showNested");
nestedEl.innerHTML = "{ data.countNested }";
el.appendChild(nestedEl);

var view = rivets.bind(fragment, model);

model.data.countNested = "1";
model.data.showNested = true;
Should(nestedEl.innerHTML).be.exactly("1");
model.data.show = false;
model.data.show = true;
model.data.countNested = "42";

Should(nestedEl.innerHTML).be.exactly("42");
});
});
Expand All @@ -251,4 +251,57 @@ describe("Rivets.binders", function() {
Should(el.children[0].innerHTML).be.exactly('received undefined');
});
});
describe('Array observe and unobserve', function() {
var fragment;
var el1;
var elEach;
var el2;
var el3;
var model;

beforeEach(function() {
/*
DOM for test
<div>
<div rv-if="scope.visible">
<div>
<div rv-each-item="scope.items">{item.data}</div>
</div>
</div>
<div>
<div rv-each-item="scope.items">{item.data}</div>
</div>
</div>
*/
fragment = document.createElement("div");
el1 = document.createElement("div");
el1.setAttribute("rv-if", "scope.visible");
el2 = document.createElement("div");
elEach = document.createElement("div");
elEach.setAttribute('rv-each-item', 'scope.items');
elEach.innerHTML = '{item.data}';
el2.appendChild(elEach);
el1.appendChild(el2);
el3 = document.createElement("div");
elEach = document.createElement("div");
elEach.setAttribute('rv-each-item', 'scope.items');
elEach.innerHTML = '{item.data}';
el3.appendChild(elEach);
fragment.appendChild(el1);
fragment.appendChild(el3);

model = { scope: {items: [], visible:true }};
});

it('observes array changes after another array binding is unbound', function() {
var view = rivets.bind(fragment, model);
model.scope.items.push({data:"data"});
Should(el3.childNodes.length).be.exactly(2);
model.scope.items.push({data:"data"});
Should(el3.childNodes.length).be.exactly(3);
model.scope.visible = false;
model.scope.items.push({data:"data"});
Should(el3.childNodes.length).be.exactly(4);
});
});
});
3 changes: 2 additions & 1 deletion src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ const adapter = {

if (!callbacks.length) {
delete map.callbacks[keypath]
this.unobserveMutations(obj[keypath], obj[this.id], keypath)
}
}

this.unobserveMutations(obj[keypath], obj[this.id], keypath)

this.cleanupWeakReference(map, obj[this.id])
}
}
Expand Down

0 comments on commit 88eec5a

Please sign in to comment.