arnelenero / simpler-state

The simplest app state management for React
https://simpler-state.js.org
MIT License
478 stars 16 forks source link

Create a plugin for syncing state across tabs #14

Closed jalasem closed 1 year ago

jalasem commented 3 years ago

Is your feature request related to a problem? Please describe. I'm currently using simpler-state in an enterprise project and I need to sync the tabs. For example, when a user logs out, I want him/her to be logged out on all tabs automatically.

Describe the solution you'd like I want every tab to receive an update when anything changes in the state

Describe alternatives you've considered Something like redux sync state

arnelenero commented 3 years ago

This is an interesting use-case. This can be something that could be built complementary to the persistence plug-in. But since even Redux Sync State uses a third-party BroadcastChannel (because official API is not yet widely standard on browsers), adding that 3rd party lib would in itself be 4x the size of simpler-state! This could be a good candidate for an "external" (not bundled) plug-in.

jalasem commented 3 years ago

Kindly guide me on how I can implement it. I don't mind publishing this as the first external plugin for simpler-state

jalasem commented 3 years ago

@arnelenero

arnelenero commented 3 years ago

@jalasem
My rough idea is:

Something like that I think should work.

(Since BroadcastChannel is not yet supported by all browsers, you will need to use this instead: https://github.com/pubkey/broadcast-channel)