From 25b9bb79b0301f2be3b6544e76a43490ee65a4ce Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 1 May 2014 10:10:22 -0500 Subject: [PATCH 1/2] fixes #744 by preventing add events on expandos --- list/list.js | 10 ++++++---- view/mustache/mustache_test.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/list/list.js b/list/list.js index df56ad79d7d..53fe1230f3b 100644 --- a/list/list.js +++ b/list/list.js @@ -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]); } } diff --git a/view/mustache/mustache_test.js b/view/mustache/mustache_test.js index a4e700db98f..7a2bb59ac80 100644 --- a/view/mustache/mustache_test.js +++ b/view/mustache/mustache_test.js @@ -3626,4 +3626,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}}
{{name}}
{{/each}}"+ + "{{#if items.spliced}}List was spliced{{/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"); + }); + + + }); From 1a28a37c6143b7a1fe3993ef40b6edc84660191a Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 1 May 2014 16:13:28 -0500 Subject: [PATCH 2/2] fixes lint --- view/mustache/mustache_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/mustache/mustache_test.js b/view/mustache/mustache_test.js index 7a2bb59ac80..b0d55d1ec9b 100644 --- a/view/mustache/mustache_test.js +++ b/view/mustache/mustache_test.js @@ -3631,7 +3631,7 @@ steal("can/model", "can/view/mustache", "can/test", "can/view/mustache/spec/spec var template = can.mustache("{{#each items}}
{{name}}
{{/each}}"+ "{{#if items.spliced}}List was spliced{{/if}}"); var items = new can.List([ - { name: 1} + { name: 1} ]); var frag = template({