Is there any way to “commit” the state in Redux to

2019-02-22 10:09发布

问题:

I'm working on a real-time multiplayer game and I use Redux on both the server and the client to store the state of the application.

However, the amount of actions dispatched into the store is significantly higher than in an usual application because my game is real-time. I suspect that this is why Redux is using a lot of memory.

To my understanding Redux stores all actions dispatched into a store in memory in order to be able to do its "time traveling". I also noticed that the Redux DevTools allows you to commit the state.

What I would like to do is commit the application e.g. every 10 seconds to save memory. I never have the need to go back more than 10 seconds in my application anyway so storing all actions seems unnecessary, even for debugging purposes.

Does Redux support this? If not, is there any way to achieve this behavior?

Thank you in advance!

回答1:

Note that while the Redux DevTools do store the history of actions to enable the time-travel debugging feature, Redux itself does not - it only keeps a reference to the current state. The DevTools also have some additional overhead due to rendering the list of actions and store contents.

Beyond that: what makes you say that Redux is "using a lot of memory"? The only memory that Redux uses is whatever is needed to represent the store state. Unless you have some particular benchmarks that actually show memory problems, I wouldn't see it as a meaningful concern.