Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Donmclean/5eef5408be01cedf6bd2c95d489b7ebc to your computer and use it in GitHub Desktop.
Save Donmclean/5eef5408be01cedf6bd2c95d489b7ebc to your computer and use it in GitHub Desktop.
Redux Observable Handling Async Example
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