From 14bce609c98fefc668f56209d1bf6ab8a1973d4b Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Sat, 21 Mar 2015 21:46:11 -0700 Subject: [PATCH] Add some examples for onCreated and onDestroyed --- docs/client/full-api/api/templates.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/client/full-api/api/templates.md b/docs/client/full-api/api/templates.md index ff355e602e..99cdf18dc8 100644 --- a/docs/client/full-api/api/templates.md +++ b/docs/client/full-api/api/templates.md @@ -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); +}); +``` +

Template instances