Last active
April 15, 2021 09:07
-
-
Save hex13/5f486c83e514dad884a87d17b8fb80a0 to your computer and use it in GitHub Desktop.
Redux-like library in 13 lines
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, state) => { | |
let subscribers = []; | |
return { | |
dispatch: (action) => { | |
state = reducer(state, action); | |
subscribers.forEach(f => f(state)); | |
}, | |
getState: () => state, | |
subscribe: (f) => { | |
subscribers.push(f); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment