Skip to content

Instantly share code, notes, and snippets.

@rt2zz
Last active August 29, 2015 14:27
Show Gist options
  • Save rt2zz/5d4c0cea90b5b9155fb6 to your computer and use it in GitHub Desktop.
Save rt2zz/5d4c0cea90b5b9155fb6 to your computer and use it in GitHub Desktop.
Side Effects API's
// side effects are created by reducer, but executed by store
function reducer(state, action, createSideEffect){
if(action.type === 'SUBMIT_DATA'){
createSideEffect(({action, getState, dispatch}) => {
//.. do work
})
}
}
// similar to above, but instead of creating side effects in the reducer, they are created and executed in a remote which the store invokes
function remote(action, finish, dispatch){
if(action.type === 'SUBMIT_DATA'){
//.. do work
}
}
// basically redux-thunk with labels and better logging
dispatch.signal('submitData', (state, dispatch) => {
//.. do work
})
@rt2zz
Copy link
Author

rt2zz commented Aug 12, 2015

Questions:
#1. Where are side effects written?

  • In action creators (redux-thunk/cerebral)
  • In reducers (elm)
  • In remotes (redux-remotes)
    #2. Are side effects one to one with actions or one to many
  • One to One (redux-thunk, cerebral-signals)
  • One to Many (elm(?), redux-remotes)
    #3. Who executes side effects?
  • Action Creator (redux-thunk)
  • Store (cerebral, redux-remotes, elm)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment