xstate 5.0.0-beta.7 → 5.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/actions/dist/xstate-actions.cjs.d.mts +2 -0
  2. package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
  3. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  4. package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
  5. package/actions/dist/xstate-actions.cjs.dev.js +2 -1
  6. package/actions/dist/xstate-actions.cjs.mjs +25 -0
  7. package/actions/dist/xstate-actions.cjs.prod.js +3 -2
  8. package/actions/dist/xstate-actions.esm.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js +1 -1
  10. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  11. package/actors/dist/xstate-actors.cjs.d.mts +2 -0
  12. package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
  13. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  14. package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
  15. package/actors/dist/xstate-actors.cjs.dev.js +2 -1
  16. package/actors/dist/xstate-actors.cjs.mjs +15 -0
  17. package/actors/dist/xstate-actors.cjs.prod.js +3 -2
  18. package/actors/dist/xstate-actors.esm.js +1 -1
  19. package/actors/dist/xstate-actors.umd.min.js +1 -1
  20. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dev/dist/xstate-dev.cjs.d.mts +2 -0
  22. package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
  23. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  24. package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
  25. package/dev/dist/xstate-dev.cjs.mjs +5 -0
  26. package/dev/dist/xstate-dev.cjs.prod.js +6 -43
  27. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  28. package/dist/{actions-0fcf4fd9.cjs.dev.js → actions-b6357569.cjs.dev.js} +252 -157
  29. package/dist/{actions-a1a641d3.cjs.prod.js → actions-bd4a184d.cjs.prod.js} +279 -160
  30. package/dist/{actions-b334e916.esm.js → actions-de434a04.esm.js} +208 -147
  31. package/dist/declarations/src/StateMachine.d.ts +2 -2
  32. package/dist/declarations/src/actions.d.ts +1 -0
  33. package/dist/declarations/src/actors/index.d.ts +2 -1
  34. package/dist/declarations/src/actors/observable.d.ts +1 -2
  35. package/dist/declarations/src/actors/promise.d.ts +1 -2
  36. package/dist/declarations/src/index.d.ts +12 -28
  37. package/dist/declarations/src/interpreter.d.ts +3 -2
  38. package/dist/declarations/src/typegenTypes.d.ts +7 -1
  39. package/dist/declarations/src/types.d.ts +5 -4
  40. package/dist/declarations/src/waitFor.d.ts +33 -0
  41. package/dist/index-0f3fdf0c.cjs.prod.js +52 -0
  42. package/dist/xstate.cjs.d.mts +2 -0
  43. package/dist/xstate.cjs.d.mts.map +1 -0
  44. package/dist/xstate.cjs.d.ts +1 -0
  45. package/dist/xstate.cjs.d.ts.map +1 -0
  46. package/dist/xstate.cjs.dev.js +97 -68
  47. package/dist/xstate.cjs.mjs +39 -0
  48. package/dist/xstate.cjs.prod.js +95 -69
  49. package/dist/xstate.esm.js +80 -57
  50. package/dist/xstate.umd.min.js +1 -1
  51. package/dist/xstate.umd.min.js.map +1 -1
  52. package/guards/dist/xstate-guards.cjs.d.mts +2 -0
  53. package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
  54. package/guards/dist/xstate-guards.cjs.d.ts +1 -0
  55. package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
  56. package/guards/dist/xstate-guards.cjs.dev.js +1 -1
  57. package/guards/dist/xstate-guards.cjs.mjs +8 -0
  58. package/guards/dist/xstate-guards.cjs.prod.js +2 -2
  59. package/guards/dist/xstate-guards.esm.js +1 -1
  60. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  61. package/package.json +7 -1
  62. package/dist/declarations/src/schema.d.ts +0 -2
@@ -1,7 +1,7 @@
1
1
  import { State } from './State.ts';
2
2
  import { StateNode } from './StateNode.ts';
3
3
  import type { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, ResolveTypegenMeta, TypegenDisabled } from './typegenTypes.ts';
4
- import type { ActorContext, ActorMap, ActorBehavior, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineSchema, NoInfer, SCXML, StateConfig, StateMachineDefinition, StateValue, TransitionDefinition, PersistedMachineState, ParameterizedObject, AnyActorContext } from './types.ts';
4
+ import type { ActorContext, ActorMap, ActorBehavior, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineTypes, NoInfer, SCXML, StateConfig, StateMachineDefinition, StateValue, TransitionDefinition, PersistedMachineState, ParameterizedObject, AnyActorContext } from './types.ts';
5
5
  export declare const NULL_EVENT = "";
6
6
  export declare const STATE_IDENTIFIER = "#";
7
7
  export declare const WILDCARD = "*";
@@ -21,7 +21,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
21
21
  */
22
22
  delimiter: string;
23
23
  options: MachineImplementationsSimplified<TContext, TEvent>;
24
- schema: MachineSchema<TContext, TEvent>;
24
+ types: MachineTypes<TContext, TEvent>;
25
25
  __xstatenode: true;
26
26
  idMap: Map<string, StateNode<TContext, TEvent>>;
27
27
  root: StateNode<TContext, TEvent>;
@@ -7,6 +7,7 @@ export { cancel } from './actions/cancel.ts';
7
7
  export { assign } from './actions/assign.ts';
8
8
  export { raise } from './actions/raise.ts';
9
9
  export { choose } from './actions/choose.ts';
10
+ export { pure } from './actions/pure.ts';
10
11
  export { actionTypes };
11
12
  export declare const initEvent: SCXML.Event<{
12
13
  type: ActionTypes;
@@ -1,4 +1,4 @@
1
- import type { EventObject, ActorRef, BaseActorRef } from '../types.ts';
1
+ import type { EventObject, ActorRef, BaseActorRef, AnyEventObject } from '../types.ts';
2
2
  export { fromTransition } from './transition.ts';
3
3
  export { fromPromise } from './promise.ts';
4
4
  export { fromObservable, fromEventObservable } from './observable.ts';
@@ -25,3 +25,4 @@ export type LifecycleSignalType = typeof startSignalType | typeof stopSignalType
25
25
  export declare function isSignal(eventType: string): eventType is LifecycleSignalType;
26
26
  export declare function isActorRef(item: any): item is ActorRef<any>;
27
27
  export declare function toActorRef<TEvent extends EventObject, TSnapshot = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TSnapshot> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
28
+ export declare function createEmptyActor(): ActorRef<AnyEventObject, undefined>;
@@ -1,8 +1,7 @@
1
1
  import { Subscribable, ActorBehavior, EventObject, Subscription } from '../types';
2
2
  export interface ObservableInternalState<T> {
3
3
  subscription: Subscription | undefined;
4
- canceled: boolean;
5
- status: 'active' | 'done' | 'error';
4
+ status: 'active' | 'done' | 'error' | 'canceled';
6
5
  data: T | undefined;
7
6
  input?: any;
8
7
  }
@@ -1,7 +1,6 @@
1
1
  import { ActorBehavior } from '../types';
2
2
  export interface PromiseInternalState<T> {
3
- status: 'active' | 'error' | 'done';
4
- canceled: boolean;
3
+ status: 'active' | 'error' | 'done' | 'canceled';
5
4
  data: T | undefined;
6
5
  input?: any;
7
6
  }
@@ -1,42 +1,26 @@
1
- import { after, done, doneInvoke, escalate, forwardTo, respond, sendParent, sendTo } from './actions.ts';
2
- import { assign } from './actions/assign.ts';
3
- import { cancel } from './actions/cancel.ts';
4
- import { choose } from './actions/choose.ts';
5
- import { log } from './actions/log.ts';
6
- import { pure } from './actions/pure.ts';
7
- import { raise } from './actions/raise.ts';
8
- import { send } from './actions/send.ts';
9
- import { stop } from './actions/stop.ts';
1
+ import { doneInvoke, forwardTo, sendParent, sendTo } from './actions.ts';
2
+ export { assign } from './actions/assign.ts';
3
+ export { cancel } from './actions/cancel.ts';
4
+ export { choose } from './actions/choose.ts';
5
+ export { log } from './actions/log.ts';
6
+ export { pure } from './actions/pure.ts';
7
+ export { raise } from './actions/raise.ts';
8
+ export { stop } from './actions/stop.ts';
10
9
  import { interpret, Interpreter, ActorStatus } from './interpreter.ts';
11
10
  import { createMachine } from './Machine.ts';
12
11
  import { mapState } from './mapState.ts';
13
12
  import { State } from './State.ts';
14
13
  import { StateNode } from './StateNode.ts';
15
- export { createSchema, t } from './schema.ts';
16
14
  export { SimulatedClock } from './SimulatedClock.ts';
17
15
  export { StateMachine } from './StateMachine.ts';
18
16
  export { getStateNodes } from './stateUtils.ts';
17
+ export { waitFor } from './waitFor.ts';
19
18
  export * from './typegenTypes.ts';
20
19
  export * from './types.ts';
21
20
  export { matchesState, pathToStateValue, toObserver, toSCXMLEvent } from './utils.ts';
22
- export { StateNode, State, mapState, actions, assign, send, sendTo, sendParent, forwardTo, interpret, Interpreter, ActorStatus as InterpreterStatus, doneInvoke, createMachine };
23
- declare const actions: {
24
- raise: typeof raise;
25
- send: typeof send;
26
- sendParent: typeof sendParent;
27
- sendTo: typeof sendTo;
28
- log: typeof log;
29
- cancel: typeof cancel;
30
- stop: typeof stop;
31
- assign: typeof assign;
32
- after: typeof after;
33
- done: typeof done;
34
- respond: typeof respond;
35
- forwardTo: typeof forwardTo;
36
- escalate: typeof escalate;
37
- choose: typeof choose;
38
- pure: typeof pure;
39
- };
21
+ export { StateNode, State, mapState, sendTo, sendParent, forwardTo, interpret, Interpreter, ActorStatus as InterpreterStatus, doneInvoke, createMachine };
22
+ export { fromPromise, fromObservable, fromCallback, fromEventObservable, fromTransition } from './actors/index.ts';
23
+ export { stateIn, not, and, or } from './guards.ts';
40
24
  declare global {
41
25
  interface SymbolConstructor {
42
26
  readonly observable: symbol;
@@ -1,5 +1,5 @@
1
1
  import { symbolObservable } from './symbolObservable.ts';
2
- import { AreAllImplementationsAssumedToBeProvided } from './typegenTypes.ts';
2
+ import { AreAllImplementationsAssumedToBeProvided, MissingImplementationsError } from './typegenTypes.ts';
3
3
  import type { ActorSystem, AnyActorBehavior, AnyStateMachine, EventFromBehavior, InterpreterFrom, PersistedStateFrom, RaiseActionObject, SnapshotFrom } from './types.ts';
4
4
  import { ActorRef, DoneEvent, EventObject, InteropSubscribable, InterpreterOptions, Observer, SCXML, SendActionObject, Subscription } from './types.ts';
5
5
  export type SnapshotListener<TBehavior extends AnyActorBehavior> = (state: SnapshotFrom<TBehavior>) => void;
@@ -77,6 +77,7 @@ export declare class Interpreter<TBehavior extends AnyActorBehavior, TEvent exte
77
77
  */
78
78
  stop(): this;
79
79
  private _complete;
80
+ private _error;
80
81
  private _stopProcedure;
81
82
  /**
82
83
  * Sends an event to the running interpreter to trigger a transition.
@@ -100,5 +101,5 @@ export declare class Interpreter<TBehavior extends AnyActorBehavior, TEvent exte
100
101
  * @param machine The machine to interpret
101
102
  * @param options Interpreter options
102
103
  */
103
- export declare function interpret<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : 'Some implementations missing', options?: InterpreterOptions<TMachine>): InterpreterFrom<TMachine>;
104
+ export declare function interpret<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: InterpreterOptions<TMachine>): InterpreterFrom<TMachine>;
104
105
  export declare function interpret<TBehavior extends AnyActorBehavior>(behavior: TBehavior, options?: InterpreterOptions<TBehavior>): Interpreter<TBehavior>;
@@ -1,4 +1,4 @@
1
- import { EventObject, IndexByType, IsNever, Prop, Values, IsAny, ActorMap, Cast, ParameterizedObject } from './types.ts';
1
+ import { Compute, EventObject, IndexByType, IsNever, Prop, Values, IsAny, ActorMap, Cast, ParameterizedObject } from './types.ts';
2
2
  export interface TypegenDisabled {
3
3
  '@@xstate/typegen': false;
4
4
  }
@@ -86,6 +86,12 @@ export type TypegenConstraint = TypegenEnabled | TypegenDisabled;
86
86
  export type AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = IsAny<TResolvedTypesMeta> extends true ? true : TResolvedTypesMeta extends TypegenEnabled ? IsNever<Values<{
87
87
  [K in keyof TMissingImplementations]: TMissingImplementations[K];
88
88
  }>> extends true ? true : false : true;
89
+ export type MissingImplementationsError<TResolvedTypesMeta, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = Compute<[
90
+ 'Some implementations missing',
91
+ Values<{
92
+ [K in keyof TMissingImplementations]: TMissingImplementations[K];
93
+ }>
94
+ ]>;
89
95
  interface AllImplementationsProvided {
90
96
  missingImplementations: {
91
97
  actions: never;
@@ -92,7 +92,7 @@ export type ActionFunction<TContext extends MachineContext, TExpressionEvent ext
92
92
  event: TExpressionEvent;
93
93
  } & ActionMeta<TEvent, TAction>) => void;
94
94
  export interface ChooseCondition<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
95
- guard?: GuardConfig<TContext, TEvent>;
95
+ guard?: GuardConfig<TContext, TExpressionEvent>;
96
96
  actions: Actions<TContext, TExpressionEvent, TEvent>;
97
97
  }
98
98
  export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = ActionType | ParameterizedObject | ActionFunction<TContext, TExpressionEvent, ParameterizedObject, TEvent> | BaseDynamicActionObject<TContext, TExpressionEvent, TEvent, any, any>;
@@ -490,13 +490,12 @@ export interface MachineConfig<TContext extends MachineContext, TEvent extends E
490
490
  * If `true`, will use SCXML semantics, such as event token matching.
491
491
  */
492
492
  scxml?: boolean;
493
- schema?: MachineSchema<TContext, TEvent, TActorMap>;
494
- tsTypes?: TTypesMeta;
493
+ types?: MachineTypes<TContext, TEvent, TActorMap, TTypesMeta>;
495
494
  }
496
495
  export type ActorMap = Record<string, {
497
496
  output: any;
498
497
  }>;
499
- export interface MachineSchema<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends ActorMap = ActorMap> {
498
+ export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends ActorMap = ActorMap, TTypesMeta = TypegenDisabled> {
500
499
  context?: TContext;
501
500
  actions?: {
502
501
  type: string;
@@ -508,6 +507,7 @@ export interface MachineSchema<TContext extends MachineContext, TEvent extends E
508
507
  type: string;
509
508
  [key: string]: any;
510
509
  };
510
+ typegen?: TTypesMeta;
511
511
  }
512
512
  export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
513
513
  history: 'shallow' | 'deep';
@@ -1010,6 +1010,7 @@ export type InferEvent<E extends EventObject> = {
1010
1010
  }[E['type']];
1011
1011
  export type TODO = any;
1012
1012
  export type StateValueFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['matches']>[0];
1013
+ export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
1013
1014
  export type StateFromMachine<TMachine extends AnyStateMachine> = TMachine['initialState'];
1014
1015
  export interface ActorSystemInfo {
1015
1016
  actors: Record<string, AnyActorRef>;
@@ -0,0 +1,33 @@
1
+ import { ActorRef, SnapshotFrom } from '.';
2
+ interface WaitForOptions {
3
+ /**
4
+ * How long to wait before rejecting, if no emitted
5
+ * state satisfies the predicate.
6
+ *
7
+ * @default 10_000 (10 seconds)
8
+ */
9
+ timeout: number;
10
+ }
11
+ /**
12
+ * Subscribes to an actor ref and waits for its emitted value to satisfy
13
+ * a predicate, and then resolves with that value.
14
+ * Will throw if the desired state is not reached after a timeout
15
+ * (defaults to 10 seconds).
16
+ *
17
+ * @example
18
+ * ```js
19
+ * const state = await waitFor(someService, state => {
20
+ * return state.hasTag('loaded');
21
+ * });
22
+ *
23
+ * state.hasTag('loaded'); // true
24
+ * ```
25
+ *
26
+ * @param actorRef The actor ref to subscribe to
27
+ * @param predicate Determines if a value matches the condition to wait for
28
+ * @param options
29
+ * @returns A promise that eventually resolves to the emitted value
30
+ * that matches the condition
31
+ */
32
+ export declare function waitFor<TActorRef extends ActorRef<any, any>>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
33
+ export {};
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var IS_PRODUCTION = "production" === 'production';
4
+
5
+ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6
+ function getGlobal() {
7
+ if (typeof globalThis !== 'undefined') {
8
+ return globalThis;
9
+ }
10
+ if (typeof self !== 'undefined') {
11
+ return self;
12
+ }
13
+ if (typeof window !== 'undefined') {
14
+ return window;
15
+ }
16
+ if (typeof global !== 'undefined') {
17
+ return global;
18
+ }
19
+ if (!IS_PRODUCTION) {
20
+ console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
21
+ }
22
+ }
23
+ function getDevTools() {
24
+ var w = getGlobal();
25
+ if (!!w.__xstate__) {
26
+ return w.__xstate__;
27
+ }
28
+ return undefined;
29
+ }
30
+ function registerService(service) {
31
+ if (typeof window === 'undefined') {
32
+ return;
33
+ }
34
+ var devTools = getDevTools();
35
+ if (devTools) {
36
+ devTools.register(service);
37
+ }
38
+ }
39
+ var devToolsAdapter = function devToolsAdapter(service) {
40
+ if (typeof window === 'undefined') {
41
+ return;
42
+ }
43
+ var devTools = getDevTools();
44
+ if (devTools) {
45
+ devTools.register(service);
46
+ }
47
+ };
48
+
49
+ exports.IS_PRODUCTION = IS_PRODUCTION;
50
+ exports.devToolsAdapter = devToolsAdapter;
51
+ exports.getGlobal = getGlobal;
52
+ exports.registerService = registerService;
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index.js";
2
+ //# sourceMappingURL=xstate.cjs.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xstate.cjs.d.mts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -1 +1,2 @@
1
1
  export * from "./declarations/src/index";
2
+ //# sourceMappingURL=xstate.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xstate.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -2,30 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('./actions-0fcf4fd9.cjs.dev.js');
5
+ var actors_dist_xstateActors = require('./actions-b6357569.cjs.dev.js');
6
6
  require('./index-ebaab3c9.cjs.dev.js');
7
7
 
8
- function pure(getActions) {
9
- return actors_dist_xstateActors.createDynamicAction({
10
- type: actors_dist_xstateActors.pure,
11
- params: {
12
- get: getActions
13
- }
14
- }, function (_event, _ref) {
15
- var _toArray;
16
- var state = _ref.state;
17
- return [state, {
18
- type: actors_dist_xstateActors.pure,
19
- params: {
20
- actions: (_toArray = actors_dist_xstateActors.toArray(actors_dist_xstateActors.toActionObjects(getActions({
21
- context: state.context,
22
- event: _event.data
23
- })))) !== null && _toArray !== void 0 ? _toArray : []
24
- }
25
- }];
26
- });
27
- }
28
-
29
8
  var _excluded = ["onDone", "onError"];
30
9
  var EMPTY_OBJECT = {};
31
10
  var StateNode = /*#__PURE__*/function () {
@@ -235,9 +214,9 @@ var StateNode = /*#__PURE__*/function () {
235
214
  id: resolvedId,
236
215
  systemId: systemId,
237
216
  toJSON: function toJSON() {
238
- var onDone = invokeConfig.onDone,
239
- onError = invokeConfig.onError,
240
- invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
217
+ invokeConfig.onDone;
218
+ invokeConfig.onError;
219
+ var invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
241
220
  return actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, invokeDefValues), {}, {
242
221
  type: actors_dist_xstateActors.invoke,
243
222
  src: resolvedSrc,
@@ -426,13 +405,13 @@ var StateMachine = /*#__PURE__*/function () {
426
405
  * The raw config used to create the machine.
427
406
  */
428
407
  config, options) {
429
- var _this$config$schema;
408
+ var _this$config$types;
430
409
  actors_dist_xstateActors._classCallCheck(this, StateMachine);
431
410
  this.config = config;
432
411
  actors_dist_xstateActors._defineProperty(this, "version", void 0);
433
412
  actors_dist_xstateActors._defineProperty(this, "delimiter", void 0);
434
413
  actors_dist_xstateActors._defineProperty(this, "options", void 0);
435
- actors_dist_xstateActors._defineProperty(this, "schema", void 0);
414
+ actors_dist_xstateActors._defineProperty(this, "types", void 0);
436
415
  actors_dist_xstateActors._defineProperty(this, "__xstatenode", true);
437
416
  actors_dist_xstateActors._defineProperty(this, "idMap", new Map());
438
417
  actors_dist_xstateActors._defineProperty(this, "root", void 0);
@@ -448,7 +427,7 @@ var StateMachine = /*#__PURE__*/function () {
448
427
  this.options = Object.assign(createDefaultOptions(), options);
449
428
  this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
450
429
  this.version = this.config.version;
451
- this.schema = (_this$config$schema = this.config.schema) !== null && _this$config$schema !== void 0 ? _this$config$schema : {};
430
+ this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
452
431
  this.transition = this.transition.bind(this);
453
432
  this.root = new StateNode(config, {
454
433
  _key: this.id,
@@ -780,11 +759,6 @@ function mapState(stateMap, stateId) {
780
759
  return stateMap[foundStateId];
781
760
  }
782
761
 
783
- function createSchema(schema) {
784
- return schema;
785
- }
786
- var t = createSchema;
787
-
788
762
  var SimulatedClock = /*#__PURE__*/function () {
789
763
  function SimulatedClock() {
790
764
  actors_dist_xstateActors._classCallCheck(this, SimulatedClock);
@@ -832,12 +806,12 @@ var SimulatedClock = /*#__PURE__*/function () {
832
806
  value: function flushTimeouts() {
833
807
  var _this = this;
834
808
  actors_dist_xstateActors._toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
835
- var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2),
836
- _idA = _ref3[0],
837
- timeoutA = _ref3[1];
838
- var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2),
839
- _idB = _ref4[0],
840
- timeoutB = _ref4[1];
809
+ var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2);
810
+ _ref3[0];
811
+ var timeoutA = _ref3[1];
812
+ var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2);
813
+ _ref4[0];
814
+ var timeoutB = _ref4[1];
841
815
  var endA = timeoutA.start + timeoutA.timeout;
842
816
  var endB = timeoutB.start + timeoutB.timeout;
843
817
  return endB > endA ? -1 : 1;
@@ -861,61 +835,116 @@ var SimulatedClock = /*#__PURE__*/function () {
861
835
  return SimulatedClock;
862
836
  }();
863
837
 
864
- var actions = {
865
- raise: actors_dist_xstateActors.raise,
866
- send: actors_dist_xstateActors.send,
867
- sendParent: actors_dist_xstateActors.sendParent,
868
- sendTo: actors_dist_xstateActors.sendTo,
869
- log: actors_dist_xstateActors.log,
870
- cancel: actors_dist_xstateActors.cancel,
871
- stop: actors_dist_xstateActors.stop,
872
- assign: actors_dist_xstateActors.assign,
873
- after: actors_dist_xstateActors.after,
874
- done: actors_dist_xstateActors.done,
875
- respond: actors_dist_xstateActors.respond,
876
- forwardTo: actors_dist_xstateActors.forwardTo,
877
- escalate: actors_dist_xstateActors.escalate,
878
- choose: actors_dist_xstateActors.choose,
879
- pure: pure
838
+ var defaultWaitForOptions = {
839
+ timeout: 10000 // 10 seconds
880
840
  };
881
841
 
842
+ /**
843
+ * Subscribes to an actor ref and waits for its emitted value to satisfy
844
+ * a predicate, and then resolves with that value.
845
+ * Will throw if the desired state is not reached after a timeout
846
+ * (defaults to 10 seconds).
847
+ *
848
+ * @example
849
+ * ```js
850
+ * const state = await waitFor(someService, state => {
851
+ * return state.hasTag('loaded');
852
+ * });
853
+ *
854
+ * state.hasTag('loaded'); // true
855
+ * ```
856
+ *
857
+ * @param actorRef The actor ref to subscribe to
858
+ * @param predicate Determines if a value matches the condition to wait for
859
+ * @param options
860
+ * @returns A promise that eventually resolves to the emitted value
861
+ * that matches the condition
862
+ */
863
+ function waitFor(actorRef, predicate, options) {
864
+ var resolvedOptions = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, defaultWaitForOptions), options);
865
+ return new Promise(function (res, rej) {
866
+ var done = false;
867
+ if (process.env.NODE_ENV !== 'production' && resolvedOptions.timeout < 0) {
868
+ console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
869
+ }
870
+ var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
871
+ sub.unsubscribe();
872
+ rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
873
+ }, resolvedOptions.timeout);
874
+ var dispose = function dispose() {
875
+ clearTimeout(handle);
876
+ done = true;
877
+ sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
878
+ };
879
+ function checkEmitted(emitted) {
880
+ if (predicate(emitted)) {
881
+ dispose();
882
+ res(emitted);
883
+ }
884
+ }
885
+
886
+ // See if the current snapshot already matches the predicate
887
+ checkEmitted(actorRef.getSnapshot());
888
+ var sub = actorRef.subscribe({
889
+ next: checkEmitted,
890
+ error: function error(err) {
891
+ dispose();
892
+ rej(err);
893
+ },
894
+ complete: function complete() {
895
+ dispose();
896
+ rej(new Error("Actor terminated without satisfying predicate"));
897
+ }
898
+ });
899
+ if (done) {
900
+ sub.unsubscribe();
901
+ }
902
+ });
903
+ }
904
+
882
905
  Object.defineProperty(exports, 'ActionTypes', {
883
906
  enumerable: true,
884
- get: function () {
885
- return actors_dist_xstateActors.ActionTypes;
886
- }
907
+ get: function () { return actors_dist_xstateActors.ActionTypes; }
887
908
  });
888
909
  exports.Interpreter = actors_dist_xstateActors.Interpreter;
889
910
  Object.defineProperty(exports, 'InterpreterStatus', {
890
911
  enumerable: true,
891
- get: function () {
892
- return actors_dist_xstateActors.ActorStatus;
893
- }
912
+ get: function () { return actors_dist_xstateActors.ActorStatus; }
894
913
  });
895
914
  Object.defineProperty(exports, 'SpecialTargets', {
896
915
  enumerable: true,
897
- get: function () {
898
- return actors_dist_xstateActors.SpecialTargets;
899
- }
916
+ get: function () { return actors_dist_xstateActors.SpecialTargets; }
900
917
  });
901
918
  exports.State = actors_dist_xstateActors.State;
919
+ exports.and = actors_dist_xstateActors.and;
902
920
  exports.assign = actors_dist_xstateActors.assign;
921
+ exports.cancel = actors_dist_xstateActors.cancel;
922
+ exports.choose = actors_dist_xstateActors.choose;
903
923
  exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
904
924
  exports.forwardTo = actors_dist_xstateActors.forwardTo;
925
+ exports.fromCallback = actors_dist_xstateActors.fromCallback;
926
+ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
927
+ exports.fromObservable = actors_dist_xstateActors.fromObservable;
928
+ exports.fromPromise = actors_dist_xstateActors.fromPromise;
929
+ exports.fromTransition = actors_dist_xstateActors.fromTransition;
905
930
  exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
906
931
  exports.interpret = actors_dist_xstateActors.interpret;
932
+ exports.log = actors_dist_xstateActors.log;
907
933
  exports.matchesState = actors_dist_xstateActors.matchesState;
934
+ exports.not = actors_dist_xstateActors.not;
935
+ exports.or = actors_dist_xstateActors.or;
908
936
  exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
909
- exports.send = actors_dist_xstateActors.send;
937
+ exports.pure = actors_dist_xstateActors.pure;
938
+ exports.raise = actors_dist_xstateActors.raise;
910
939
  exports.sendParent = actors_dist_xstateActors.sendParent;
911
940
  exports.sendTo = actors_dist_xstateActors.sendTo;
941
+ exports.stateIn = actors_dist_xstateActors.stateIn;
942
+ exports.stop = actors_dist_xstateActors.stop;
912
943
  exports.toObserver = actors_dist_xstateActors.toObserver;
913
944
  exports.toSCXMLEvent = actors_dist_xstateActors.toSCXMLEvent;
914
945
  exports.SimulatedClock = SimulatedClock;
915
946
  exports.StateMachine = StateMachine;
916
947
  exports.StateNode = StateNode;
917
- exports.actions = actions;
918
948
  exports.createMachine = createMachine;
919
- exports.createSchema = createSchema;
920
949
  exports.mapState = mapState;
921
- exports.t = t;
950
+ exports.waitFor = waitFor;
@@ -0,0 +1,39 @@
1
+ export {
2
+ ActionTypes,
3
+ Interpreter,
4
+ InterpreterStatus,
5
+ SimulatedClock,
6
+ SpecialTargets,
7
+ State,
8
+ StateMachine,
9
+ StateNode,
10
+ and,
11
+ assign,
12
+ cancel,
13
+ choose,
14
+ createMachine,
15
+ doneInvoke,
16
+ forwardTo,
17
+ fromCallback,
18
+ fromEventObservable,
19
+ fromObservable,
20
+ fromPromise,
21
+ fromTransition,
22
+ getStateNodes,
23
+ interpret,
24
+ log,
25
+ mapState,
26
+ matchesState,
27
+ not,
28
+ or,
29
+ pathToStateValue,
30
+ pure,
31
+ raise,
32
+ sendParent,
33
+ sendTo,
34
+ stateIn,
35
+ stop,
36
+ toObserver,
37
+ toSCXMLEvent,
38
+ waitFor
39
+ } from "./xstate.cjs.js";