-
-
Save oojikoo/dd6a08af2d8e0bbbbdf72b75ba31d4c8 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); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this was an idea to our project, too. I didn't implement it at the end.
the original one is https://gist.github.com/deadNightTiger/efbcd984c57b6ef34fed93157acb07fb