Created
February 10, 2017 17:36
-
-
Save Donmclean/5eef5408be01cedf6bd2c95d489b7ebc to your computer and use it in GitHub Desktop.
Redux Observable Handling Async Example
This file contains 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
const fetchFirst = () => ({ type: FETCH_FIRST }); | |
const fetchSecond = (response) => ({ type: FETCH_SECOND, payload: response }); | |
const fetchFirstManager = (actions, store) => | |
actions.ofType(FETCH_FIRST) | |
.switchMap(action => | |
ajax('/first') | |
.map(response => fetchSecond(response)) | |
); | |
const fetchSecondManager = (actions, store) => | |
actions.ofType(FETCH_SECOND) | |
.switchMap(action => | |
ajax('/second') | |
.map(response => ({ type: OK_IM_DONE, payload: response })) | |
); | |
store.dispatch(fetchFirst()); | |
// fetchFirst() -> [await response] -> fetchSecond() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment