Skip to content

Instantly share code, notes, and snippets.

@hex13
Last active April 15, 2021 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hex13/5f486c83e514dad884a87d17b8fb80a0 to your computer and use it in GitHub Desktop.
Save hex13/5f486c83e514dad884a87d17b8fb80a0 to your computer and use it in GitHub Desktop.
Redux-like library in 13 lines
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