begin building Tick

main
Brian Sakal 2 years ago
parent 8806ce48d7
commit e37161d3a0

@ -26,6 +26,11 @@ export const On = function<S,E extends EventShape>(eventName:E[0], ...reactions:
export const Do = function(fn:DoFn_T) : Do_T{ return {type:'Do', fn}; }; export const Do = function(fn:DoFn_T) : Do_T{ return {type:'Do', fn}; };
export const Goto = function<S>(targetStateName:S) : Goto_T<S> { return {type:'Goto', targetStateName} }; export const Goto = function<S>(targetStateName:S) : Goto_T<S> { return {type:'Goto', targetStateName} };
interface Tick_T {
doFunctions: Array<DoFn_T>
};
const Tick = function(doFunctions : Array<DoFn_T>) : Tick_T{ return {doFunctions}; };
export interface Interpreter_T<S,E extends EventShape,C> { export interface Interpreter_T<S,E extends EventShape,C> {
machine: Machine_T<S,E>; machine: Machine_T<S,E>;
@ -62,7 +67,21 @@ function getOns<S,E extends EventShape>(state : State_T<S,E>, event:E) : Array<O
export function send<S,E extends EventShape,C>(interpreter : Interpreter_T<S,E,C>, event:E){ export function send<S,E extends EventShape,C>(interpreter : Interpreter_T<S,E,C>, event:E){
const state = getState(interpreter); const state = getState(interpreter);
const ons = getOns(state, event); 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(){}; export const Spawn = function(){};

Loading…
Cancel
Save