Skip to content

Instantly share code, notes, and snippets.

@Scarysize
Last active May 6, 2020 05:54
Show Gist options
  • Save Scarysize/f2fe922b9b93c74594be8c8ccd103239 to your computer and use it in GitHub Desktop.
Save Scarysize/f2fe922b9b93c74594be8c8ccd103239 to your computer and use it in GitHub Desktop.
export function createStorageListener(store) {
return event => {
// the storage event tells you which value changed
const {action} = JSON.parse(event.newValue);
store.dispatch(action);
}
}
// when you setup the app
const store = initStore(/*...*/);
if (/* check if this is a 'follower' */) {
window.addEventListener('storage', createStorageListener(store));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment