Kelvin U
Kelvin U

Reputation: 353

Meteor: How to make a helper function reactive?

I'm trying to get a helper to re-run and return the updated collection whenever this collection is updated.

For example:

Template.imagegallery.myimages = function() {

   return Images.find({owner: Meteor.userId()}).fetch(); 

}

When I add data to the Images via a Meteor.call on the server side, my collection updates locally on the client, but the helper function does not re-run and the images don't update.....

any idea what i need to do to put the return collection from the helper object into a re-active context?

Upvotes: 0

Views: 223

Answers (1)

Marco de Jongh
Marco de Jongh

Reputation: 5458

Return a cursor instead of a array:

Helper:

Template.imagegallery.myimages = function() {
   return Images.find({owner: Meteor.userId()});
}

Template:

<template name="imagegallery">
     {{#each myimages}}
           !!!DOSTUFF!!!
     {{/each}}
</template>

Fetch breaks reactivity in almost all cases. Because when you use fetch the Blaze only receives a array. So Blaze never creates the dependencies required for reactivity because it doesn't know that is data coming from a collection as that information is lost when you use fetch.

*Blaze is meteor's templating system

Upvotes: 1

Related Questions