UNPKG

@div-int/typedfsm

Version:

A TypeScript finite state machine library

46 lines (45 loc) 1.66 kB
export declare namespace Typed { interface OnPreChange<T, K> { (from: T, to: T, action: K): boolean; } interface OnPostChange<T, K> { (from: T, to: T, action: K): void; } class Transition<T, K> { private _fsm; private _fromState; private _fromAction; private _toState; private _toAction; readonly fromState: T; readonly fromAction: K; readonly toState: T; readonly toAction: K; constructor(fsm: FSM<T, K>, fromState: T, fromAction: K, toState: T, toAction?: K); to(toState: T, toAction?: K): Transition<T, K>; toFrom(toFromState: T, toAction?: K): Transition<T, K>; } class FSM<T, K> { private _defaultState; private _currentState; private _transitions; private _onPreChange; private _onPostChange; readonly defaultState: T; readonly currentState: T; readonly transitions: Transition<T, K>[]; OnPreChange: OnPreChange<T, K>; OnPostChange: OnPostChange<T, K>; constructor(defaultState: T); reset(): void; findTransition(fromState: T, toState: T): Transition<T, K>; isTransition(fromState: T, toState: T): boolean; findAction(fromState: T, toAction: K): Transition<T, K>; isAction(fromState: T, toAction: K): boolean; canChange(changeState: T): boolean; change(changeState: T): T | Error; canDo(doAction: K): boolean; do(doAction: K): T | Error; from(fromState: T, fromAction?: K): Transition<T, K>; } }