Spark.isolate re-renders

This commit is contained in:
David Greenspan
2012-07-27 18:08:48 -07:00
parent e6de65be76
commit b930748001
2 changed files with 31 additions and 0 deletions

View File

@@ -136,6 +136,15 @@ Spark.isolate = function (htmlFunc) {
renderer.annotate(ctx.run(htmlFunc), "_isolate", function (range) {
ctx.on_invalidate(function () {
// XXX update with patching
var frag = Spark.render(function () {
return Spark.isolate(htmlFunc);
});
var oldContents = range.replace_contents(frag); // (should patch)
range.destroy();
// (GC oldContents)
// later:
// GC, rewire, patching, etc.
});
});

View File

@@ -64,3 +64,25 @@ Tinytest.add("spark - assembly", function (test) {
test.isTrue(attrValue.indexOf('abc<!--') === 0, attrValue);
test.isTrue(attrValue.indexOf('-->xyz') >= 0, attrValue);
});
Tinytest.add("spark - basic isolate", function (test) {
var R = ReactiveVar('foo');
var div = OnscreenDiv(Spark.render(function() {
return '<div>' + Spark.isolate(function() {
return '<span>' + R.get() + '</span>';
}) + '</div>';
}));
test.equal(div.html(), '<div><span>foo</span></div>');
R.set('bar');
test.equal(div.html(), '<div><span>foo</span></div>');
Meteor.flush();
test.equal(div.html(), '<div><span>bar</span></div>');
R.set('baz');
Meteor.flush();
test.equal(div.html(), '<div><span>baz</span></div>');
});