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.
| 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 |
This method returns the reactive context in order to provide the ability to chain the logic.
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
thiscontext, with all the values that available from the Cursor that returned fromfindmethod,
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
relevantIdvariable, will trigger the helpers method again, and the objects returned in the cursor will be different.