Created
May 18, 2017 10:10
-
-
Save stevermeister/b9315d65a8cfdee8589f0a9da17ba61a 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 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