All files invokeStore.js

100% Statements 2/2
100% Branches 3/3
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19                        3x   3x        
/**
 * @description Does a dry run to extract the initial state in case it was not defined
 * @param {Function} reducer a function which takes a current state and an action
 * @param {*} storeInit optional initial state
 * @param {Array} middlewares  an array of redux friendly middleware
 * Redux friendly middleware consume dispatch, and getState, and has a minimal signature of
 * store => next => action => next(action)
 * @return {Object} container the reducer, a formal initialState and the middleware
 */
export function invokeStore(reducer, storeInit, middlewares = []) {
  // if the initial state is given, take it,
  // otherwise do a dry run
  const initialState = storeInit || reducer(undefined, {});
 
  return { reducer, initialState, middlewares };
}
 
export default invokeStore;