-
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
fix: storage syncing for feature stores #249
base: master
Are you sure you want to change the base?
Conversation
ea77578
to
5aaf459
Compare
@BBlackwo Could you please review the changes whenever you find some time. Thanks |
Any plan on reviewing/merging that PR soon @BBlackwo ? |
Can we merge this please? I would love to use it also instead of defining it in the root store. |
+1 Also defining it in the root store means I must create maps and the like to hold the reducers, = more code. Also really appreciate this going in. |
Hey thanks for the PR @Abhirocks889! Given it's a fairly significant change I'm not sure when I'll get a chance to review it properly. I'm maintaining this project in my spare time, doing my best. |
@BBlackwo Is there anything I can do to lend a hand? I did have a nosey at the PR and it did seem a large change. If I can do some of the lifting, then happy to help. I use this library daily and need this feature. |
If some of you that are interested can test it out in your projects and give feedback that'd be helpful. You should be able to use the branch directly in your package.json: "dependencies": {
"ngrx-store-localstorage": "Abhirocks889/ngrx-store-localstorage#fix\/feature-stores"
} |
@inthegarage see the above comment about testing the branch. Also happy for anyone to review the PR and leave comments. You don't have to be a maintainer to review the PRs 🙂 |
Hello @BBlackwo , I agree that it is maybe a significant change but a non-breaking one as it is controlled by the flag in the |
@BBlackwo At the moment I could not get the feature to work, I'll have a another go later. From a code point of view it does seem fine, although I'd like to see the use of the boolean changed, so that I don't have to keep saying "true" all the time. I'll make a formal comment once I have tested it properly. The linting and tests all pass though, so that's good. |
@Abhirocks889 I'm trying to test your PR, however when I do a build_dist I get the following error:
This is when I do npm run build_dist Everything node_modules wise installed correctly. Do you know the correct build sequence? |
any updates on this bug? |
Summary
This PR introduces a fix for the issue not syncing with feature stores
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Current Behavior
Currently, it is not possible to sync the state of a feature store by adding the meta reducer inside the feature module. Instead, it has to be done within the app module for all the feature stores.
Issue Number: 96
New Behavior
With this fix, it is now possible to sync the state of any store directly within the feature module in addition to being able to perform the same from within the app module.
Breaking Change?
Other information
As per my understanding and observation, the basic difference between syncing a state in the root app module via
StoreModule.forRoot
versus in a feature throughStoreModule.forFeature
is the fact that in the former, thesyncStateUpdate
method receives the entire State where each feature is described by key-value pairs (eg:{cart: {items: []} checkout: {methods: []}}
), whereas in the latter, thesyncStateUpdate
method receives the respective feature slice state (eg:{items: []}
for cart and{methods: []}
for checkout).PFA the screenshots illustrating the same:
Syncing in the app module
Syncing in the feature module
Therefore, the latter scenario was not handled as it always looked for the key specified in the config and fetch the corresponding state for the key.
The fix introduces a new boolean property to the
LocalStorageConfig
calledforFeature
which when enabled, handles the state syncing for feature stores.