Skip to content

Commit 05444bb

Browse files
committed
landmark render callbacks bubble up
1 parent b4ccc65 commit 05444bb

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

examples/landmark-demo/client/landmark-demo.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ Template.stateDemo.timers = function () {
7070
};
7171

7272
Template.timer.events = {
73+
'click .reset': function () {
74+
// XXX need to get the template state object
75+
// XXX also probably need to have the landmark available..
76+
Timers.remove(this._id);
77+
},
7378
'click .delete': function () {
7479
Timers.remove(this._id);
7580
}

examples/landmark-demo/landmark-demo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ <h2>Template callbacks</h2>
6161

6262
<template name="timer">
6363
<span class="elapsed"></span>
64+
<input type="button" value="Reset" class="reset">
6465
<input type="button" value="Delete" class="delete">
6566
Z={{z}}
6667
</template>

packages/spark/spark.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
// XXX should functions with an htmlFunc use try/finally inside?
2020

21-
// XXX do render callbacks "bubble up" to enclosing landmarks?
21+
// XXX test that render callbacks bubble up to enclosing landmark
22+
// (code is written, needs a test)
2223

2324
(function() {
2425

@@ -324,14 +325,24 @@ var scheduleOnscreenSetup = function (frag, landmarkRanges) {
324325

325326
// Deliver render callbacks to all landmarks that are now
326327
// onscreen (possibly not for the first time.)
327-
//
328-
// XXX should bubble up and notify parent landmarks too? for all
329-
// the same reasons we need to do it for node preservation?
330328
_.each(landmarkRanges, function (landmarkRange) {
331329
if (! landmarkRange.isPreservedConstant)
332330
landmarkRange.renderCallback.call(landmarkRange.landmark);
333331
});
334332

333+
// Deliver render callbacks to all landmarks that enclose the
334+
// updated region.
335+
//
336+
// XXX unify with notifyWatchers. maybe remove _ANNOTATION_WATCH
337+
// and just give everyone a contentsModified callback (sibling to
338+
// 'finalize')
339+
//
340+
// future: include an argument in the callback to distinguish this
341+
// case from the previous
342+
var walk = renderedRange;
343+
while ((walk = findParentOfType(Spark._ANNOTATION_LANDMARK, walk)))
344+
walk.renderCallback.call(walk.landmark);
345+
335346
// This code can run several times on the same nodes (if the
336347
// output of a render is included in a render), so it must be
337348
// idempotent. This is not the best, asymptotically. There are

0 commit comments

Comments
 (0)