4 ms·
An alternative thought model of Redux could be represented like this: function createStore(reducer) { let actions = []; let subscribers = []; re
by eiriklv 10y ago
An alternative thought model of Redux could be represented like this:
function createStore(reducer) {
let actions = [];
let subscribers = [];
return {
getState() {
return actions.reduce(reducer, undefined);
},
subscribe(subscriber) {
subscribers.push(subscriber);
},
dispatch(action) {
actions.push(action);
subscribers.forEach(subscriber => subscriber());
}
};
}
If you start out by digging into how Array.reduce works you're 90% there, which is where the name "Redux" comes from.