Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Abhirocks889
Copy link

@Abhirocks889 Abhirocks889 commented May 12, 2023

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:

  • The commit message follows our guidelines:
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

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?

  • Yes
  • No

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 through StoreModule.forFeature is the fact that in the former, the syncStateUpdate method receives the entire State where each feature is described by key-value pairs (eg: {cart: {items: []} checkout: {methods: []}}), whereas in the latter, the syncStateUpdate 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

app-module-storage-sync

Syncing in the feature module

lazy-storage-sync

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 called forFeature which when enabled, handles the state syncing for feature stores.

Note: PFA a stackblitz that illustrates the behavior after the fix: https://stackblitz.com/edit/angular-ivy-bdu1sx?file=README.md

@Abhirocks889
Copy link
Author

@BBlackwo Could you please review the changes whenever you find some time. Thanks

@BBlackwo BBlackwo added the feature stores Functionality related to feature stores / modules label May 24, 2023
@tinesoft
Copy link

tinesoft commented Jul 18, 2023

Any plan on reviewing/merging that PR soon @BBlackwo ?
It would be a very welcome addition/fix to this great library !

@faileon
Copy link

faileon commented Jul 19, 2023

Can we merge this please? I would love to use it also instead of defining it in the root store.

@inthegarage
Copy link

inthegarage commented Jul 24, 2023

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.

@BBlackwo
Copy link
Collaborator

BBlackwo commented Jul 26, 2023

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.

@inthegarage
Copy link

@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.

@BBlackwo
Copy link
Collaborator

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"
}

@BBlackwo
Copy link
Collaborator

@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 🙂

@Abhirocks889
Copy link
Author

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 StorageConfig. Having said that, it would be great for others to try out the change and provide feedback.

@inthegarage
Copy link

inthegarage commented Jul 31, 2023

@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.

@inthegarage
Copy link

@Abhirocks889 I'm trying to test your PR, however when I do a build_dist I get the following error:

Could not resolve "./lib/index" from "dist/lib/esm2020/public_api.mjs"

This is when I do npm run build_dist

Everything node_modules wise installed correctly. Do you know the correct build sequence?

@dofamine
Copy link

any updates on this bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature stores Functionality related to feature stores / modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants