-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/mergedeep rehydrate no mutation #114
Feature/mergedeep rehydrate no mutation #114
Conversation
Adds lodash.merge as dependency and simplify code Make sure undefined state runs through reducer Remove `state` parameter default value in the signature
This lgtm from a cursory glance. Could someone more familiar with current project please take a look as well, thanks! @bufke |
@btroncone The main thing to decide upon is the new dependency on lodash.merge. I know that introducing dependencies might not be the optimal way, but in fact improper merging was source of the major bug. It actually solves the problem. Feel free to edit the PR code if you have a better solution. I just wanted to come up with something that works. On a side note: there is a couple of PRs hanging out there in this project, I bet each of them has valuable chunks of code. It would be good to review all of them and cherry-pick the best of all worlds. This or that, let's test, and move on. |
This PR looks good however there's a scenario that the solution doesn't cater for: If a key has been removed from I had a quick look and couldn't find a way in lodash (nor immutable.js) that would allow merging to a destination object but limit the merge to existing properties. One approach could be using lodash In my opinion, it'd be a better solution to recursively iterate over |
@JohnKis Thanks for your valuable input. You are right that this scenario was kind of neglected and should be handled. I will try to look into solving it over the weekend. The main purpose of this PR though is to fix the critical bugs which users suffer from. IMO it is better to proceed incrementally, ie. merge this code which I believe solves harmful bugs and then try to improve it by handling other case. Granted, the previous code might have been able to remove keys, but it had nasty bugs where the state was completely destroyed. So the main questions are: would merging this PR be harmful to users? would it solve problems? If we now choose to try to solve all imperfections that this code has, we will probably never move forward. |
Agreed. The PR definitely improves the merging behaviour so I'm happy for it to go ahead. We just need to keep in mind that there are other areas that will need to be covered eventually. |
It would be of great help if you could create an issue with the specific case you have in mind. |
Sure, I can create it. I'm wondering whether it's worth doing after this PR got merged, otherwise the issue won't make a lot of sense in the context of the current release. |
@JohnKis I believe there is never too many test cases :) But not only that. As you said, my PR doesn't cover removing keys. Thus, after merging it, we will have a bug, so your test case will actually help solve it. |
Created #115 |
I should have time to review this tomorrow and test it with my project. |
This adds about 10kb to a production bundle I tested this with store-freeze and it works. Since it seems like there is high demand to make this work without regressions I'm going to merge this.
|
@bufke @btroncone when this fix will it be available ? |
I will publish 7.0.0 this morning, sorry for delay. 👍 |
I regret to say that this PR only partially solves the problem. My setupI have a couple of feature modules StoreModule.forFeature('feature1', reducer) and the reducer says: export interface State extends fromRoot.State {
feature1: Feature1State;
} my localStorageSync config is: {
keys: [{app: [...]}, {feature1: [...]}, {feature2: [...]} ],
rehydrate: true,
} As long as don't include a SolutionFor all non-app modules (slices) that you selectively save to local storage, you need to apply this solution - ie. explicitly handling Conclusion
|
This is a PR that aims at solving long lasting bugs that users complained about in #110, #80, #65:
The PR does not change existing dependencies (such as angular, ngrx store, etc), but rather aims at fixing the current state of things and make the library safe for our users ASAP. After the PR has been tested and approved, we can take it from there and perform upgrades as there is a couple of improvement needs, such as add
storeFreeze
in testsThe immutability, as I believe, has been achieved sufficiently by using spread operator, rather than by using a third-party library. It was tested on an app which has
storeFreeze
in place (as the last meta reducer):[localStorageSyncReducer, storeFreeze];
In order to achieve the proper deep merge behavior,
lodash.merge
has been added. We can change it toimmutable.js
later, however there is a big footprint and some tree-shakeability complaints on their repo.The PR adds two test cases for filtered scenarios, including a case where the state in save in separate chunks rather than in one combined piece.
Let's test it thoroughly before we merge.