joshnuss / svelte-persisted-store

A Svelte store that persists to localStorage
MIT License
997 stars 41 forks source link

Adds option to disable syncing across tabs #226

Closed joshnuss closed 9 months ago

joshnuss commented 9 months ago

A new config option to disable syncing across tabs.

Usage

const store = persisted(key, initial, { syncTabs: true })

Default is true, to maintain backwards compatibility.

bertmad3400 commented 9 months ago

When I first looked at this PR, it seemed strange and unnecessary to me, but after thinking the use-cases through, it actually makes a lot of sense. Would be awesome to have in the lib

joshnuss commented 9 months ago

Thanks for the feedback @bertmad3400,

I think it can lead to one tab overwriting another's local storage (race conditions), but in some cases, that's OK.

For example, when storing preferences in local storage, it could be weird if changes in one tab adjusted the other tab. It's fine if the last one to update wins.

github-actions[bot] commented 9 months ago

:tada: This PR is included in version 0.8.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: