Stop from receiving notifications

Whenever we add a hook in the store it always return a HookLink instance that represents the link between the hook and the store. We can use it to stop our hook from getting notified on any dispatched action.

In this example we use the destroy method to manually destroy the hook when it reach its 3rd invocation.

hookLink is only available inside reducers after hook initial phase.

controller-d.js
angular
  .module('App', [])
  .controller('ControllerD', function ControllerD($scope, CounterStore) {
    const hookLink = CounterStore.hook('INCREMENT_COUNT', (state, calls) => {
      $scope.count = state.count;

      if (calls === 3) {
        hookLink.destroy();
      }
    });
  });

Another method of HookLink is destroyOn. This method is used for auto destroying of hook. It basically bind the hook to AngularJS scope so when the scope destroyed also hook is get destroyed.

controller-d.js
angular
  .module('App', [])
  .controller('ControllerD', function ControllerD($scope, CounterStore) {
    CounterStore.hook('INCREMENT_COUNT', (state) => {
      $scope.count = state.count;
    }).destroyOn($scope);
  });

Last updated