mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Add some examples for onCreated and onDestroyed
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user