-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
611 additions
and
539 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,97 @@ | ||
/** | ||
* Transition grouping to faciliate fluent api | ||
* @class Transitions<T> | ||
*/ | ||
declare class Transitions<T> { | ||
public fsm: FiniteStateMachine<T>; | ||
constructor(fsm: FiniteStateMachine<T>); | ||
public fromStates: T[]; | ||
public toStates: T[]; | ||
declare module TypeState { | ||
/** | ||
* Specify the end state(s) of a transition function | ||
* @method to | ||
* @param ...states {T[]} | ||
* Transition grouping to faciliate fluent api | ||
* @class Transitions<T> | ||
*/ | ||
public to(...states: T[]): void; | ||
} | ||
/** | ||
* Internal representation of a transition function | ||
* @class TransitionFunction<T> | ||
*/ | ||
declare class TransitionFunction<T> { | ||
public fsm: FiniteStateMachine<T>; | ||
public from: T; | ||
public to: T; | ||
constructor(fsm: FiniteStateMachine<T>, from: T, to: T); | ||
} | ||
/*** | ||
* A simple finite state machine implemented in TypeScript, the templated argument is meant to be used | ||
* with an enumeration. | ||
* @class FiniteStateMachine<T> | ||
*/ | ||
declare class FiniteStateMachine<T> { | ||
public currentState: T; | ||
private _startState; | ||
private _transitionFunctions; | ||
private _onCallbacks; | ||
private _exitCallbacks; | ||
private _enterCallbacks; | ||
/** | ||
* @constructor | ||
* @param startState {T} Intial starting state | ||
*/ | ||
constructor(startState: T); | ||
public addTransitions(fcn: Transitions<T>): 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 | ||
*/ | ||
public on(state: T, callback: () => any): FiniteStateMachine<T>; | ||
/** | ||
* 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 | ||
*/ | ||
public onEnter(state: T, callback: () => boolean): FiniteStateMachine<T>; | ||
class Transitions<T> { | ||
public fsm: FiniteStateMachine<T>; | ||
constructor(fsm: FiniteStateMachine<T>); | ||
public fromStates: T[]; | ||
public toStates: T[]; | ||
/** | ||
* Specify the end state(s) of a transition function | ||
* @method to | ||
* @param ...states {T[]} | ||
*/ | ||
public to(...states: T[]): void; | ||
public toAny(states: any): void; | ||
} | ||
/** | ||
* 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 | ||
* Internal representation of a transition function | ||
* @class TransitionFunction<T> | ||
*/ | ||
public onExit(state: T, callback: () => boolean): FiniteStateMachine<T>; | ||
/** | ||
* Declares the start state(s) of a transition function, must be followed with a '.to(...endStates)' | ||
* @method from | ||
* @param ...states {T[]} | ||
*/ | ||
public from(...states: T[]): Transitions<T>; | ||
private _validTransition(from, to); | ||
/** | ||
* Check whether a transition to a new state is valide | ||
* @method canGo | ||
* @param state {T} | ||
*/ | ||
public canGo(state: T): boolean; | ||
/** | ||
* Transition to another valid state | ||
* @method go | ||
* @param state {T} | ||
*/ | ||
public go(state: T): 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 | ||
class TransitionFunction<T> { | ||
public fsm: FiniteStateMachine<T>; | ||
public from: T; | ||
public to: T; | ||
constructor(fsm: FiniteStateMachine<T>, from: T, to: T); | ||
} | ||
/*** | ||
* A simple finite state machine implemented in TypeScript, the templated argument is meant to be used | ||
* with an enumeration. | ||
* @class FiniteStateMachine<T> | ||
*/ | ||
public reset(): void; | ||
private _transitionTo(state); | ||
class FiniteStateMachine<T> { | ||
public currentState: T; | ||
private _startState; | ||
private _transitionFunctions; | ||
private _onCallbacks; | ||
private _exitCallbacks; | ||
private _enterCallbacks; | ||
/** | ||
* @constructor | ||
* @param startState {T} Intial starting state | ||
*/ | ||
constructor(startState: T); | ||
public addTransitions(fcn: Transitions<T>): 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 | ||
*/ | ||
public on(state: T, callback: (from?: T) => any): FiniteStateMachine<T>; | ||
/** | ||
* 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 | ||
*/ | ||
public onEnter(state: T, callback: (from?: T) => boolean): FiniteStateMachine<T>; | ||
/** | ||
* 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 | ||
*/ | ||
public onExit(state: T, callback: (to?: T) => boolean): FiniteStateMachine<T>; | ||
/** | ||
* Declares the start state(s) of a transition function, must be followed with a '.to(...endStates)' | ||
* @method from | ||
* @param ...states {T[]} | ||
*/ | ||
public from(...states: T[]): Transitions<T>; | ||
public fromAny(states: any): Transitions<T>; | ||
private _validTransition(from, to); | ||
/** | ||
* Check whether a transition to a new state is valide | ||
* @method canGo | ||
* @param state {T} | ||
*/ | ||
public canGo(state: T): boolean; | ||
/** | ||
* Transition to another valid state | ||
* @method go | ||
* @param state {T} | ||
*/ | ||
public go(state: T): 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 | ||
*/ | ||
public reset(): void; | ||
private _transitionTo(state); | ||
} | ||
} |
Oops, something went wrong.