Skip to content

Instantly share code, notes, and snippets.

@liximomo
Created April 22, 2016 14:00
Show Gist options
  • Save liximomo/46a38db27cae4dfa709f74cbc6b21170 to your computer and use it in GitHub Desktop.
Save liximomo/46a38db27cae4dfa709f74cbc6b21170 to your computer and use it in GitHub Desktop.
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