lib/utils.js
/**
 * Creates and returns a new store. The store is responsible for holding and mutating state.
 * @param  {Object} options                Options
 * @param  {*}      options.initialState   Value of the initial store state, can be any type
 * @param  {Object} options.actionHandlers Map of functions to handle actions
 * @return {Object}                        New store
 */
Creates and returns a new store. The store is responsible for holding and mutating state.
@param  {Object} options                Options
@param  {*}      options.initialState   Value of the initial store state, can be any type
@param  {Object} options.actionHandlers Map of functions to handle actions
@return {Object}                        New store
Creates and returns a new store . The store is responsible for holding and mutating state . @param { Object } options Options @param { * } options . initialState Value of the initial store state can be any type @param { Object } options . actionHandlers Map of functions to handle actions @return { Object } New store
function createStore(options) {
  var dispatcher = this.dispatcher;
  if (!options || options.initialState === undefined) {
    throw new Error('Fluxaroo: An initialState object must be defined when creating a store');
  }
  function Store(options) {
    this.actionHandlers = options.actionHandlers;
    this.getState = function() {
      return options.initialState;
    };
    this.storeKey = dispatcher.register(function(action) {
      if (options.actionHandlers[action.type]) {
        options.initialState = options.actionHandlers[action.type](options.initialState, action);
        this.emit('change');
      }
    }.bind(this));
  }
  Store.prototype = new EventEmitter();
  return new Store(options);
}
function createStore ( options ) { var dispatcher = this . dispatcher ; if ( ! options || options . initialState === undefined ) { throw new Error ( 'Fluxaroo: An initialState object must be defined when creating a store' ) ; } function Store ( options ) { this . actionHandlers = options . actionHandlers ; this . getState = function ( ) { return options . initialState ; } ; this . storeKey = dispatcher . register ( function ( action ) { if ( options . actionHandlers [ action . type ] ) { options . initialState = options . actionHandlers [ action . type ] ( options . initialState , action ) ; this . emit ( 'change' ) ; } } . bind ( this ) ) ; } Store . prototype = new EventEmitter ( ) ; return new Store ( options ) ; }
Creates and returns a new store.
Creates and returns a new store .
// Store the action handlers on the instance so they can be accessed for testing // Read-only access to the state // The storeKey can be used in Dispatcher.waitFor() // By the time the action reaches here the dispatcher will have checked it has a valid type