Meteor - Quick Tips #2

Blaze Template Removal

Instead of using jQuery to perform DOM removal operations, Meteor’s Blaze remove can do the same thing with the following

Remove Element with Blaze
1
Blaze.remove(Template.instance().view);

The above can be ran in the Template’s render function or in a Template event handler. Most likely, the removal will take place in an event handler.

Attach Template’s Local Variables to Template Instance

Since all Templates files variables are encapsulated within a closure, there might be possibilities of memory leaks. To ensure that local variables are properly cleaned up, attached a data store object to the Template instance. When the Template instance is destroy so will all the references to it variables.

DataStore Object on Template Instance
1
2
3
4
5
6
7
8
var ds = {
thing1: 1,
thing2: 2
};

Template.myTemplate.created = function() {
this.ds = ds;
};