Last active
December 31, 2015 03:29
-
-
Save Torsten85/7928276 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
if (Meteor.isClient) { | |
Items = new Meteor.Collection('items', {connection: null, transform: function (doc) { | |
doc.render = function () { | |
console.log('rendered ' + this.name); | |
return 'rendered ' + this.name; | |
}; | |
return doc; | |
}}); | |
// insert dummy data | |
var itemId = Items.insert({name: 'itemA'}); | |
Template['templateA'].items = function () { | |
return Items.find({}); | |
}; | |
Template['templateA'].rendered = function () { | |
console.log('rendered TemplateA'); | |
}; | |
Template['templateA'].destroyed = function () { | |
console.log('destroyed TemplateA'); | |
}; | |
Session.set('templateName', 'templateA'); | |
UI.body.template = function () { | |
console.log('giving template'); | |
var template = Template[Session.get('templateName')]; | |
return template && template.withData({renderedAt: Date.now()}); | |
}; | |
setInterval(function () { | |
// Updating collection to trigger invalidation of cursor | |
Items.update(itemId, {$set: {chaned: Date.now()}}); | |
}, 1000); | |
setTimeout(function () { | |
// Destroying Template, should stop observing | |
Session.set('templateName', 'bogus'); | |
}, 1500); | |
} |
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>each</title> | |
</head> | |
<body> | |
{{> template}} | |
</body> | |
<template name="templateA"> | |
Rendered At: {{renderedAt}} <br><br> | |
{{item.name}} <br> {{item.render}} | |
{{#each items}} | |
{{this.name}} <br> {{this.render}} <br><br> | |
{{/each}} | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment