Is it possible to import values from the store worker file?
rssfrncsrenishaw opened this issue · 8 comments
Is there anyway to import values from the store worker file?
For example, when using "connected-react-router" it is common to create the history object inside of your store and export it.
I imagine this is incompatible with connected-react-router or any other Redux libraries that rely on window. Redux-persist is another example (local storage).
Thanks for tipping in.
Unfortunately, we can't access DOM in a worker thread.
Yeah, redux-persist doesn't work.
The history object in connected-react-router requires the same object, so no, it doesn't work.
Hmm, it seems like we need worker-aware middleware in the entire eco system.
It's a tough problem.
I wonder if we could split a store into two (in a main thread and in a worker thread)...
No problem - thanks for all your great work/experimentation in the redux ecosystem at the moment!
I wonder if it is possible for only the reducer to run inside of the worker? This is really all I personally would want from a redux worker solution. This would enable me to run complex and potentially long running logic inside of the reducer without being concerned that I will block the UI - currently I move this kind of logic to either before (thunk etc.) or after (deriving it in a component using for example your react-hooks-worker!) the reducer.
Assuming your heavy reducers don't care about connected-react-rounter, wouldn't it be possible to have two stores? One normal store and, the other store in worker.
It's not like a traditional redux global/single store pattern, but technically you could do that.
ref: reduxjs/react-redux#1309
Or, you could try another approach: middleware/enhancer only in worker.
I haven't looked into detail, but something like these:
@rssfrncsrenishaw
I made an example for connected-react-router.
https://github.com/dai-shi/redux-in-worker/tree/233ec2d2d3b2a49958ee77b71a973429cbcf41ca/examples/03_router
It is very tricky, so maybe not for a real use.
You can run it by:
npm run examples:router
I appreciate the recommendations and your example above - certainly looks a bit trickier.
Closing this. Feel free to reopen or continue discussion.