From 80c5e2a5caa078f2516b530560764d1a23f2d9b9 Mon Sep 17 00:00:00 2001 From: Geoff Schmidt Date: Wed, 8 Aug 2012 18:19:07 -0700 Subject: [PATCH] state preservation demo (not working yet) --- .../landmark-demo/client/landmark-demo.js | 48 ++++++++++++------- examples/landmark-demo/landmark-demo.html | 1 - 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/examples/landmark-demo/client/landmark-demo.js b/examples/landmark-demo/client/landmark-demo.js index 26078bf8f1a..faf9900c121 100644 --- a/examples/landmark-demo/client/landmark-demo.js +++ b/examples/landmark-demo/client/landmark-demo.js @@ -35,6 +35,11 @@ function () { return Session.get("x"); }; +Template.stateDemo.y = +function () { + return Session.get("y"); +}; + Template.stateDemo.events = { 'click .create': function () { @@ -46,36 +51,45 @@ Template.stateDemo.timers = function () { return Timers.find(); }; -Template.stateDemo.timersRunning = function () { - return Session.get("timersRunning"); -}; - Template.timer.events = { 'click .delete': function () { Timers.remove(this._id); } }; +Template.timer.z = function () { + return Session.get("z"); +}; + Template.timer.create = function () { - /* - this.when = new Date(); - this.node = null; - this.timer = setInterval(function () { - }, 500); - Session.set("timersRunning", (Session.get("timersRunning") || 0) + 1); - */ + var self = this; + console.log("timer create"); + self.elapsed = 0; + self.node = null; + self.update = function () { + self.node.innerHTML = self.elapsed + " second" + + ((self.elapsed === 1) ? "" : "s"); + } }; Template.timer.render = function (landmark) { -/* - this.node = landmark.findOne(".elapsed"); -*/ + var self = this; + console.log("timer render"); + self.node = landmark.find(".elapsed"); + self.update(); + + if (! self.timer) { + var tick = function () { + self.elapsed++; + self.timer = setTimeout(tick, 1000); + self.update(); + }; + tick(); + } }; Template.timer.destroy = function () { -/* + console.log("timer destroy"); clearInterval(this.timer); - Session.set("timersRunning", (Session.get("timersRunning") || 0) - 1); - */ }; diff --git a/examples/landmark-demo/landmark-demo.html b/examples/landmark-demo/landmark-demo.html index fb2d193bf40..4547d3a963f 100644 --- a/examples/landmark-demo/landmark-demo.html +++ b/examples/landmark-demo/landmark-demo.html @@ -50,7 +50,6 @@

Template callbacks

Y={{y}} {{/each}} - Interval timers running: {{timersRunning}} X={{x}}