News for hackers. Stuff that matters.
Re:Ask HN: I get React but not Redux by eiriklv on Saturday December 17, 2016 @12:54PM (#13201612)
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.

There are no comments on this comment yet.