Meteor JS : How to make a helper method is triggered after a certain event?

When you want the tele of information are changed after some event or some operation you can use the Deps.Dependency.

You should put in your javascript file:

var  myDependencyVar = new Deps.Dependency ;

You should place in the event that will hold the responsible operation for later update other data:

myDependencyVar.changed ();

You must place in the helpers you want to be triggered again:

myDependencyVar.depend ();

Example:

I want whenever change the value selected in a input the buildNewValues function is called and the new values will render on the page.

var  newValueDep = new Deps.Dependency ;

Template.MyTemplate.events({
    "change .mySelect" : function(e) {
        e.preventDefault();
        buildNewValues(); 
        newValueDep.changed();
    },
Template.MyTemplate.helpers({
    'getAllValues': function(){
        newValueDep.depend()
        {...}

    },

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s