AngularJS Store
v3.0.0
v3.0.0
  • Introduction
  • Installation
  • Tutorials
    • Setup a store
    • Get the current state
    • Update the state
    • Get notified on state changes
    • Stop from receiving notifications
  • API Reference
    • NgStore
    • copy
    • dispatch
    • hook
Powered by GitBook
On this page
  1. Tutorials

Stop from receiving notifications

PreviousGet notified on state changesNextAPI Reference

Last updated 6 years ago

Was this helpful?

CtrlK

Was this helpful?

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);
});