From 46238fd47371e2bcc05447e8b6ea658ff84ea79f Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Wed, 1 Aug 2012 18:34:32 -0700 Subject: [PATCH] table fixes and tests --- packages/liveui/liveui_tests.js | 88 ++------------------------------- packages/spark/spark.js | 14 ++++++ packages/spark/spark_tests.js | 86 ++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 85 deletions(-) diff --git a/packages/liveui/liveui_tests.js b/packages/liveui/liveui_tests.js index f4fef0f5f7..bb52d37d8d 100644 --- a/packages/liveui/liveui_tests.js +++ b/packages/liveui/liveui_tests.js @@ -31,95 +31,13 @@ var legacyLabels = { Tinytest.add("liveui - tables", function(test) { - var R = ReactiveVar(0); - var table = OnscreenDiv(Meteor.ui.render(function() { - var buf = []; - buf.push(""); - for(var i=0; i"); - buf.push("
"+(i+1)+"
"); - return buf.join(''); - })); - - R.set(1); - Meteor.flush(); - test.equal(table.html(), "
1
"); - - R.set(10); - test.equal(table.html(), "
1
"); - Meteor.flush(); - test.equal(table.html(), ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - "
1
2
3
4
5
6
7
8
9
10
"); - - R.set(0); - Meteor.flush(); - test.equal(table.html(), "
"); - table.kill(); - Meteor.flush(); - test.equal(R.numListeners(), 0); - - var div = OnscreenDiv(); - div.node().appendChild(document.createElement("TABLE")); - div.node().firstChild.appendChild(Meteor.ui.render(function() { - var buf = []; - for(var i=0; i"+(i+1)+""); - return buf.join(''); - })); - test.equal(div.html(), "
"); - R.set(3); - Meteor.flush(); - test.equal(div.html(), ""+ - ""+ - ""+ - ""+ - "
1
2
3
"); - test.equal(div.node().firstChild.rows.length, 3); - R.set(0); - Meteor.flush(); - test.equal(div.html(), "
"); - div.kill(); - Meteor.flush(); - - test.equal(R.numListeners(), 0); - - div = OnscreenDiv(); - div.node().appendChild(DomUtils.htmlToFragment("
")); - R.set(3); - div.node().getElementsByTagName("tr")[0].appendChild(Meteor.ui.render( - function() { - var buf = []; - for(var i=0; i"+(i+1)+""); - return buf.join(''); - })); - test.equal(div.html(), - ""+ - "
123
"); - R.set(1); - Meteor.flush(); - test.equal(div.html(), - "
1
"); - div.kill(); - Meteor.flush(); - test.equal(R.numListeners(), 0); + var R = ReactiveVar(""); // Test tables with patching - R.set(""); - div = OnscreenDiv(Meteor.ui.render(function() { + var div = OnscreenDiv(Meteor.ui.render(function() { return ''+R.get()+'
'; - })); + }, {preserve: legacyLabels})); Meteor.flush(); R.set("Hello"); Meteor.flush(); diff --git a/packages/spark/spark.js b/packages/spark/spark.js index fd610d916d..fa86ff3f1f 100644 --- a/packages/spark/spark.js +++ b/packages/spark/spark.js @@ -308,6 +308,20 @@ Spark.isolate = function (htmlFunc) { var frag = Spark.render(function () { return Spark.isolate(htmlFunc); }); + + var tempRange = new LiveRange(Spark._ANNOTATION_ISOLATE, frag, null, + true /* inner */); + tempRange.operate(function (start, end) { + // Wrap contents of frag, *inside* the ISOLATE annotation, + // as appropriate for insertion into `range`. We want the + // wrapping inside the range so that if you have a + // containing an isolate, and the isolate returns a + // sometimes and a other times, the wrapping will + // change as appropriate. + DomUtils.wrapFragmentForContainer(frag, range.containerNode()); + }); + tempRange.destroy(); + var oldContents = range.replace_contents(frag); // XXX should patch Spark.finalize(oldContents); notifyWatchers(range); diff --git a/packages/spark/spark_tests.js b/packages/spark/spark_tests.js index 9615b608a9..daaa158487 100644 --- a/packages/spark/spark_tests.js +++ b/packages/spark/spark_tests.js @@ -478,3 +478,89 @@ Tinytest.add("spark - data context", function (test) { ""); }); }); + +Tinytest.add("spark - tables", function (test) { + var R = ReactiveVar(0); + + var table = OnscreenDiv(Meteor.render(function() { + var buf = []; + buf.push("
"); + for(var i=0; i"); + buf.push("
"+(i+1)+"
"); + return buf.join(''); + })); + + R.set(1); + Meteor.flush(); + test.equal(table.html(), "
1
"); + + R.set(10); + test.equal(table.html(), "
1
"); + Meteor.flush(); + test.equal(table.html(), ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + "
1
2
3
4
5
6
7
8
9
10
"); + + R.set(0); + Meteor.flush(); + test.equal(table.html(), "
"); + table.kill(); + Meteor.flush(); + test.equal(R.numListeners(), 0); + + var div = OnscreenDiv(); + div.node().appendChild(document.createElement("TABLE")); + div.node().firstChild.appendChild(Meteor.render(function() { + var buf = []; + for(var i=0; i"+(i+1)+""); + return buf.join(''); + })); + test.equal(div.html(), "
"); + R.set(3); + Meteor.flush(); + test.equal(div.html(), ""+ + ""+ + ""+ + ""+ + "
1
2
3
"); + test.equal(div.node().firstChild.rows.length, 3); + R.set(0); + Meteor.flush(); + test.equal(div.html(), "
"); + div.kill(); + Meteor.flush(); + + test.equal(R.numListeners(), 0); + + div = OnscreenDiv(); + div.node().appendChild(DomUtils.htmlToFragment("
")); + R.set(3); + div.node().getElementsByTagName("tr")[0].appendChild(Meteor.render( + function() { + var buf = []; + for(var i=0; i"+(i+1)+""); + return buf.join(''); + })); + test.equal(div.html(), + ""+ + "
123
"); + R.set(1); + Meteor.flush(); + test.equal(div.html(), + "
1
"); + div.kill(); + Meteor.flush(); + test.equal(R.numListeners(), 0); +}); \ No newline at end of file