getReactively

Use this method to get a context variable and watch it reactively, so each change of this variable causes the dependents (autorun, helper functions and subscriptions) to run again.

The getReactively method is part of the ReactiveContext, and available on every context and $scope.


Arguments

Name Type Details Required
variableName String The name of the context's variable to bind to Yes
objectEquality Function
Boolean
Use true to deep watch the object, or a function to provide custom equality function. The default value is false, which does a shallow / reference watch only. No

Return value

This method returns the current value of the reactive variable.


Example with subscribe:

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

  this.relevantId = 10;

  this.subscribe('users', () => {
    return [ this.getReactively('relevantId') ];
  });

  this.relevantId = 50; // This will cause the subscribe arguments method to run again
}]);

Example with helpers:

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

  this.myUser: {
    id: 10
  };

  this.helpers({
    myData: () => {
      return Data.find({_id: this.getReactively('myUser.id')});
    }
  });

  this.myUser.id = 29; // This will cause the helper to run again and update the view
}]);