Dispatch REDUX_STORAGE_SAVE only when state has been really changed. #144

Closed
opened 2016-06-12 18:15:08 +00:00 by steida · 9 comments
steida commented 2016-06-12 18:15:08 +00:00 (Migrated from github.com)

From developer experience, it really makes sense to not dispatch REDUX_STORAGE_SAVE when nothing has been changed.

Update Engine save?

From developer experience, it really makes sense to not dispatch REDUX_STORAGE_SAVE when nothing has been changed. Update Engine save?
michaelcontento commented 2016-06-12 18:28:48 +00:00 (Migrated from github.com)

I also like the idea but it would require a deep comparision of the state which might be a bit difficult, as the user free to put immutablejs or any other non-plain-old-javascript-object in the state.

I also like the idea but it would require a deep comparision of the state which might be a bit difficult, as the user free to put immutablejs or any other non-plain-old-javascript-object in the state.
steida commented 2016-06-12 19:26:59 +00:00 (Migrated from github.com)

Not at all.

All Immutable Iterables also implement toJSON() allowing them to be passed to JSON.stringify directly.

https://github.com/facebook/immutable-js#converts-back-to-raw-javascript-objects

And if the user puts inside a object with circular references, it will fail anyway.

Not at all. > All Immutable Iterables also implement toJSON() allowing them to be passed to JSON.stringify directly. https://github.com/facebook/immutable-js#converts-back-to-raw-javascript-objects And if the user puts inside a object with circular references, it will fail anyway.
michaelcontento commented 2016-06-13 08:44:20 +00:00 (Migrated from github.com)

I'm not saying it's impossible to implement 😃

We also should think about where to add this check. Currently the middleware (see here) is will trigger the action after engine.save resolves. If we add this check before calling engine.save we also skip the whole engine-decorator stack (which might be expensive too), but redux-storage-decorator-filter for example could increase the "skip save hitrate".

I'm not saying it's impossible to implement 😃 We also should think about where to add this check. Currently the middleware ([see here](https://github.com/michaelcontento/redux-storage/blob/master/src/createMiddleware.js#L88-L89)) is will trigger the action after `engine.save` resolves. If we add this check **before** calling `engine.save` we also skip the whole engine-decorator stack (which might be expensive too), but `redux-storage-decorator-filter` for example could increase the _"skip save hitrate"_.
adamterlson commented 2016-06-23 12:30:17 +00:00 (Migrated from github.com)

I just discovered this issue myself and found that it results in, naturally, all of my connected components re-rendering, which in turn re-renders my stateless functional components (as they lack the componentShouldUpdate check). This has resulted in a noticeable slowdown in the rendering performance of my react native app.

Are you aware of any work-arounds to this that can help alleviate the performance impact of the overly chatty REDUX_STORAGE_SAVE?

I just discovered this issue myself and found that it results in, naturally, all of my `connect`ed components re-rendering, which in turn re-renders my stateless functional components (as they lack the componentShouldUpdate check). This has resulted in a noticeable slowdown in the rendering performance of my react native app. Are you aware of any work-arounds to this that can help alleviate the performance impact of the overly chatty REDUX_STORAGE_SAVE?
michaelcontento commented 2016-06-23 12:39:22 +00:00 (Migrated from github.com)

Your connected components should only re-render as soon as the state changes. REDUX_STORAGE_SAVE is, on its own, just a simple action and does not change the state itself. So as long as you don't process and modify the save action, the state keeps the same and no component should start re-rendering.

Can you provide us some example code to illustrate this behaviour?

Your `connect`ed components should only re-render as soon as the state changes. `REDUX_STORAGE_SAVE` is, on its own, just a simple action and **does not** change the state itself. So as long as you don't process and modify the save action, the state keeps the same and no component should start re-rendering. Can you provide us some example code to illustrate this behaviour?
adamterlson commented 2016-06-23 12:50:31 +00:00 (Migrated from github.com)

Ah, well, thanks for the intel! Perhaps I have some other odd behavior going on! Let me do some investigation on my end and I'll check back when I know more.

Just to be clear, would you expect the mapStateToProps and mapDispatchToProps functions to execute as the result of the message, or you're saying they shouldn't execute unless the redux store itself has been modified?

Ah, well, thanks for the intel! Perhaps I have some other odd behavior going on! Let me do some investigation on my end and I'll check back when I know more. Just to be clear, would you expect the mapStateToProps and mapDispatchToProps functions to execute as the result of the message, or you're saying they shouldn't execute unless the redux store itself has been modified?
cuitianze commented 2016-10-22 08:49:06 +00:00 (Migrated from github.com)

How can i trigger saving engine in custom http request file outside the component?
Scene: User had logined in app, however the server tell client that the user is not login, so i should change the localstorage.
Apologize for my poor english.

How can i trigger saving engine in custom http request file outside the component? Scene: User had logined in app, however the server tell client that the user is not login, so i should change the localstorage. Apologize for my poor english.
cuitianze commented 2016-10-22 09:12:36 +00:00 (Migrated from github.com)

Sorry, i have known what i need, just use store function(dispatch actions) outside components.

Sorry, i have known what i need, just use store function(dispatch actions) outside components.
michaelcontento commented 2016-11-02 20:55:21 +00:00 (Migrated from github.com)

Sorry for the bad news but this package is no longer maintained. 😞

My focus has left the react / node ecosystem and I don't have to time to keep things up to date. But if you want to step in and become the new maintainer of redux-storage and all of it parts, just ping me! 😃

Sorry for the bad news but this package is no longer maintained. 😞 My focus has left the react / node ecosystem and I don't have to time to keep things up to date. But if you want to step in and become the new maintainer of `redux-storage` and all of it parts, just ping me! 😃
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MichaelContento/redux-storage#144
No description provided.