import { StateConfiguration } from './state-configuration'; import { StateMachineInfo } from './reflection/state-machine-info'; import { Transition } from './transition'; import { StateContext } from './state-context'; import { FiringMode } from './firing-mode'; /** * Models behaviour as transitions between a finite set of states. * * @export * @class StateMachine * @template TState The type used to represent the states. * @template TTrigger The type used to represent the triggers that cause state transitions. * @link https://github.com/dotnet-state-machine/stateless/blob/dev/src/Stateless/StateMachine.cs */ export declare class StateMachine extends StateContext { private readonly _stateConfiguration; private readonly _stateAccessor; private readonly _stateMutator; private _unhandledTriggerAction; private readonly _onTransitionedEvent; private readonly _eventQueue; private _firing; private readonly _fireHandler; /** * Creates an instance of StateMachine. * @param {(TState | { stateAccessor: () => TState; stateMutator: (state: TState) => any; })} initialState * @memberof StateMachine */ constructor(initialState: TState | { accessor: () => TState; mutator: (state: TState) => any; }, firingMode?: FiringMode); /** * The current state. * * @memberof StateMachine */ /** * The initial state * * @type {TState} * @memberof StateMachine */ state: TState; /** * The currently-permissible trigger values. * * @readonly * @type {Promise} * @memberof StateMachine */ readonly permittedTriggers: Promise; /** * The currently-permissible trigger values. * * @param {...any[]} args * @returns {Promise} * @memberof StateMachine */ getPermittedTriggers(...args: any[]): Promise; /** * Get current presentation. * * @readonly * @type {StateRepresentation} * @memberof StateMachine */ private readonly currentRepresentation; /** * Provides an info object which exposes the states, transitions, and actions of this machine. * * @param {string} stateType * @param {string} triggerType * @returns {StateMachineInfo} * @memberof StateMachine */ getInfo(stateType?: string, triggerType?: string): StateMachineInfo; private getRepresentation; /** * Begin configuration of the entry/exit actions and allowed transitions * when the state machine is in a particular state. * * @param {TState} state The state to configure. * @returns {StateConfiguration} >A configuration object through which the state can be configured. * @memberof StateMachine */ configure(state: TState): StateConfiguration; /** * Transition from the current state via the specified trigger. * The target state is determined by the configuration of the current state. * Actions associated with leaving the current state and entering the new one * will be invoked. * * @param {TTrigger} trigger The trigger to fire. * @returns {Promise} * @memberof StateMachine * @throws The current state does not allow the trigger to be fired. */ fire(trigger: TTrigger, ...args: any[]): Promise; /** * Activates current state. Actions associated with activating the currrent state * will be invoked. The activation is idempotent and subsequent activation of the same current state * will not lead to re-execution of activation callbacks. * * @returns {Promise} * @memberof StateMachine */ activate(): Promise; /** * Deactivates current state. Actions associated with deactivating the currrent state * will be invoked. The deactivation is idempotent and subsequent deactivation of the same current state * will not lead to re-execution of deactivation callbacks. * * @returns {Promise} * @memberof StateMachine */ deactivate(): Promise; /** * Determine how to Fire the trigger * * @private * @param {TTrigger} trigger The trigger. * @param {...any[]} args A variable-length parameters list containing arguments. * @returns {Promise} * @memberof StateMachine */ private internalFire; /** * Queue events and then fire in order. * If only one event is queued, this behaves identically to the non-queued version. * * @private * @param {TTrigger} trigger The trigger. * @param {any[]} args A variable-length parameters list containing argument * @returns {Promise} * @memberof StateMachine */ private internalFireQueued; /** * This method handles the execution of a trigger handler. It finds a handle, then updates the current state information. * * @private * @param {TTrigger} trigger * @param {any[]} args * @returns {Promise} * @memberof StateMachine */ private internalFireOne; private handleReentryTrigger; private handleTransitioningTrigger; /** * Override the default behaviour of throwing an exception when an unhandled trigger * * @param {(((state: TState, trigger: TTrigger, unmetGuards: string[]) => any | Promise))} unhandledTriggerAction * @returns {*} * @memberof StateMachine */ onUnhandledTrigger(unhandledTriggerAction: ((state: TState, trigger: TTrigger, unmetGuards: string[]) => any | Promise)): any; /** * Determine if the state machine is in the supplied state. * * @param {TState} state * @returns {boolean} True if the current state is equal to, or a substate of, the supplied state. * @memberof StateMachine */ isInState(state: TState): boolean; /** * Returns true if can be fired in the current state. * * @param {TTrigger} trigger Trigger to test. * @returns {boolean} True if the trigger can be fired, false otherwise. * @memberof StateMachine */ canFire(trigger: TTrigger): Promise; /** * A human-readable representation of the state machine. * * @returns {string} A description of the current state and permitted triggers. * @memberof StateMachine */ toString(): Promise; private defaultUnhandledTriggerAction; /** * Registers a callback that will be invoked every time the statemachine transitions from one state into another. * * @param {((transition: Transition) => any | Promise)} onTransitionAction The action to execute, accepting the details * @returns {*} * @memberof StateMachine */ onTransitioned(onTransitionAction: (transition: Transition) => any | Promise): any; } //# sourceMappingURL=state-machine.d.ts.map