helpers

Use this method to define Meteor collections that will be reactive throughout the entire reactive context life.

The parameter of this method is an object whose keys will be added to the reactive context as arrays, representing the reactive collections. Each value of the object must be a function that returns a Mongo.Cursor.

Under the hood, each helper starts a new Tracker.autorun to create the reactivity.

The helpers method is part of the ReactiveContext, and available on every context and $scope and will stop automatically when when it's context ($scope) is destroyed.


Arguments

Name Type Details Required
definitions Object
Helper Name => Function
Object containing name => function definition, where each name is a string and each function is the helper function which returns a MongoDB Cursor Yes

Return value

This method returns the reactive context in order to provide the ability to chain the logic.


Usage Example:

myModule.controller('MyCtrl', ['$scope', '$reactive', function($scope, $reactive) {
  $reactive(this).attach($scope);

  this.helpers({
    users: () => Users.find({}),
  });
}]);

The example above will create an array on this context, with all the values that available from the Cursor that returned from find method,

Example with getReactively:

myModule.controller('MyCtrl', ['$scope', '$reactive', function($scope, $reactive) {
  $reactive(this).attach($scope);

  this.relevantId = 10;

  this.helpers({
    users: () => Users.find({ _id: this.getReactively('relevantId') })
  });
}]);

In the following example, each change in relevantId variable, will trigger the helpers method again, and the objects returned in the cursor will be different.