src/main/javascript/common/FluxIt.js
/**
 * An ES7 decorator for "lazy loading" an object from api calls and a passed in id
 *
 * @param {object|Array.<object>} Stores the stores to watch and call '.get' on
 * @param {function|Array.<function>} fetchFunctions the functions to pass the id and current state object into
 * @param {string:Array.<string>} dataKeys the dataKeys to use for creating the state
 * @param {func} stateFunc? an optional state func to use
 */
An ES7 decorator for "lazy loading" an object from api calls and a passed in id
@param {object|Array.} Stores the stores to watch and call '.get' on
@param {function|Array.} fetchFunctions the functions to pass the id and current state object into
@param {string:Array.} dataKeys the dataKeys to use for creating the state
@param {func} stateFunc. an optional state func to use
An ES7 decorator for " lazy loading " an object from api calls and a passed in id @param { object|Array . } Stores the stores to watch and call ' . get ' on @param { function|Array . } fetchFunctions the functions to pass the id and current state object into @param { string : Array . } dataKeys the dataKeys to use for creating the state @param { func } stateFunc . an optional state func to use
function lazyLoad(Stores, fetchFunctions, dataKeys, stateFunc) {
  if(!Stores) {
    throw new Error(`Attempted to flux a component without any stores. See the component ${Component}`);
  }
  if(!(Stores instanceof Array)) {
    Stores = [Stores];
  }
  if(!(dataKeys instanceof Array)) {
    dataKeys = [dataKeys];
  }
  if(!(fetchFunctions instanceof Array)) {
    fetchFunctions = [fetchFunctions];
  }
  if(Stores.length !== dataKeys.length) {
    throw new Error(`Lazy loading with the incorrect number of dataKeys. See component ${Component}`);
  }
  const updateState = props => {
    let state = (stateFunc && stateFunc(props)) || {};
    Stores.forEach((Store, i) => {
      state[dataKeys[i]] = Store.get(props.id);
    });
    return state;
  };
  const apiFuncs = context => {
    fetchFunctions.forEach((api, i) => {
      api(context.id, context[dataKeys[i]]);
    });
  };
  return init(updateState, Stores, apiFuncs);
}
function lazyLoad ( Stores , fetchFunctions , dataKeys , stateFunc ) { if ( ! Stores ) { throw new Error ( ` ${ Component } ` ) ; } if ( ! ( Stores instanceof Array ) ) { Stores = [ Stores ] ; } if ( ! ( dataKeys instanceof Array ) ) { dataKeys = [ dataKeys ] ; } if ( ! ( fetchFunctions instanceof Array ) ) { fetchFunctions = [ fetchFunctions ] ; } if ( Stores . length !== dataKeys . length ) { throw new Error ( ` ${ Component } ` ) ; } const updateState = props => { let state = ( stateFunc && stateFunc ( props ) ) || { } ; Stores . forEach ( ( Store , i ) => { state [ dataKeys [ i ] ] = Store . get ( props . id ) ; } ) ; return state ; } ; const apiFuncs = context => { fetchFunctions . forEach ( ( api , i ) => { api ( context . id , context [ dataKeys [ i ] ] ) ; } ) ; } ; return init ( updateState , Stores , apiFuncs ) ; }
An ES7 decorator for "lazy loading" an object from api calls and a passed in id
 @param {object|Array.<object>} Stores the stores to watch and call '.get' on
 @param {function|Array.<function>} fetchFunctions the functions to pass the id and current state object into
 @param {string:Array.<string>} dataKeys the dataKeys to use for creating the state
 @param {func} stateFunc?
An ES7 decorator for " lazy loading " an object from api calls and a passed in id @param { object|Array . <object > } Stores the stores to watch and call ' . get ' on @param { function|Array . <function > } fetchFunctions the functions to pass the id and current state object into @param { string : Array . <string > } dataKeys the dataKeys to use for creating the state @param { func } stateFunc?