-
Notifications
You must be signed in to change notification settings - Fork 34
proposal: withLocalStorage/withSessionStorage #11
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
Comments
Hiho, sure thing. To me, the only question is about the |
@rainerhahnekamp form my experience, working with any web storage is vulnerable to issues with versioning serialized data structures sooner or later. Example:
Anyway I'm open to suggestions - what is your take - make it optional? Or a different approach (dunno, migrating)? |
I think adding withStorage would be a better approach, default it to session maybe, but allow you to pass in any storage interface https://developer.mozilla.org/en-US/docs/Web/API/Storage its a simple API so it's extendable too. I also think make validatorfn optional too. |
@markostanimirovic: as far as I know the NgRx team has plans to come up with such a feature in the future as well. could you please comment here, how concrete those plans are? I guess @ducin doesn't want to spend his time implementing it and - all of a sudden - an official pops up. |
@ducin yeah, I'd say to get started very quickly that we provide a validator function by default. We can still discuss what that one should do. I also think that the use cases you mentioned along different strategies should definitely show up in the documentation. |
oh definitely! |
@Jordan-Hall do you mean pass the global object (not "interface"), e.g. Subjectively, I don't have strong preference with |
@ducin correct sorry pass in the object withStorage(localStorage) but for types use the storage interface. |
Hey 👋 That's true, we're considering introducing this plugin to the core library, but it's still not finally confirmed. ngrx/platform#3997 Here is the implementation of the Note: To make this feature SSR-friendly, the storage factory needs to be passed as an input argument instead of a storage: export const CounterStore = signalStore(
withState({ count: 0 }),
withStorageSync({
key: 'counter',
// if not passed, `localStorage` is used as the default
storage: () => sessionStorage,
})
); |
When I created ngrx/plattform#4180 a little over motivated at the end of 2023 @rainerhahnekamp suggested opening a PR for ngrx-toolkit which can be found here ngrx-toolkit#7. |
I actually think the PR should get merged it seems perfect |
Yes, so I'd say that if @bohoffi and @ducin want to take on the risk that it might become redundant, we can add it to the toolkit. So if you both agree (@Jordan-Hall of course you are invited to join here as well), we should maybe start discussing the API. PS: @bohoffi thousand apologies but I didn't see your PR. I guess it was due to the day. "New Year's Eve" is my birthday and there is usually a trend that everybody else celebrates on that (but maybe for other reasons :) ) |
@rainerhahnekamp I'm not in a hurry as I'm using the implementation as provided via the PR in a private project already. (Well not everyone's having such a big bang birthday party 😂) |
With version 0.0.7, the sync storage extension is now available. @ducin, if you want to add or modify some of the features... we would be ready. |
Closing this issue since no further comments for 10 days and the version of @bohoffi is already available. |
Hi Angular Architects!
Here's my proposal for a custom signalStoreFeature to be included within this library. I wanted to make my own library, but it makes much more sense to join forces. If you're open for contributions/PRs from outside...?
The idea behind this web storage synchronization is:
which does the following:
Please let me know what you think. If the idea is ok, I'll work on the PR.
The text was updated successfully, but these errors were encountered: