Skip to content

Commit

Permalink
Merge pull request canjs#936 from bitovi/list-expandos-744
Browse files Browse the repository at this point in the history
fixes list expandos and live binding by preventing add events on expandos
  • Loading branch information
justinbmeyer committed May 1, 2014
2 parents e0a3386 + 1a28a37 commit 1e125bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,18 @@ steal("can/util", "can/map", "can/map/bubble.js",function (can, Map, bubble) {

Map.prototype._triggerChange.apply(this, arguments);
// `batchTrigger` direct add and remove events...
if (!~attr.indexOf('.')) {
var index = +attr;
// Make sure this is not nested and not an expando
if (!~attr.indexOf('.') && !isNaN(index)) {

if (how === 'add') {
can.batch.trigger(this, how, [newVal, +attr]);
can.batch.trigger(this, how, [newVal, index]);
can.batch.trigger(this, 'length', [this.length]);
} else if (how === 'remove') {
can.batch.trigger(this, how, [oldVal, +attr]);
can.batch.trigger(this, how, [oldVal, index]);
can.batch.trigger(this, 'length', [this.length]);
} else {
can.batch.trigger(this, how, [newVal, +attr]);
can.batch.trigger(this, how, [newVal, index]);
}

}
Expand Down
19 changes: 19 additions & 0 deletions view/mustache/mustache_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3656,4 +3656,23 @@ steal("can/model", "can/view/mustache", "can/test", "can/view/mustache/spec/spec
data.attr("show", true);
equal(frag.childNodes[0].innerHTML, "Is showing", "Not showing the else");
});

test("Expandos (#744)", function(){
var template = can.mustache("{{#each items}}<div>{{name}}</div>{{/each}}"+
"{{#if items.spliced}}<strong>List was spliced</strong>{{/if}}");
var items = new can.List([
{ name: 1}
]);

var frag = template({
items: items
});
//items.splice(0,2);
items.attr('spliced', true);
// 2 because {{#each}} keeps a textnode placeholder
equal(frag.childNodes[2].nodeName.toLowerCase(),"strong", "worked");
});



});

0 comments on commit 1e125bf

Please sign in to comment.