Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to handle expensive computation of derived data in Redux?

I'm currently developing an application that performs large number of computation os front-end. These computations are part of mapStateToProps function that computes derived data from state.

I would like to compute derived data in WebWorker, but I'm not sure how to implement whole data flow. reselect could help a bit with rendering view for the second time, but it still doesn't solve the problem of blocking the UI during computation.

like image 291
Pavel Gavlík Avatar asked Jan 20 '26 05:01

Pavel Gavlík


1 Answers

+1 to pushing the computation into a web-worker; you can author a custom Redux Middleware to intercept an action; read any additional state from the store and then pass that off to your web-worker. When the worker calls back your middleware can dispatch the result.

Bonus points for implementing a cache inside the middleware :)

edit: Here's a gist which follows the same thought process.

like image 188
JonnyReeves Avatar answered Jan 22 '26 21:01

JonnyReeves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!