Hacker News new | past | comments | ask | show | jobs | submit login

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.



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: