Last active
October 22, 2018 19:15
-
-
Save baso53/68dad2ea190671bb2d21f1b1733b0314 to your computer and use it in GitHub Desktop.
implementing-sagas-middleware-3
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
| ... | |
| if (handler) { | |
| const handlerInstance = handler(action); | |
| let yieldedValue = handlerInstance.next(); | |
| (async () => { | |
| while (!yieldedValue.done) { | |
| switch (yieldedValue.value.effect) { | |
| case 'effect/CALL': | |
| await yieldedValue.value.payload.apply(null, yieldedValue.value.args) | |
| .then(res => { yieldedValue = handlerInstance.next(res) }) | |
| .catch(err => { yieldedValue = handlerInstance.throw(err) }); | |
| break; | |
| case 'effect/PUT': | |
| store.dispatch(yieldedValue.value.payload); | |
| yieldedValue = handlerInstance.next(); | |
| break; | |
| default: | |
| yieldedValue = handlerInstance.next(); | |
| } | |
| } | |
| })(); | |
| } | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment