Created
March 20, 2018 06:42
-
-
Save ikorolev93/efbcd984c57b6ef34fed93157acb07fb to your computer and use it in GitHub Desktop.
Running redux-saga in a web worker
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
import {theSaga} from "somewhere"; | |
const ctx: Worker = self as any; | |
const workerIO: RunSagaOptions<Action, undefined> = { | |
subscribe: cb => { | |
const listener = (ev: MessageEvent) => cb(ev.data); | |
ctx.addEventListener("message", listener); | |
return () => ctx.removeEventListener("message", listener); | |
}, | |
dispatch: action => ctx.postMessage(action), | |
}; | |
runSaga(workerIO, theSaga); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment