Created
September 30, 2019 13:15
-
-
Save LBWright/6bc1cc3f9f871fbc0845eb4af7f561c2 to your computer and use it in GitHub Desktop.
Revisions
-
LBWright revised this gist
Sep 30, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ export const createWellsTask = ({ serverId }) => async (dispatch) => { }); } }; // Where it comes together inside of container.js const mapDispatchToProps = { subscribeAppForAsset, unsubscribeAppFromAsset, -
LBWright created this gist
Sep 30, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ // inside of my actions.js, my actions look like this... // because I'm creating a function that returns a function, I have access to dispatch // through the Thunk middleware. I technically have access to state too, as a second argument // Because I'm using dispatch here, this specific function can be bound to the redux store // You could maybe think about it like a singleton? export const createWellsTask = ({ serverId }) => async (dispatch) => { const payload = { properties: { operation: 'list_wells', witsml_server: serverId, }, }; dispatch({ type: TYPES.CREATE_WELLS_TASK, }); try { const response = await post('/v2/tasks', { task: payload }); dispatch({ type: TYPES.CREATE_WELLS_TASK_SUCCESS, payload: response.toJS(), }); } catch (e) { dispatch({ type: TYPES.CREATE_WELLS_TASK_ERROR, payload: e, }); } }; // Where it comes together const mapDispatchToProps = { subscribeAppForAsset, unsubscribeAppFromAsset, createWellsTask, }; export default connect( mapStateToProps, mapDispatchToProps )(StreamMapper); /**************************/ //it could also be done like this with no 'actions file' (using .then just for variance) const mapDispatchToProps = (dispatch) => { createWellsTask: (myArgs) => dispatch({type: MYTYPE, payload: myArgs}) // You could break up your bound functions here and 'assemble them' inside of your component } export default connect( mapStateToProps, mapDispatchToProps )(StreamMapper); /************************/