Created
July 7, 2013 07:55
-
-
Save Slava/5942742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>testappp</title> | |
</head> | |
<body> | |
{{> hello}} | |
</body> | |
<template name="hello"> | |
<h1>Hello World!</h1> | |
<ol> | |
{{#each top5Things}} | |
<li>{{this.x}}</li> | |
{{/each}} | |
</ol> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
things = new Meteor.Collection("things"); | |
if (Meteor.isClient) { | |
Deps.autorun(function () { | |
Session.set("top5", _.sortBy(things.find().fetch(), function (thing) { return thing.x; }).slice(0, 5)); | |
}); | |
Template.hello.top5Things = function () { | |
return Session.get("top5"); | |
}; | |
Template.hello.rendered = function () { | |
console.log(new Date); // this will print every time the template is rerendered | |
// if you see new log every two secs, it means it rerenders even if the result didn't change | |
// if you see new log every four secs, it is good :) | |
}; | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
things.remove({}); | |
// Pre populate data | |
_.times(5, function (x) { | |
things.insert({ x: x }); | |
}); | |
// Insert new thing every 2 seconds | |
var sign = -1; | |
var next = 6; | |
// Every *second* time (every 4 secs) the insert should trigger the rerender on client side | |
Meteor.setInterval(function () { | |
things.insert({ x: next*sign }); | |
sign *= -1; | |
next++; | |
}, 2 * 1000); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment