add generic type param to Interpreter for context
This commit is contained in:
+6
-6
@@ -37,15 +37,15 @@ export const Context = function(fn:ContextMutationFunction_T) : ContextMutation_
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface Interpreter_T {
|
export interface Interpreter_T<C=any> {
|
||||||
machine: Machine_T;
|
machine: Machine_T;
|
||||||
state: string;
|
state: string;
|
||||||
context: any;
|
context: C;
|
||||||
eventQueue:Array<Event_T>;
|
eventQueue:Array<Event_T>;
|
||||||
subscriptions: Record<string, SubscriptionCallbackFunction_T>;
|
subscriptions: Record<string, SubscriptionCallbackFunction_T>;
|
||||||
isTransitioning: boolean;
|
isTransitioning: boolean;
|
||||||
isPaused: boolean;
|
isPaused: boolean;
|
||||||
start: ()=>Interpreter_T;
|
start: ()=>Interpreter_T<C>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,14 +53,14 @@ export interface Interpreter_T {
|
|||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @param {Machine_T} machine
|
* @param {Machine_T} machine
|
||||||
* @param {InitialContextFunction_T} initialContextFunction - in the form of a function rather than a direct value, so as to facilitate co-initialization of peer interpreters. Otherwise, the "parent" interpreter will start, but without a reference to a running child interpreter which it might expect to exist.
|
* @param {any} initialContext
|
||||||
* @param {?string} [initialStateName]
|
* @param {?string} [initialStateName]
|
||||||
* @returns {Interpreter_T}
|
* @returns {Interpreter_T}
|
||||||
*/
|
*/
|
||||||
export function Interpreter(machine:Machine_T, initialContext:any, initialStateName?:string) : Interpreter_T{
|
export function Interpreter<C>(machine:Machine_T, initialContext:any, initialStateName?:string) : Interpreter_T<C>{
|
||||||
if(typeof initialStateName === 'undefined'){ initialStateName = machine.states[0].name; }
|
if(typeof initialStateName === 'undefined'){ initialStateName = machine.states[0].name; }
|
||||||
//@ts-expect-error
|
//@ts-expect-error
|
||||||
const interpreter : Interpreter_T = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, subscriptions: {}, isPaused: true};
|
const interpreter : Interpreter_T<C> = {machine, state: initialStateName, context:initialContext, eventQueue:[], isTransitioning:false, subscriptions: {}, isPaused: true};
|
||||||
interpreter.start = ()=>{ start(interpreter); return interpreter; }
|
interpreter.start = ()=>{ start(interpreter); return interpreter; }
|
||||||
send(interpreter, ['entry', null] );
|
send(interpreter, ['entry', null] );
|
||||||
return interpreter;
|
return interpreter;
|
||||||
|
|||||||
Reference in New Issue
Block a user