dai-shi / redux-in-worker

Entire Redux in Web Worker
https://www.npmjs.com/package/redux-in-worker
MIT License
261 stars 6 forks source link

Question - Selectors in workers #10

Open hirviid opened 3 years ago

hirviid commented 3 years ago

Hi!

Your library looks very interesting and promising for our use case. We're working on a very big planning application with a lot of data in a redux store. The state is quite flat and we use selectors (with reduxjs/reselect) to combine several parts of the state to get different filtered and nested data structures optimized for rendering in React. These selectors are the most heavy part of the application.

Would it be possible to move these selectors to a webworker as well? Would Redux useSelector be able to import the selector from the webworker?

dai-shi commented 3 years ago

Would it be possible to move these selectors to a webworker as well?

I think so. I assume you mean to use those selectors in reducers.

Would Redux useSelector be able to import the selector from the webworker?

Hm, so you mean the selector functions you pass to useSelector are heavy? In this case, it'd require quite a bit of refactoring: Do heavy computations in reducers / middleware in pure redux, and useSelector in react-redux should be lightweight. It's so-called de-normalization. Maybe not very typical in normal redux.

hirviid commented 3 years ago

Thanks for the quick response!

Our state is normalized indeed. We have some heavy parts in the reducers, where a certain action needs to update several parts of the state. But the most heavy part is in the selectors though, where we combine and calculate data from the state before giving it to a component. So in our case I guess it would make sense to try to move the selectors to a web worker.

I will make a proof of concept. I'm also looking at https://github.com/HerbCaudill/react-redux-worker , it looks like the selectors you pass to useSelector run in the worker in that package.

You can close this question if you want, I'll come with an update later when I have time for the poc.

dai-shi commented 3 years ago

Cool! Look forward to hearing updates.

Feel free to drop questions about impl / expected behavior.