add Interpreter().start() for convenient start-upon-creation
This commit is contained in:
+4
-1
@@ -45,6 +45,7 @@ export interface Interpreter_T {
|
||||
subscriptions: Record<string, SubscriptionCallbackFunction_T>;
|
||||
isTransitioning: boolean;
|
||||
isPaused: boolean;
|
||||
start: ()=>Interpreter_T;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +59,9 @@ export interface Interpreter_T {
|
||||
*/
|
||||
export function Interpreter(machine:Machine_T, initialContext:any, initialStateName?:string) : Interpreter_T{
|
||||
if(typeof initialStateName === 'undefined'){ initialStateName = machine.states[0].name; }
|
||||
const interpreter = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, subscriptions: {}, isPaused: true}
|
||||
//@ts-expect-error
|
||||
const interpreter : Interpreter_T = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, subscriptions: {}, isPaused: true};
|
||||
interpreter.start = ()=>{ start(interpreter); return interpreter; }
|
||||
send(interpreter, ['entry', null] );
|
||||
return interpreter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user