Skip to content

Instantly share code, notes, and snippets.

@mauriciord
Created April 2, 2020 14:38
Show Gist options
  • Save mauriciord/27eeaedca94f3a7eddbe0d39b8694332 to your computer and use it in GitHub Desktop.
Save mauriciord/27eeaedca94f3a7eddbe0d39b8694332 to your computer and use it in GitHub Desktop.
Create Store function - My own
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