Closed
Description
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:
- per store (granular, not global like)
- redux-independent
- only signals are taken into account, not computeds.
- private withWebStorage implementation serves: withLocalStorage/withSessionStorage
withLocalStorage(key: string, {
validatorFn: (obj) => void, // required validator will be less troublesome in the long run
serializer?: (obj) => string, // defaults to JSON.stringify
deserializer?: (string) => obj // defaults to JSON.parse
})
which does the following:
- onInit -> deserialize the storage content if it exists, iterate over signal properties and set them
- whenever an update happens on a signal, it's being serialized and dumped to web storage: withHooks / onInit / effect -> reads the state, serializes it and pushes. This establishes synchronization
Please let me know what you think. If the idea is ok, I'll work on the PR.
Metadata
Metadata
Assignees
Labels
No labels