import { ActivationAction, MachineInputSource, MachineState, PriorityExpression } from './index'; import { IHistory } from './interfaces'; import { InputOf, StateOf } from './util'; export declare type StateCombiner, M2 extends StateMachine, S1 extends MachineState = StateOf, S2 extends MachineState = StateOf, I1 extends MachineState = InputOf, I2 extends MachineState = InputOf> = { (params: { first: M1; second: M2; precedence: 'first' | 'second'; }): (S1 & S2); }; export declare type ProgramEntry = { action: ActivationAction; priority: number | PriorityExpression; }; /** * Your state machine should inherit the `StateMachine` class. */ export declare class StateMachine { /** * The active state machine program. * @type {Map} * @private */ private _program; private readonly _history; private _exitState?; /** * Constructor, requires an initial state. * @param {S} initialState The initial state for this machine. * @param inputSource Machine inputs. */ protected constructor(initialState: S, inputSource?: I); /** * The state at program exit. Returns `undefined` unless the program has ended. * @returns {Readonly | undefined} */ readonly exitState: Readonly | undefined; readonly history: IHistory; /** * Advance a single tick and return. * @returns {number} Number of actions fired during this tick. */ step(): number; /** * A blocking call that evaluates the state machine until it exits. * @param {boolean} forever Should we keep going even if the machine stops reacting? * @returns {Readonly|null} Returns the machine's exit state, * or null if the machine halted. */ run(forever?: boolean): Readonly; /** * Resets the state machine to the initial state. * @param {S} initialState (optional) Restart with a different initial state. */ reset(initialState?: S): void; /** * Call this from any action to signal program completion. * @param {Readonly} exitState The exit state to * return from `.run.` */ exit(exitState?: Readonly): void; /** * Combine this machine with a new one. (warning: shared variables in state * may cause emergent behaviour, calls to `exit()` from one machine may abort * early for the other) * @param other Other machine to combine with. * @param precedence Which machine takes precedence when there's a conflict in * state variables. Defaults to 'this'. * @param initialState A combined state to use for the new machine, or a * custom function to combine the states. You may supply a string * {'current'|'initial'} to perform automatic conversion. * Defaults to 'current'. * @return A hybrid event machine exhibiting the behaviour of both parents. */ recombine, OS extends MachineState = StateOf>(other: T, precedence?: 'this' | 'other', initialState?: (OS & S) | StateCombiner, StateMachine> | 'current' | 'initial'): StateMachine; }