Created
May 6, 2017 18:06
-
-
Save davidpatters0n/ea346bf7e8aa3af8689c7bc23d80830e to your computer and use it in GitHub Desktop.
a really skinned version of createStore
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
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