Skip to content

Instantly share code, notes, and snippets.

@gigobyte
Last active March 28, 2019 09:28
Show Gist options
  • Save gigobyte/0e13e1f4d1c775b1e65be5fe5d9649df to your computer and use it in GitHub Desktop.
Save gigobyte/0e13e1f4d1c775b1e65be5fe5d9649df to your computer and use it in GitHub Desktop.
// Elm architecture - all data fetching is in the reducer
reducer(state, action) {
if (action === LOCATION_CHANGE && action.payload === '/send-payment') {
return loop(state, Cmd.action(fetchData()))
}
if (action === FETCH_DATA) {
return loop(state, corporateApiCall())
}
}
// React-ish Elm-ish architecture - everything except initial data fetching is in the reducer
class SendPaymentContainer {
componentDidMount() {
this.props.fetchData()
}
}
reducer(state, action) {
// the api call is still in the reducer but it's triggered by the lifecycle method
if (action === FETCH_DATA) {
return loop(state, corporateApiCall())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment