Skip to content

Commit c9a8049

Browse files
committed
Spark.list: moved,removed call rendered()
1 parent a17b2e4 commit c9a8049

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/spark/spark.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,18 @@ Spark.list = function (cursor, itemFunc, elseFunc) {
872872
if (! renderer)
873873
cleanup();
874874

875+
// Called by `removed` and `moved` in order to cause render callbacks on
876+
// parent landmarks.
877+
// XXX This is not the final solution. 1) This code should be unified
878+
// with the code in scheduleOnscreenSetup. 2) In general, lists are
879+
// going to cause a lot of callbacks (one per collection callback).
880+
// Maybe that will make sense if we give render callbacks subrange info.
881+
var notifyParentsRendered = function () {
882+
var walk = outerRange;
883+
while ((walk = findParentOfType(Spark._ANNOTATION_LANDMARK, walk)))
884+
walk.renderCallback.call(walk.landmark);
885+
};
886+
875887
// The DOM update callbacks.
876888
_.extend(callbacks, {
877889
added: function (item, beforeIndex) {
@@ -902,6 +914,8 @@ Spark.list = function (cursor, itemFunc, elseFunc) {
902914
Spark.finalize(itemRanges[atIndex].extract());
903915

904916
itemRanges.splice(atIndex, 1);
917+
918+
notifyParentsRendered();
905919
});
906920
},
907921

@@ -918,6 +932,8 @@ Spark.list = function (cursor, itemFunc, elseFunc) {
918932
itemRanges[newIndex].insertBefore(frag);
919933

920934
itemRanges.splice(newIndex, 0, range);
935+
936+
notifyParentsRendered();
921937
});
922938
},
923939

packages/templating/templating_tests.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ Tinytest.add("templating - #each render callback", function (test) {
769769
entries.remove({x:'a'});
770770
test.equal(buf, []);
771771
Meteor.flush();
772-
test.expect_fail();
773772
test.equal(buf, ['<div>b</div><div>c</div><div>d</div>']);
774773
buf.length = 0;
775774

776775
// moved/changed
777776
entries.update({x:'b'}, {$set: {x: 'z'}});
778777
test.equal(buf, []);
779778
Meteor.flush();
780-
test.equal(buf, ['<div>c</div><div>d</div><div>z</div>']);
779+
test.equal(buf, ['<div>c</div><div>d</div><div>z</div>',
780+
'<div>c</div><div>d</div><div>z</div>']);
781781
buf.length = 0;
782782

783783
// test pure "moved"
@@ -816,7 +816,6 @@ Tinytest.add("templating - #each render callback", function (test) {
816816
Meteor.flush();
817817
test.equal(div.html().replace(/\s/g, ''),
818818
'<div>b</div><div>c</div><div>a</div>');
819-
test.expect_fail();
820819
test.equal(buf, ['<div>b</div><div>c</div><div>a</div>']);
821820
buf.length = 0;
822821

0 commit comments

Comments
 (0)