eonarheim / TypeState

A strongly typed finite state machine for TypeScript
http://eonarheim.github.io/TypeState/example/
BSD 2-Clause "Simplified" License
272 stars 28 forks source link

Pass in from/to in callbacks #2

Closed kamranayub closed 10 years ago

kamranayub commented 10 years ago

This way I can better handle if I want to cancel a transition based on the source or destination.

fsm.on(MyState.Red, (from: MyState) => {
  if (from === MyState.Green) {
    console.log("Transitioned from green to red");
  }
});

fsm.onEnter(MyState.Red, (from: MyState) => {
  if (from === MyState.Green) {
    console.log("Transitioning from green to red");
  }
});

fsm.onExit(MyState.Red, (to: MyState) => {
  if (to === MyState.Green) {
    console.log("Transitioning from red to green");
  }
});
eonarheim commented 10 years ago

Agreed