joshnuss / svelte-persisted-store

A Svelte store that persists to localStorage
MIT License
1.02k stars 42 forks source link

Preventing cross-Tab state synchronisation #203

Closed Holf closed 1 year ago

Holf commented 1 year ago

Hi,

I see this code, which propagates state changes across instances of the same app in different browsers and tabs:

https://github.com/joshnuss/svelte-persisted-store/blob/dde5eceb183d72e010fb39f83469b0265b5e2c8e/index.ts#L56-L65

Might you consider an option to ~disable this behaviour~ selectively control this behaviour?

I'm thinking perhaps the persisted could additionally return an updateOtherTabs(enabled: boolean), which would allow you to turn this behaviour on and off.

This flag would determine whether or not the set on line 59 is called.

Alternatively, we could have the option to pass in our own handleStorage function?