Skip to content

Commit

Permalink
state preservation demo (not working yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
gschmidt committed Aug 9, 2012
1 parent 07113b6 commit 80c5e2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
48 changes: 31 additions & 17 deletions examples/landmark-demo/client/landmark-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function () {
return Session.get("x");
};

Template.stateDemo.y =
function () {
return Session.get("y");
};


Template.stateDemo.events = {
'click .create': function () {
Expand All @@ -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);
*/
};
1 change: 0 additions & 1 deletion examples/landmark-demo/landmark-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ <h2>Template callbacks</h2>
Y={{y}}
</div>
{{/each}}
Interval timers running: {{timersRunning}}
X={{x}}
</template>

Expand Down

0 comments on commit 80c5e2a

Please sign in to comment.