Closed zip-fa closed 1 month ago
Hi, I was also thinking of having something like this one https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event
When the storage changes, we also emit that value back to the signal
Yes, this would be helpful to "notify changes" from another tab and synchronise signals state between tabs with zero efforts
@zip-fa I opened a PR https://github.com/nartc/ngxtension-platform/pull/295 for this. It's a bit different from what you proposed, but it is similar to an implementation I had created for something else.
Would love to get your feedback on both implementation and ease of use.
Maybe this post will be useful to have local storage type safe ;) https://blog.herodevs.com/interact-with-browser-storage-type-safe-fee0ad07428f
Closing this as already merged https://github.com/ngxtension/ngxtension-platform/blob/main/libs/ngxtension/inject-local-storage/src/inject-local-storage.ts
We just need docs for it now.
Hi. I have little utility-function to sync my signal properties with local storage, which probably could be added to ngextension.
local-storage.ts:
sync-with-local-storage.ts:
usage:
It will:
1) create
testNamespace
key in localstorage with this serialized json structure:{"test": "123"}
2) get value from localStorage & set it to signal on class init phase (if exists) 3) trigger on every signal change & update local storage 4) not throw error in SSR env