How to use the flux/lib/invariant function in flux

To help you get started, we’ve selected a few flux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webkom / lego-webapp / src / Dispatcher.js View on Github external
store.dispatchToken = this.register((payload) => {
      var action = payload.action;
      if (!store.hasOwnProperty('actions')) return;

      var handler = store.actions[action.type];
      var handlerName = action.type;

      // the store doesn't care about this action
      if (!handler) return;

      if (typeof handler === 'string') {
        handlerName = handler;
        handler = store[handler];
      }

      invariant(
        typeof handler === 'function',
        '%s is not a function', handlerName
      );

      if (store.waitFor)
        this.waitFor(store.waitFor);

      handler.call(store, action);
    });
  }
github webkom / lego-webapp / src / Dispatcher.js View on Github external
registerStore(store) {
    invariant(!store.dispatchToken, 'The store is already registered');

    store.dispatchToken = this.register((payload) => {
      var action = payload.action;
      if (!store.hasOwnProperty('actions')) return;

      var handler = store.actions[action.type];
      var handlerName = action.type;

      // the store doesn't care about this action
      if (!handler) return;

      if (typeof handler === 'string') {
        handlerName = handler;
        handler = store[handler];
      }