finestate
Version:
Powerful and easy to use Finite State Machine with hierarchy, orthogonal states and 100% tests coverage.
56 lines (52 loc) • 2.38 kB
TypeScript
// Generated by dts-bundle v0.7.3
export const ThrowMsg_TheSameClassUsedTwiceInTheFSMDescription = "The same class is used twice in FSM description: ";
export const ThrowMsg_TheStateIsNotRegistered = "The state is not registered in FSM: ";
export const ThrowMsg_TransitionFromTransitionOrInitIsNotAllowed = "Transition from transition or init is not allowed.";
export const ThrowMsg_TransitionFromOneOrthoAreaToAnotherIsNotAllowed = "Transition from one ortho area to another is not allowed.";
export class Fsm {
constructor(descs: StateDesc[]);
init(params?: StateParams): void;
get rootState(): State | null;
transit(from: State, to: StateType, params?: StateParams): boolean;
dispatch(evt: EventType): boolean;
}
export const ThrowMsg_DestroyedStateUsed = "Destroyed state used";
export type StateType = new (...args: any[]) => State;
export type StateDesc = [StateType, ...StateDesc[][]];
export function stateDesc(stateType: StateType, ...orthoAreas: StateDesc[][]): StateDesc;
export abstract class Event {
}
export type EventType = Event | string | number;
export function stateTypeFromStateDesc(stateDesc: StateDesc): StateType;
export function numOrthoChildrenFromStateDesc(stateDesc: StateDesc): number;
export function orthoChildrenFromStateDesc(stateDesc: StateDesc, index: number): StateDesc[];
export enum DispatchOrder {
Ascending = 0,
Descending = 1
}
export enum DispatchOrthoPolicy {
StopOnProcessed = 0,
DontStopOnProcessed = 1
}
export interface StateParams {
}
export abstract class State {
protected dispatchOrder: DispatchOrder;
protected dispatchOrthoPolicy: DispatchOrthoPolicy;
constructor(fsm: Fsm, parentState: State | null, orthoIndex: number, numOrthoChildren: number);
context<T extends State>(state: new (...args: any[]) => T): T | null;
get fsm(): Fsm;
get parent(): State | null;
get children(): (State | null)[];
get orthoIndex(): number;
get destroyed(): boolean;
_init(params: StateParams): void;
dispatchToChildren(evt: EventType): boolean;
dispatch(evt: EventType): boolean;
processEvent(_evt: EventType): boolean | void | Promise<boolean | void>;
_destroy(): void;
transit(stateType: StateType, params?: StateParams): boolean;
protected initParams(_params: StateParams): void;
protected init(): void;
protected destroy(): void;
}