From b482c449d30f65ce2859e16d04eb28b123cc1fe3 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Fri, 13 Dec 2013 17:47:50 -0800 Subject: [PATCH] Test that #each stops its cursors when removed --- packages/observe-sequence/observe_sequence.js | 2 ++ packages/spacebars-tests/template_tests.html | 6 ++++++ packages/spacebars-tests/template_tests.js | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/packages/observe-sequence/observe_sequence.js b/packages/observe-sequence/observe_sequence.js index e2c5a0c8d7..6c109653d3 100644 --- a/packages/observe-sequence/observe_sequence.js +++ b/packages/observe-sequence/observe_sequence.js @@ -125,6 +125,8 @@ ObserveSequence = { return { stop: function () { computation.stop(); + if (activeObserveHandle) + activeObserveHandle.stop(); } }; }, diff --git a/packages/spacebars-tests/template_tests.html b/packages/spacebars-tests/template_tests.html index b7ba4e2bfa..36808c8fa9 100644 --- a/packages/spacebars-tests/template_tests.html +++ b/packages/spacebars-tests/template_tests.html @@ -263,3 +263,9 @@ {{foo}} {{bar}} {{/with}} + + diff --git a/packages/spacebars-tests/template_tests.js b/packages/spacebars-tests/template_tests.js index ab86af0bcc..18e825162e 100644 --- a/packages/spacebars-tests/template_tests.js +++ b/packages/spacebars-tests/template_tests.js @@ -821,3 +821,21 @@ Tinytest.add('spacebars - templates - with someData', function (test) { test.equal(someDataRuns, 1); test.equal(trim(stripComments(div.innerHTML)), 'CCC YO'); }); + +Tinytest.add('spacebars - template - #each stops when rendered element is removed', function (test) { + var tmpl = Template.spacebars_template_test_each_stops; + var coll = new Meteor.Collection(null); + coll.insert({}); + tmpl.items = function () { return coll.find(); }; + + var div = renderToDiv(tmpl); + divRendersTo(test, div, 'x'); + + // trigger #each component destroyed + $(div).remove(); + + // insert another document. cursor should no longer be observed so + // should have no effect. + coll.insert({}); + divRendersTo(test, div, 'x'); +}); \ No newline at end of file