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;
|
||||
state: string;
|
||||
context: any;
|
||||
context: C;
|
||||
eventQueue:Array<Event_T>;
|
||||
subscriptions: Record<string, SubscriptionCallbackFunction_T>;
|
||||
isTransitioning: boolean;
|
||||
isPaused: boolean;
|
||||
start: ()=>Interpreter_T;
|
||||
start: ()=>Interpreter_T<C>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,14 +53,14 @@ export interface Interpreter_T {
|
||||
*
|
||||
* @export
|
||||
* @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]
|
||||
* @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; }
|
||||
//@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; }
|
||||
send(interpreter, ['entry', null] );
|
||||
return interpreter;
|
||||
|
||||
Reference in New Issue
Block a user