Skip to content

Instantly share code, notes, and snippets.

@davidpatters0n
Created May 6, 2017 18:06
Show Gist options
  • Save davidpatters0n/ea346bf7e8aa3af8689c7bc23d80830e to your computer and use it in GitHub Desktop.
Save davidpatters0n/ea346bf7e8aa3af8689c7bc23d80830e to your computer and use it in GitHub Desktop.
a really skinned version of createStore
const createStore = (reducer) => {
let state = reducer();
const listeners = [];
const store = {
getState() {
return state;
},
dispatch(action) {
state = reducer(state, action);
listeners.forEach((callback) => {
callback();
})
},
subscribe(callback) {
listeners.push(callback)
}
}
return store;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment