How to use dispatchr - 10 common examples

To help you get started, we’ve selected a few dispatchr 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 christianalfoni / flux-angular / dist / flux-angular.esm.js View on Github external
var FluxService = function FluxService(immutableDefaults, $rootScope) {
  this.stores = [];
  this.dispatcherInstance = dispatchr.createDispatcher();
  this.dispatcher = this.dispatcherInstance.createContext();

  this.dispatch = function () {
    if (registeredStores.length) {
      console.warn('There are still stores not injected: ' + registeredStores.join(',') + '. Make sure to manually inject all stores before running any dispatches or set autoInjectStores to true.'); // eslint-disable-line no-console
    }

    this.dispatcher.dispatch.apply(this.dispatcher, arguments);
  };

  this.createStore = function (name, spec) {
    var store = createStore(name, spec, immutableDefaults, this);
    var storeInstance; // Create the exports object

    store.exports = {};
    this.dispatcherInstance.registerStore(store);
github christianalfoni / flux-angular / src / flux-angular.js View on Github external
const FluxService = function(immutableDefaults, $rootScope) {
  this.stores = []
  this.dispatcherInstance = dispatchr.createDispatcher()
  this.dispatcher = this.dispatcherInstance.createContext()

  this.dispatch = function() {
    if (registeredStores.length) {
      console.warn(
        'There are still stores not injected: ' +
          registeredStores.join(',') +
          '. Make sure to manually inject all stores before running any dispatches or set autoInjectStores to true.'
      ) // eslint-disable-line no-console
    }
    this.dispatcher.dispatch.apply(this.dispatcher, arguments)
  }

  this.createStore = function(name, spec) {
    const store = createStore(name, spec, immutableDefaults, this)
    let storeInstance
github yahoo / fluxible / packages / fluxible / lib / Fluxible.js View on Github external
function Fluxible(options) {
    debug('Fluxible instance instantiated', options);
    options = options || {};

    // Options
    this._component = options.component;
    this._componentActionErrorHandler =
        options.componentActionErrorHandler || defaultComponentActionHandler;
    this._plugins = [];

    // Initialize dependencies
    this._dispatcher = dispatchr.createDispatcher(options);
}
github jeffkole / fluxible-immutable-store / tests / unit / createImmutableStore.js View on Github external
it('should not conflict with other instances of itself', function () {
    var dispatcherA = dispatcher.createDispatcher({ stores: stores });
    var dispatcherContextA = dispatcherA.createContext({});
    var dispatcherB = dispatcher.createDispatcher({ stores: stores });
    var dispatcherContextB = dispatcherB.createContext({});

    var storeA = dispatcherContextA.getStore(PrivatesStore);
    var storeB = dispatcherContextB.getStore(PrivatesStore);

    expect(storeA.number).to.equal(50);
    expect(storeB.number).to.equal(50);
    dispatcherContextA.dispatch('TRIGGER', 100);
    expect(storeA.number).to.equal(100);
    expect(storeB.number).to.equal(50);
  });
});
github jeffkole / fluxible-immutable-store / tests / unit / createImmutableStore.js View on Github external
it('should not conflict with other instances of itself', function () {
    var dispatcherA = dispatcher.createDispatcher({ stores: stores });
    var dispatcherContextA = dispatcherA.createContext({});
    var dispatcherB = dispatcher.createDispatcher({ stores: stores });
    var dispatcherContextB = dispatcherB.createContext({});

    var storeA = dispatcherContextA.getStore(PrivatesStore);
    var storeB = dispatcherContextB.getStore(PrivatesStore);

    expect(storeA.number).to.equal(50);
    expect(storeB.number).to.equal(50);
    dispatcherContextA.dispatch('TRIGGER', 100);
    expect(storeA.number).to.equal(100);
    expect(storeB.number).to.equal(50);
  });
});
github jeffkole / fluxible-immutable-store / tests / unit / createImmutableStore.js View on Github external
beforeEach(function () {
  this.dispatcher = dispatcher.createDispatcher({ stores: stores });
  this.dispatcherContext = this.dispatcher.createContext({});
});
github DefinitelyTyped / DefinitelyTyped / types / dispatchr / dispatchr-tests.ts View on Github external
},

    additionalMethod() {}
});

class ExtendedStore extends BaseStore {
    static handlers = {
        ACTION_NAME: 'actionHandler'
    };

    actionHandler() {
        this.emitChange();
    }
}

const dispatcher = createDispatcher({
    errorHandler(e, context) {
        e.meta;
        e.type;
        e.message;
    },
    stores: [TestStore]
});

const context = dispatcher.createContext({});
context.dispatch('ACTION_NAME', {});
github yahoo / fluxible / packages / fluxible / utils / createMockActionContext.js View on Github external
module.exports = function createMockActionContext(options) {
    options = options || {};
    options.mockActionContextClass = options.mockActionContextClass || MockActionContextClass;
    options.stores = options.stores || [];
    options.dispatcher = options.dispatcher || dispatchr.createDispatcher({
        stores: options.stores
    });
    options.dispatcherContext = options.dispatcherContext || options.dispatcher.createContext();

    return new options.mockActionContextClass(options.dispatcherContext);
};
github insoftpub / storefront / src / Context.js View on Github external
* SOFTWARE.
 */

import dispatchr from 'dispatchr';
import stores from './stores';
import actions from './actions';
import { setImmediate } from 'setimmediate2';
import { UserAgent } from 'express-useragent/lib/express-useragent';
import { getCookieClient, setCookieClient } from './utils/cookie';
import { createId, removeCss } from './utils/styles';
import { map, reduce } from 'lodash';
import { siteName } from './config';

const
    storeNames = map(stores, item => item.storeName),
    dispatcher = dispatchr.createDispatcher({
        stores
    });

class Context {
    constructor() {
        this.dispatcher = dispatcher.createContext();

        this.getStore = this.getStore.bind(this);
        this.insertCss = this.insertCss.bind(this);
        this.removeCss = this.removeCss.bind(this);
        this.executeAction = this.executeAction.bind(this);
        this.dispatch = this.dispatch.bind(this);
        this.dehydrate = this.dehydrate.bind(this);
        this.styles = {};
    }
github yahoo / fluxible / packages / fluxible / utils / createMockComponentContext.js View on Github external
module.exports = function createMockComponentContext(options) {
    options = options || {};
    options.mockComponentContextClass = options.mockComponentContextClass || MockComponentContextClass;
    options.stores = options.stores || [];
    options.dispatcher = options.dispatcher || dispatchr.createDispatcher({
        stores: options.stores
    });
    options.dispatcherContext = options.dispatcherContext || options.dispatcher.createContext();

    return new options.mockComponentContextClass(options.dispatcherContext);
};

dispatchr

A Flux dispatcher for applications that run on the server and the client.

Unrecognized
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis