import isFunction from 'lodash/isFunction';
import { createAction as CA, handleActions as handle } from 'redux-actions';

// matches action names with reducers and returns an object to
// be used with handleActions
// passes all state as a third argument
export const bindActionsToReducers = (actions, reducerList, appState) =>
  Object.keys(actions).reduce((result, k) => {
    const c = {};
    const name = actions[k];
    c[name] = (state, action) =>
      reducerList.reduce((r, reducer) => {
        if (!reducer.hasOwnProperty(k) || !isFunction(reducer[k])) return r;
        return reducer[k](r, action, appState);
      }, state);

    return { ...result, ...c };
  }, {});

export const handleActions = (key, actions, reducers, state) =>
  handle(bindActionsToReducers(actions, [reducers], state), state[key] || {});

// our own actioncreattor that can handle thunks
// fires the action as init
// and leaves resolve/reject to the thunk creator
export const createThunkAction = (name, thunkAction) => {
  if (!thunkAction) return CA(name);
  thunkAction.toString = () => name;
  return thunkAction;
};

@@ -306,26 +306,16 @@
 ucerList
-, appState
 ) =%3E%0A  O
@@ -493,38 +493,102 @@
     
-if (!reducer.hasOwnProperty(k)
+const hasProperty = Object.prototype.hasOwnProperty.call(reducer, k);%0A        if (!hasProperty
  %7C%7C 
@@ -661,18 +661,8 @@
 tion
-, appState
 );%0A 
@@ -1123,16 +1123,39 @@
 =%3E name;
+ // eslint-disable-line
 %0A  retur

Stop passing all store in each action