State.d.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
  2. import { StateNode } from './StateNode';
  3. import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
  4. import { BaseActionObject, Prop } from './types';
  5. export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
  6. export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
  7. /**
  8. * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
  9. */
  10. export declare const isState: typeof isStateConfig;
  11. export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
  12. export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
  13. value: any;
  14. context: TContext;
  15. }, TResolvedTypesMeta = TypegenDisabled> {
  16. value: StateValue;
  17. context: TContext;
  18. historyValue?: HistoryValue | undefined;
  19. history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
  20. actions: Array<ActionObject<TContext, TEvent>>;
  21. activities: ActivityMap;
  22. meta: any;
  23. events: TEvent[];
  24. event: TEvent;
  25. _event: SCXML.Event<TEvent>;
  26. _sessionid: string | null;
  27. /**
  28. * Indicates whether the state has changed from the previous state. A state is considered "changed" if:
  29. *
  30. * - Its value is not equal to its previous value, or:
  31. * - It has any new actions (side-effects) to execute.
  32. *
  33. * An initial state (with no history) will return `undefined`.
  34. */
  35. changed: boolean | undefined;
  36. /**
  37. * Indicates whether the state is a final state.
  38. */
  39. done: boolean | undefined;
  40. /**
  41. * The enabled state nodes representative of the state value.
  42. */
  43. configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
  44. /**
  45. * The next events that will cause a transition from the current state.
  46. */
  47. nextEvents: Array<TEvent['type']>;
  48. /**
  49. * The transition definitions that resulted in this state.
  50. */
  51. transitions: Array<TransitionDefinition<TContext, TEvent>>;
  52. /**
  53. * An object mapping actor IDs to spawned actors/invoked services.
  54. */
  55. children: Record<string, ActorRef<any>>;
  56. tags: Set<string>;
  57. machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, any, TResolvedTypesMeta> | undefined;
  58. /**
  59. * Creates a new State instance for the given `stateValue` and `context`.
  60. * @param stateValue
  61. * @param context
  62. */
  63. static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
  64. /**
  65. * Creates a new State instance for the given `config`.
  66. * @param config The state config
  67. */
  68. static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any, any, any>;
  69. /**
  70. * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
  71. * @param stateValue
  72. * @param context
  73. */
  74. static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context: TC): State<TC, TE>;
  75. /**
  76. * Creates a new State instance.
  77. * @param value The state value
  78. * @param context The extended state
  79. * @param historyValue The tree representing historical values of the state nodes
  80. * @param history The previous state
  81. * @param actions An array of action objects to execute as side-effects
  82. * @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
  83. * @param meta
  84. * @param events Internal event queue. Should be empty with run-to-completion semantics.
  85. * @param configuration
  86. */
  87. constructor(config: StateConfig<TContext, TEvent>);
  88. /**
  89. * Returns an array of all the string leaf state node paths.
  90. * @param stateValue
  91. * @param delimiter The character(s) that separate each subpath in the string state node path.
  92. */
  93. toStrings(stateValue?: StateValue, delimiter?: string): string[];
  94. toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine" | "toStrings" | "toJSON" | "matches" | "hasTag" | "can"> & {
  95. tags: string[];
  96. };
  97. /**
  98. * Whether the current state value is a subset of the given parent state value.
  99. * @param parentStateValue
  100. */
  101. matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : never>(parentStateValue: TSV): boolean;
  102. matches<TSV extends TResolvedTypesMeta extends TypegenDisabled ? TTypestate['value'] : never>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
  103. value: TSV;
  104. context: any;
  105. } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
  106. value: TSV;
  107. };
  108. /**
  109. * Whether the current state configuration has a state node with the specified `tag`.
  110. * @param tag
  111. */
  112. hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'tags'> : string): boolean;
  113. /**
  114. * Determines whether sending the `event` will cause a non-forbidden transition
  115. * to be selected, even if the transitions have no actions nor
  116. * change the state value.
  117. *
  118. * @param event The event to test
  119. * @returns Whether the event will cause a transition
  120. */
  121. can(event: TEvent | SimpleEventsOf<TEvent>['type']): boolean;
  122. }
  123. //# sourceMappingURL=State.d.ts.map