Last active
May 6, 2020 05:54
-
-
Save Scarysize/f2fe922b9b93c74594be8c8ccd103239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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