Skip to content

Instantly share code, notes, and snippets.

@baso53
Last active October 22, 2018 19:15
Show Gist options
  • Select an option

  • Save baso53/68dad2ea190671bb2d21f1b1733b0314 to your computer and use it in GitHub Desktop.

Select an option

Save baso53/68dad2ea190671bb2d21f1b1733b0314 to your computer and use it in GitHub Desktop.
implementing-sagas-middleware-3
...
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