lib/utils.js
/**
 * Creates a wrapper component that automatically injects store values and action handlers into
 * the props of the given component.
 * @param  {*} component                     The component into which store values and actions are injected
 * @param  {Object} options                  Options
 * @param  {Object} options.storeDepedencies Array of store instances that the container depends on
 * @param  {Object} options.storeProps       Function that returns an object map of store values to inject
 * @param  {Object} options.actionProps      Function that returns an object map of action handlers to inject
 * @return {Object}                          React component class
 */
Creates a wrapper component that automatically injects store values and action handlers into
the props of the given component.
Creates a wrapper component that automatically injects store values and action handlers into the props of the given component .
function createContainer(component, options) {
  var dispatcher = this.dispatcher;
  if (options.storeProps && !Array.isArray(options.storeDepedencies)) {
    throw new Error('Fluxaroo: An array of storeDepedencies must be defined when creating a container with storeProps');
  }
  return React.createClass({
    getState: function() {
      var state = {};
      if (options.storeProps) {
        extend(state, options.storeProps(this.props));
      }
      if (options.actionProps) {
        extend(state, wrapActionProps(dispatcher, options.actionProps(this.props)));
      }
      return state;
    },
    getInitialState: function() {
      return this.getState();
    },
    onStoreChange: function() {
      this.setState(this.getState());
    },
    componentDidMount: function() {
      if (options.storeDepedencies) {
        options.storeDepedencies.forEach(function(store) {
          store.addListener('change', this.onStoreChange);
        }.bind(this));
      }
    },
    componentWillUnmount: function() {
      if (options.storeDepedencies) {
        options.storeDepedencies.forEach(function(store) {
          store.removeListener('change', this.onStoreChange);
        }.bind(this));
      }
    },
    render: function() {
      return React.createElement(component, extend({}, this.state, this.props));
    }
  });
}
function createContainer ( component , options ) { var dispatcher = this . dispatcher ; if ( options . storeProps && ! Array . isArray ( options . storeDepedencies ) ) { throw new Error ( 'Fluxaroo: An array of storeDepedencies must be defined when creating a container with storeProps' ) ; } return React . createClass ( { getState : function ( ) { var state = { } ; if ( options . storeProps ) { extend ( state , options . storeProps ( this . props ) ) ; } if ( options . actionProps ) { extend ( state , wrapActionProps ( dispatcher , options . actionProps ( this . props ) ) ) ; } return state ; } , getInitialState : function ( ) { return this . getState ( ) ; } , onStoreChange : function ( ) { this . setState ( this . getState ( ) ) ; } , componentDidMount : function ( ) { if ( options . storeDepedencies ) { options . storeDepedencies . forEach ( function ( store ) { store . addListener ( 'change' , this . onStoreChange ) ; } . bind ( this ) ) ; } } , componentWillUnmount : function ( ) { if ( options . storeDepedencies ) { options . storeDepedencies . forEach ( function ( store ) { store . removeListener ( 'change' , this . onStoreChange ) ; } . bind ( this ) ) ; } } , render : function ( ) { return React . createElement ( component , extend ( { } , this . state , this . props ) ) ; } } ) ; }
Creates a wrapper component that automatically injects store values and action handlers into
 the props of the given component.
Creates a wrapper component that automatically injects store values and action handlers into the props of the given component .
// Returns on object representing the state by merging the result of storeProps() and actionProps() // Copy the result of storeProps() onto the new state object // Copy the result of actionProps() onto the new state object // Triggered whenever a store action handler finishes