import { Machine, State, On, SideEffect, Goto, Interpreter, send, SideEffectFunction_T } from '../index'; const beginTimer : SideEffectFunction_T = (ctx, e, self)=>{ setTimeout(()=>{ send(self, ['timer-finished',null]); }, 800); }; const log : SideEffectFunction_T = (ctx, e, self)=>{ console.log(self.state); }; type S = | 'green' | 'yellow' | 'red'; type E = | ['entry',null] | ['timer-finished',null]; type C = {}; const machine = Machine( State('green', On('entry', SideEffect(beginTimer), SideEffect(log) ), On('timer-finished', Goto('yellow') ) ), State('yellow', On('entry', SideEffect(beginTimer), SideEffect(log) ), On('timer-finished', Goto('red') ) ), State('red', On('entry', SideEffect(beginTimer), SideEffect(log) ), On('timer-finished', Goto('green') ) ), ); const actor = Interpreter(machine, {context:{}});