Created
April 22, 2016 14:00
-
-
Save liximomo/46a38db27cae4dfa709f74cbc6b21170 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
function observeStore(store, select, onChange) { | |
let currentState; | |
function handleChange() { | |
let nextState = select(store.getState()); | |
if (nextState !== currentState) { | |
currentState = nextState; | |
onChange(currentState); | |
} | |
} | |
let unsubscribe = store.subscribe(handleChange); | |
handleChange(); | |
return unsubscribe; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment