ifandelse / machina.js

js ex machina - finite state machines in JavaScript
http://machina-js.org/
Other
1.93k stars 147 forks source link

WIP: Add promises returns for deferred calls #160

Open RickyCook opened 6 years ago

RickyCook commented 6 years ago

This allows values to be passed out of the FSM before a state transition happens:

fsm = machina.Fsm({
  ...,
  states: {
    uninitialized: {
      '*': function() {
        this.deferUntilTransitation();
        this.transition('start')
      }
    },
    start: {
      getValue: function() {
        return 'the value'
      }
    }
  }
})

assert await fsm.handle('getValue') === 'the value'

This change is Reviewable