/** * Transition grouping to faciliate fluent api * @class Transitions */ export declare class Transitions { fsm: FiniteStateMachine; constructor(fsm: FiniteStateMachine); fromStates: T[]; toStates: T[]; /** * Specify the end state(s) of a transition function * @method to * @param ...states {T[]} */ to(...states: T[]): TransitionFunctions; toAny(states: any): void; } /** * Internal representation of a transition function * @class TransitionFunction */ export declare class TransitionFunction { fsm: FiniteStateMachine; from: T; to: T; constructor(fsm: FiniteStateMachine, from: T, to: T); } export declare class TransitionFunctions extends Array> { private fsm; constructor(fsm: FiniteStateMachine); on(trigger: number, callback?: (from: T, to: T) => any): void; } /*** * A simple finite state machine implemented in TypeScript, the templated argument is meant to be used * with an enumeration. * @class FiniteStateMachine */ export declare class FiniteStateMachine { currentState: T; private _startState; private _transitionFunctions; private _onCallbacks; private _exitCallbacks; private _enterCallbacks; private _triggers; /** * @constructor * @param startState {T} Intial starting state */ constructor(startState: T); addTransitions(fcn: Transitions): TransitionFunctions; addEvent(trigger: number, fromState: T, toState: T): void; trigger(trigger: number, options?: Object): void; /** * Listen for the transition to this state and fire the associated callback * @method on * @param state {T} State to listen to * @param callback {fcn} Callback to fire */ on(state: T, callback: (from?: T, to?: T) => any): FiniteStateMachine; /** * Listen for the transition to this state and fire the associated callback, returning * false in the callback will block the transition to this state. * @method on * @param state {T} State to listen to * @param callback {fcn} Callback to fire */ onEnter(state: T, callback: (from?: T, options?: Object) => boolean): FiniteStateMachine; /** * Listen for the transition to this state and fire the associated callback, returning * false in the callback will block the transition from this state. * @method on * @param state {T} State to listen to * @param callback {fcn} Callback to fire */ onExit(state: T, callback: (to?: T, options?: Object) => boolean): FiniteStateMachine; /** * Declares the start state(s) of a transition function, must be followed with a '.to(...endStates)' * @method from * @param ...states {T[]} */ from(...states: T[]): Transitions; fromAny(states: any): Transitions; private _validTransition; /** * Check whether a transition to a new state is valide * @method canGo * @param state {T} */ canGo(state: T): boolean; /** * Transition to another valid state * @method go * @param state {T} */ go(state: T, options?: Object): void; /** * This method is availble for overridding for the sake of extensibility. * It is called in the event of a successful transition. * @method onTransition * @param from {T} * @param to {T} */ onTransition(from: T, to: T, options?: Object): void; /** * Reset the finite state machine back to the start state, DO NOT USE THIS AS A SHORTCUT for a transition. * This is for starting the fsm from the beginning. * @method reset */ reset(): void; private _transitionTo; }