Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Last active September 5, 2017 19:49
Show Gist options
  • Save Calvin-Huang/ba1a310b3b780f527904f0b5d5a5e0a1 to your computer and use it in GitHub Desktop.
Save Calvin-Huang/ba1a310b3b780f527904f0b5d5a5e0a1 to your computer and use it in GitHub Desktop.
Subscribe store and dispatch another actions.
store.subscribe(() => {
const action = store.getState().lastAction;
switch (action.type) {
case START_REQUEST: {
fetch('/api/v1/foo')
.then(response => response.json())
.then((data) => {
store.dispatch(receive(data));
})
.catch((error) => {
store.dispatch(showNotification(error));
});
break;
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment