utils.d.ts 6.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior, RaiseActionObject, SendActionObject } from './types';
  2. import { StateNode } from './StateNode';
  3. import { State } from './State';
  4. import { Actor } from './Actor';
  5. import { ActionObject, AnyStateMachine } from '.';
  6. export declare function keys<T extends object>(value: T): Array<keyof T & string>;
  7. export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;
  8. export declare function getEventType<TEvent extends EventObject = EventObject>(event: Event<TEvent>): TEvent['type'];
  9. export declare function getActionType(action: Action<any, any>): ActionType;
  10. export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
  11. export declare function isStateLike(state: any): state is StateLike<any>;
  12. export declare function toStateValue(stateValue: StateLike<any> | StateValue | string[], delimiter: string): StateValue;
  13. export declare function pathToStateValue(statePath: string[]): StateValue;
  14. export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
  15. [key in keyof O]: P;
  16. };
  17. export declare function mapFilterValues<T, P>(collection: {
  18. [key: string]: T;
  19. }, iteratee: (item: T, key: string, collection: {
  20. [key: string]: T;
  21. }) => P, predicate: (item: T) => boolean): {
  22. [key: string]: P;
  23. };
  24. /**
  25. * Retrieves a value at the given path.
  26. * @param props The deep path to the prop of the desired value
  27. */
  28. export declare const path: <T extends Record<string, any>>(props: string[]) => any;
  29. /**
  30. * Retrieves a value at the given path via the nested accessor prop.
  31. * @param props The deep path to the prop of the desired value
  32. */
  33. export declare function nestedPath<T extends Record<string, any>>(props: string[], accessorProp: keyof T): (object: T) => T;
  34. export declare function toStatePaths(stateValue: StateValue | undefined): string[][];
  35. export declare function pathsToStateValue(paths: string[][]): StateValue;
  36. export declare function flatten<T>(array: Array<T | T[]>): T[];
  37. export declare function toArrayStrict<T>(value: T[] | T): T[];
  38. export declare function toArray<T>(value: T[] | T | undefined): T[];
  39. export declare function mapContext<TContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext, _event: SCXML.Event<TEvent>): any;
  40. export declare function isBuiltInEvent(eventType: EventType): boolean;
  41. export declare function isPromiseLike(value: any): value is PromiseLike<any>;
  42. export declare function isBehavior(value: any): value is Behavior<any, any>;
  43. export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
  44. export declare function updateHistoryStates(hist: HistoryValue, stateValue: StateValue): Record<string, HistoryValue | undefined>;
  45. export declare function updateHistoryValue(hist: HistoryValue, stateValue: StateValue): HistoryValue;
  46. export declare function updateContext<TContext, TEvent extends EventObject>(context: TContext, _event: SCXML.Event<TEvent>, assignActions: Array<AssignAction<TContext, TEvent>>, state?: State<TContext, TEvent>): TContext;
  47. declare let warn: (condition: boolean | Error, message: string) => void;
  48. export { warn };
  49. export declare function isArray(value: any): value is any[];
  50. export declare function isFunction(value: any): value is Function;
  51. export declare function isString(value: any): value is string;
  52. export declare function toGuard<TContext, TEvent extends EventObject>(condition?: Condition<TContext, TEvent>, guardMap?: Record<string, ConditionPredicate<TContext, TEvent>>): Guard<TContext, TEvent> | undefined;
  53. export declare function isObservable<T>(value: any): value is Subscribable<T>;
  54. export declare const symbolObservable: typeof Symbol.observable;
  55. export declare const interopSymbols: {
  56. [Symbol.observable]: () => any;
  57. };
  58. export declare function isMachine(value: any): value is AnyStateMachine;
  59. export declare function isActor(value: any): value is Actor;
  60. export declare const uniqueId: () => string;
  61. export declare function toEventObject<TEvent extends EventObject>(event: Event<TEvent>, payload?: EventData): TEvent;
  62. export declare function toSCXMLEvent<TEvent extends EventObject>(event: Event<TEvent> | SCXML.Event<TEvent>, scxmlEvent?: Partial<SCXML.Event<TEvent>>): SCXML.Event<TEvent>;
  63. export declare function toTransitionConfigArray<TContext, TEvent extends EventObject>(event: TEvent['type'] | NullEvent['type'] | '*', configLike: SingleOrArray<TransitionConfig<TContext, TEvent> | TransitionConfigTarget<TContext, TEvent>>): Array<TransitionConfig<TContext, TEvent> & {
  64. event: TEvent['type'] | NullEvent['type'] | '*';
  65. }>;
  66. export declare function normalizeTarget<TContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, any, TEvent>> | undefined): Array<string | StateNode<TContext, any, TEvent>> | undefined;
  67. export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
  68. export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
  69. export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
  70. export declare function toObserver<T>(nextHandler?: Partial<Observer<T>> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
  71. export declare function createInvokeId(stateNodeId: string, index: number): string;
  72. export declare function isRaisableAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(action: ActionObject<TContext, TExpressionEvent, TEvent>): action is RaiseActionObject<TContext, TExpressionEvent, TEvent> | SendActionObject<TContext, TExpressionEvent, TEvent>;
  73. //# sourceMappingURL=utils.d.ts.map