Last active
March 19, 2019 21:09
-
-
Save visarts/781e26efc300da4fad481daeb000f9b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as stocksActions from './stocks/actions' | |
/* HEAVILY borrowed from redux/bindActionCreators | |
important: first parameter given to actions is payload, second is dispatch | |
*/ | |
const bindDispatchToActions = (actions, dispatch) => { | |
const mappedActions = {} | |
for (let key in actions) { | |
const action = actions[key] | |
if (typeof action === 'function') { | |
if (action instanceof Promise) { | |
mappedActions[key] = function(payload = {}) { | |
return action(payload, dispatch) | |
} | |
} else { | |
mappedActions[key] = function(params) { | |
return dispatch(action.apply(this, [params, dispatch])) | |
} | |
} | |
} | |
} | |
return mappedActions | |
} | |
function getRootActions(dispatch) { | |
return { | |
stocks: bindDispatchToActions(stocksActions, dispatch) | |
} | |
} | |
export default getRootActions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment