Add some examples for onCreated and onDestroyed

This commit is contained in:
Slava Kim
2015-03-21 21:46:11 -07:00
parent d332646a54
commit 14bce609c9

View File

@@ -120,6 +120,16 @@ These callbacks fire once and are the first group of callbacks to fire.
Handling the `created` event is a useful way to set up values on template
instance that are read from template helpers using `Template.instance()`.
```javascript
Template.myPictures.onCreated(function () {
// set up local reactive variables
this.dataVar = new ReactiveVar("some value");
// register this template within some central store
GalleryTemplates.push(this);
});
```
{{> autoApiBox "Template#onDestroyed"}}
These callbacks are called when an occurrence of a template is taken off
@@ -131,6 +141,15 @@ This group of callbacks is most useful for cleaning up or undoing any external
effects of `created` or `rendered` groups. This group fires once and is the last
callback to fire.
```javascript
Template.myPictures.onDestroyed(function () {
// deregister from some central store
var positionInStore = GalleryTemplates.indexOf(this);
if (positionInStore !== -1)
GalleryTemplates.splice(positionInStore, 1);
});
```
<h2 id="template_inst"><span>Template instances</span></h2>