Template instance helpers

Hey,

is there a way to run a helper only once per template instance?

I have a helper which returns a random value from a array in a list
when i now add a item to the list the helper gets called for every template instance again.
But it should be only called for the new template instance.

Any advice ?

template.onCreated(function () {
  this.getRandomValue = _.memoize(function () { ... });
});

template.helpers({
  myHelper: function () {
    return Template.instance().getRandomValue();
  }
});
2 Likes