Last active
March 28, 2019 09:28
-
-
Save gigobyte/0e13e1f4d1c775b1e65be5fe5d9649df 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
// 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