Last active
March 29, 2018 20:12
-
-
Save sarjumulmi/3103f444bb131cf765db997ff289b197 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 const createStore = (reducer, initialState = {}) => { | |
let currentState = initialState; | |
const listeners = []; | |
function getState() { | |
return currentState; | |
} | |
function dispatch(action) { | |
currentState = reducer(currentState, action); | |
listeners.forEach(listener => listener()); | |
} | |
function subscribe(listener) { | |
listeners.push(listener); | |
} | |
return { | |
getState, | |
dispatch, | |
subscribe | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment