Skip to content

Instantly share code, notes, and snippets.

@stevermeister
Created May 18, 2017 10:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevermeister/b9315d65a8cfdee8589f0a9da17ba61a to your computer and use it in GitHub Desktop.
Save stevermeister/b9315d65a8cfdee8589f0a9da17ba61a to your computer and use it in GitHub Desktop.
function createStore(reducer, initialState) {
var currentReducer = reducer;
var currentState = initialState;
var listener = () => {};
return {
getState() {
return currentState;
},
dispatch(action) {
currentState = currentReducer(currentState, action);
listener(); // Note that we added this line!
return action;
},
subscribe(newListener) {
listener = newListener;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment