Last active
September 5, 2017 19:49
-
-
Save Calvin-Huang/ba1a310b3b780f527904f0b5d5a5e0a1 to your computer and use it in GitHub Desktop.
Subscribe store and dispatch another actions.
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
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