diff --git a/src/index.ts b/src/index.ts index d764f93..d22695b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,6 +26,11 @@ export const On = function(eventName:E[0], ...reactions: export const Do = function(fn:DoFn_T) : Do_T{ return {type:'Do', fn}; }; export const Goto = function(targetStateName:S) : Goto_T { return {type:'Goto', targetStateName} }; +interface Tick_T { + doFunctions: Array +}; +const Tick = function(doFunctions : Array) : Tick_T{ return {doFunctions}; }; + export interface Interpreter_T { machine: Machine_T; @@ -62,7 +67,21 @@ function getOns(state : State_T, event:E) : Array(interpreter : Interpreter_T, event:E){ const state = getState(interpreter); const ons = getOns(state, event); - ons.forEach + const tick = Tick(ons + .map((on)=>on.reactions) + .flat() + .map((reaction)=>{ + if(reaction.type === 'Do'){ + return reaction.fn; + } + else if(reaction.type === 'Goto'){ + return (ctx,e,self)=>{}; + } + else{ + return (ctx,e,self)=>{}; + } + }) + ); } export const Spawn = function(){};