Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This was a nice thing in the example from Raganwald's blog post. The `transitionsTo` decorator:

  function transitionsTo (stateName, fn) {
    return function (...args) {
      const returnValue = fn.apply(this, args);
      this[STATE] = this[STATES][stateName];
      return returnValue;
    };
  }
By separating the state transitions from the state actions in this way it allows the functional components to be reused much more easily. You can construct the miniplayer using only the states you need with only the transitions you need (rather than obscured/hidden capabilities).



This is a nice approach, thank you for pointing it out.

I'd argue that you are building a separate state machine for the two players, but there is some reuse possible in this approach.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: