Created
April 2, 2020 14:38
-
-
Save mauriciord/27eeaedca94f3a7eddbe0d39b8694332 to your computer and use it in GitHub Desktop.
Create Store function - My own
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
function createStore(initialState, reducer) { | |
let state = initialState; | |
let callback = []; | |
return { | |
listen(cb) { | |
callback = calback.push(cb); | |
}, | |
dispatch(actionCreator) { | |
const newState = reducer(state, actionCreator); | |
state = { ...state, ...newState }; | |
callback(state); | |
}, | |
get() { return state; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment