xstate 4.28.1 → 4.30.2

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 (59) hide show
  1. package/CHANGELOG.md +218 -91
  2. package/README.md +5 -5
  3. package/dist/xstate.interpreter.js +1 -1
  4. package/dist/xstate.js +1 -1
  5. package/dist/xstate.web.js +2 -2
  6. package/es/Actor.d.ts +2 -3
  7. package/es/Actor.js +15 -6
  8. package/es/Machine.d.ts +5 -4
  9. package/es/State.d.ts +19 -15
  10. package/es/State.js +4 -9
  11. package/es/StateNode.d.ts +22 -17
  12. package/es/StateNode.js +14 -13
  13. package/es/actions.d.ts +3 -4
  14. package/es/actions.js +8 -3
  15. package/es/behaviors.d.ts +1 -1
  16. package/es/devTools.d.ts +3 -4
  17. package/es/each.d.ts +1 -1
  18. package/es/index.d.ts +6 -23
  19. package/es/index.js +12 -23
  20. package/es/interpreter.d.ts +35 -27
  21. package/es/interpreter.js +31 -21
  22. package/es/model.d.ts +2 -2
  23. package/es/model.types.d.ts +8 -9
  24. package/es/schema.d.ts +1 -0
  25. package/es/schema.js +2 -1
  26. package/es/scxml.d.ts +2 -2
  27. package/es/stateUtils.d.ts +6 -5
  28. package/es/typegenTypes.d.ts +121 -0
  29. package/es/types.d.ts +128 -64
  30. package/es/utils.d.ts +5 -5
  31. package/es/utils.js +5 -2
  32. package/lib/Actor.d.ts +2 -3
  33. package/lib/Actor.js +14 -5
  34. package/lib/Machine.d.ts +5 -4
  35. package/lib/State.d.ts +19 -15
  36. package/lib/State.js +4 -9
  37. package/lib/StateNode.d.ts +22 -17
  38. package/lib/StateNode.js +14 -13
  39. package/lib/actions.d.ts +3 -4
  40. package/lib/actions.js +5 -0
  41. package/lib/behaviors.d.ts +1 -1
  42. package/lib/devTools.d.ts +3 -4
  43. package/lib/each.d.ts +1 -1
  44. package/lib/index.d.ts +6 -23
  45. package/lib/index.js +17 -27
  46. package/lib/interpreter.d.ts +35 -27
  47. package/lib/interpreter.js +29 -19
  48. package/lib/model.d.ts +2 -2
  49. package/lib/model.types.d.ts +8 -9
  50. package/lib/schema.d.ts +1 -0
  51. package/lib/schema.js +2 -0
  52. package/lib/scxml.d.ts +2 -2
  53. package/lib/stateUtils.d.ts +6 -5
  54. package/lib/typegenTypes.d.ts +121 -0
  55. package/lib/typegenTypes.js +2 -0
  56. package/lib/types.d.ts +128 -64
  57. package/lib/utils.d.ts +5 -5
  58. package/lib/utils.js +5 -2
  59. package/package.json +5 -5
package/es/StateNode.js CHANGED
@@ -50,8 +50,8 @@ function () {
50
50
  /**
51
51
  * The initial extended state
52
52
  */
53
- _context // TODO: this is unsafe, but we're removing it in v5 anyway
54
- ) {
53
+ _context, // TODO: this is unsafe, but we're removing it in v5 anyway
54
+ _stateInfo) {
55
55
  var _this = this;
56
56
 
57
57
  if (_context === void 0) {
@@ -81,8 +81,8 @@ function () {
81
81
  this.idMap = {};
82
82
  this.tags = [];
83
83
  this.options = Object.assign(createDefaultOptions(), options);
84
- this.parent = this.options._parent;
85
- this.key = this.config.key || this.options._key || this.config.id || '(machine)';
84
+ this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
85
+ this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
86
86
  this.machine = this.parent ? this.parent.machine : this;
87
87
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
88
88
  this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : STATE_DELIMITER);
@@ -100,9 +100,9 @@ function () {
100
100
  this.states = this.config.states ? mapValues(this.config.states, function (stateConfig, key) {
101
101
  var _a;
102
102
 
103
- var stateNode = new StateNode(stateConfig, {
104
- _parent: _this,
105
- _key: key
103
+ var stateNode = new StateNode(stateConfig, {}, undefined, {
104
+ parent: _this,
105
+ key: key
106
106
  });
107
107
  Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
108
108
  return stateNode;
@@ -437,9 +437,10 @@ function () {
437
437
 
438
438
 
439
439
  StateNode.prototype.resolveState = function (state) {
440
- var configuration = Array.from(getConfiguration([], this.getStateNodes(state.value)));
441
- return new State(__assign(__assign({}, state), {
442
- value: this.resolve(state.value),
440
+ var stateFromConfig = state instanceof State ? state : State.create(state);
441
+ var configuration = Array.from(getConfiguration([], this.getStateNodes(stateFromConfig.value)));
442
+ return new State(__assign(__assign({}, stateFromConfig), {
443
+ value: this.resolve(stateFromConfig.value),
443
444
  configuration: configuration,
444
445
  done: isInFinalState(configuration, this),
445
446
  tags: getTagsFromConfiguration(configuration)
@@ -1141,6 +1142,9 @@ function () {
1141
1142
  });
1142
1143
 
1143
1144
  StateNode.prototype.getInitialState = function (stateValue, context) {
1145
+ this._init(); // TODO: this should be in the constructor (see note in constructor)
1146
+
1147
+
1144
1148
  var configuration = this.getStateNodes(stateValue);
1145
1149
  return this.resolveTransition({
1146
1150
  configuration: configuration,
@@ -1158,9 +1162,6 @@ function () {
1158
1162
  * entering the initial state.
1159
1163
  */
1160
1164
  get: function () {
1161
- this._init(); // TODO: this should be in the constructor (see note in constructor)
1162
-
1163
-
1164
1165
  var initialStateValue = this.initialStateValue;
1165
1166
 
1166
1167
  if (!initialStateValue) {
package/es/actions.d.ts CHANGED
@@ -1,15 +1,14 @@
1
- import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
1
+ import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject, Cast, ActorRef, EventFrom } from './types';
2
2
  import * as actionTypes from './actionTypes';
3
3
  import { State } from './State';
4
4
  import { StateNode } from './StateNode';
5
- import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
6
5
  export { actionTypes };
7
6
  export declare const initEvent: SCXML.Event<{
8
7
  type: ActionTypes;
9
8
  }>;
10
9
  export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
11
10
  export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
12
- export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
11
+ export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, import("./types").BaseActionObject> | undefined) => ActionObject<TContext, TEvent>[];
13
12
  export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
14
13
  /**
15
14
  * Raises an event. This places the event in the internal event queue, so that
@@ -151,5 +150,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
151
150
  */
152
151
  export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
153
152
  export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
154
- export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
153
+ export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
155
154
  //# sourceMappingURL=actions.d.ts.map
package/es/actions.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { __assign, __read, __spreadArray } from './_virtual/_tslib.js';
2
2
  import { IS_PRODUCTION } from './environment.js';
3
- import { isFunction, toEventObject, getEventType, toSCXMLEvent, isString, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
3
+ import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
4
4
  import { SpecialTargets, ActionTypes } from './types.js';
5
- import { send as send$1, update, assign as assign$1, init, raise as raise$1, log as log$1, cancel as cancel$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1 } from './actionTypes.js';
5
+ import { send as send$1, raise as raise$1, update, log as log$1, cancel as cancel$1, assign as assign$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1, init } from './actionTypes.js';
6
+ import * as actionTypes from './actionTypes.js';
7
+ export { actionTypes };
6
8
 
7
9
  var initEvent = /*#__PURE__*/toSCXMLEvent({
8
10
  type: init
@@ -288,6 +290,9 @@ var assign = function (assignment) {
288
290
  assignment: assignment
289
291
  };
290
292
  };
293
+ function isActionObject(action) {
294
+ return typeof action === 'object' && 'type' in action;
295
+ }
291
296
  /**
292
297
  * Returns an event type that represents an implicit event that
293
298
  * is sent after the specified `delay`.
@@ -512,4 +517,4 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
512
517
  return [resolvedActions, updatedContext];
513
518
  }
514
519
 
515
- export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
520
+ export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, isActionObject, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
package/es/behaviors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActorContext, ActorRef, Behavior, EventObject } from '.';
1
+ import { ActorContext, ActorRef, Behavior, EventObject } from './types';
2
2
  /**
3
3
  * Returns an actor behavior from a reducer and its initial state.
4
4
  *
package/es/devTools.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { Interpreter } from '.';
2
1
  import { AnyInterpreter } from './types';
3
2
  declare type ServiceListener = (service: AnyInterpreter) => void;
4
3
  export interface XStateDevInterface {
5
- register: (service: Interpreter<any>) => void;
6
- unregister: (service: Interpreter<any>) => void;
4
+ register: (service: AnyInterpreter) => void;
5
+ unregister: (service: AnyInterpreter) => void;
7
6
  onRegister: (listener: ServiceListener) => {
8
7
  unsubscribe: () => void;
9
8
  };
10
- services: Set<Interpreter<any>>;
9
+ services: Set<AnyInterpreter>;
11
10
  }
12
11
  export declare function getGlobal(): typeof globalThis | undefined;
13
12
  export declare function registerService(service: AnyInterpreter): void;
package/es/each.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventObject, SingleOrArray, ActionObject } from '.';
1
+ import { EventObject, SingleOrArray, ActionObject } from './types';
2
2
  export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
3
3
  export declare function each<TContext, TEvent extends EventObject>(collection: keyof TContext, item: keyof TContext, index: keyof TContext, actions: SingleOrArray<ActionObject<TContext, TEvent>>): ActionObject<TContext, TEvent>;
4
4
  //# sourceMappingURL=each.d.ts.map
package/es/index.d.ts CHANGED
@@ -3,32 +3,15 @@ import { mapState } from './mapState';
3
3
  import { StateNode } from './StateNode';
4
4
  import { State } from './State';
5
5
  import { Machine, createMachine } from './Machine';
6
- import { Actor } from './Actor';
7
- import { raise, send, sendParent, sendTo, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
6
+ import { Actor, toActorRef } from './Actor';
7
+ import * as actions from './actions';
8
8
  import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
9
9
  import { matchState } from './match';
10
- import { createSchema } from './schema';
11
- declare const actions: {
12
- raise: typeof raise;
13
- send: typeof send;
14
- sendParent: typeof sendParent;
15
- sendTo: typeof sendTo;
16
- sendUpdate: typeof sendUpdate;
17
- log: typeof log;
18
- cancel: (sendId: string | number) => import("./types").CancelAction;
19
- start: typeof start;
20
- stop: typeof stop;
21
- assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
22
- after: typeof after;
23
- done: typeof done;
24
- respond: typeof respond;
25
- forwardTo: typeof forwardTo;
26
- escalate: typeof escalate;
27
- choose: typeof choose;
28
- pure: typeof pure;
29
- };
30
- export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
10
+ import { createSchema, t } from './schema';
11
+ declare const assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>, send: typeof actions.send, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke;
12
+ export { Actor, toActorRef, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
31
13
  export * from './types';
14
+ export * from './typegenTypes';
32
15
  declare global {
33
16
  interface SymbolConstructor {
34
17
  readonly observable: symbol;
package/es/index.js CHANGED
@@ -1,33 +1,22 @@
1
1
  export { matchesState } from './utils.js';
2
2
  export { mapState } from './mapState.js';
3
3
  export { ActionTypes, SpecialTargets } from './types.js';
4
- import { raise, send, sendParent, sendTo, sendUpdate, log, cancel, start, stop, assign, after, done, respond, forwardTo, escalate, choose, pure } from './actions.js';
5
- export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate } from './actions.js';
4
+ import { assign as assign$1, send as send$1, sendParent as sendParent$1, sendUpdate as sendUpdate$1, forwardTo as forwardTo$1, doneInvoke as doneInvoke$1 } from './actions.js';
5
+ import * as actions from './actions.js';
6
+ export { actions };
6
7
  export { State } from './State.js';
8
+ export { toActorRef } from './Actor.js';
7
9
  export { StateNode } from './StateNode.js';
8
10
  export { Machine, createMachine } from './Machine.js';
9
11
  export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
10
12
  export { matchState } from './match.js';
11
- export { createSchema } from './schema.js';
13
+ export { createSchema, t } from './schema.js';
12
14
 
13
- var actions = {
14
- raise: raise,
15
- send: send,
16
- sendParent: sendParent,
17
- sendTo: sendTo,
18
- sendUpdate: sendUpdate,
19
- log: log,
20
- cancel: cancel,
21
- start: start,
22
- stop: stop,
23
- assign: assign,
24
- after: after,
25
- done: done,
26
- respond: respond,
27
- forwardTo: forwardTo,
28
- escalate: escalate,
29
- choose: choose,
30
- pure: pure
31
- };
15
+ var assign = assign$1,
16
+ send = send$1,
17
+ sendParent = sendParent$1,
18
+ sendUpdate = sendUpdate$1,
19
+ forwardTo = forwardTo$1,
20
+ doneInvoke = doneInvoke$1;
32
21
 
33
- export { actions };
22
+ export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate };
@@ -1,9 +1,11 @@
1
- import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
1
+ import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription, StateConfig, InteropSubscribable } from './types';
2
2
  import { State } from './State';
3
+ import { symbolObservable } from './utils';
4
+ import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
3
5
  export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
4
6
  value: any;
5
7
  context: TContext;
6
- }> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
8
+ }, TResolvedTypesMeta = TypegenDisabled> = (state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, event: TEvent) => void;
7
9
  export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;
8
10
  export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
9
11
  export declare type Listener = () => void;
@@ -24,15 +26,21 @@ export declare enum InterpreterStatus {
24
26
  export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
25
27
  value: any;
26
28
  context: TContext;
27
- }> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
28
- machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
29
+ }, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>> {
30
+ machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>;
29
31
  /**
30
32
  * The default interpreter options:
31
33
  *
32
34
  * - `clock` uses the global `setTimeout` and `clearTimeout` functions
33
35
  * - `logger` uses the global `console.log()` method
34
36
  */
35
- static defaultOptions: InterpreterOptions;
37
+ static defaultOptions: {
38
+ execute: boolean;
39
+ deferEvents: boolean;
40
+ clock: Clock;
41
+ logger: any;
42
+ devTools: boolean;
43
+ };
36
44
  /**
37
45
  * The current state of the interpreted machine.
38
46
  */
@@ -72,9 +80,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
72
80
  * @param machine The machine to be interpreted
73
81
  * @param options Interpreter options
74
82
  */
75
- constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
76
- get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
77
- get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
83
+ constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>, options?: InterpreterOptions);
84
+ get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
85
+ get state(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
78
86
  static interpret: typeof interpret;
79
87
  /**
80
88
  * Executes the actions of the given state, with that state's `context` and `event`.
@@ -82,56 +90,56 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
82
90
  * @param state The state whose actions will be executed
83
91
  * @param actionsConfig The action implementations to use
84
92
  */
85
- execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
93
+ execute(state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
86
94
  private update;
87
- onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
88
- subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
89
- subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
95
+ onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
96
+ subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>): Subscription;
97
+ subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
90
98
  /**
91
99
  * Adds an event listener that is notified whenever an event is sent to the running interpreter.
92
100
  * @param listener The event listener
93
101
  */
94
- onEvent(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
102
+ onEvent(listener: EventListener): this;
95
103
  /**
96
104
  * Adds an event listener that is notified whenever a `send` event occurs.
97
105
  * @param listener The event listener
98
106
  */
99
- onSend(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
107
+ onSend(listener: EventListener): this;
100
108
  /**
101
109
  * Adds a context listener that is notified whenever the state context changes.
102
110
  * @param listener The context listener
103
111
  */
104
- onChange(listener: ContextListener<TContext>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
112
+ onChange(listener: ContextListener<TContext>): this;
105
113
  /**
106
114
  * Adds a listener that is notified when the machine is stopped.
107
115
  * @param listener The listener
108
116
  */
109
- onStop(listener: Listener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
117
+ onStop(listener: Listener): this;
110
118
  /**
111
119
  * Adds a state listener that is notified when the statechart has reached its final state.
112
120
  * @param listener The state listener
113
121
  */
114
- onDone(listener: EventListener<DoneEvent>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
122
+ onDone(listener: EventListener<DoneEvent>): this;
115
123
  /**
116
124
  * Removes a listener.
117
125
  * @param listener The listener to remove
118
126
  */
119
- off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
127
+ off(listener: (...args: any[]) => void): this;
120
128
  /**
121
129
  * Alias for Interpreter.prototype.start
122
130
  */
123
- init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
131
+ init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | undefined) => this;
124
132
  /**
125
133
  * Starts the interpreter from the given state, or the initial state.
126
134
  * @param initialState The state to start the statechart from
127
135
  */
128
- start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
136
+ start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
129
137
  /**
130
138
  * Stops the interpreter and unsubscribe all listeners.
131
139
  *
132
140
  * This will also notify the `onStop` listeners.
133
141
  */
134
- stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
142
+ stop(): this;
135
143
  /**
136
144
  * Sends an event to the running interpreter to trigger a transition.
137
145
  *
@@ -141,7 +149,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
141
149
  *
142
150
  * @param event The event(s) to send
143
151
  */
144
- send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
152
+ send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
145
153
  private batch;
146
154
  /**
147
155
  * Returns a send function bound to this interpreter instance.
@@ -157,7 +165,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
157
165
  *
158
166
  * @param event The event to determine the next state
159
167
  */
160
- nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
168
+ nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
161
169
  private forward;
162
170
  private defer;
163
171
  private cancel;
@@ -181,11 +189,11 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
181
189
  toJSON(): {
182
190
  id: string;
183
191
  };
184
- [Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
185
- getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
192
+ [symbolObservable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
193
+ getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
186
194
  }
187
195
  export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
188
- export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
196
+ export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE, any, any, any, any>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE, any, any, any, any>>;
189
197
  export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;
190
198
  /**
191
199
  * Creates a new Interpreter instance for the given machine with the provided options, if any.
@@ -196,6 +204,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
196
204
  export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
197
205
  value: any;
198
206
  context: TContext;
199
- }>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
207
+ }, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta> : 'Some implementations missing', options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
200
208
  export {};
201
209
  //# sourceMappingURL=interpreter.d.ts.map
package/es/interpreter.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
2
2
  import { IS_PRODUCTION } from './environment.js';
3
- import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, interopSymbols, symbolObservable, isArray, toEventObject, isString, isActor, toObserver, uniqueId } from './utils.js';
3
+ import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
4
4
  import { ActionTypes, SpecialTargets } from './types.js';
5
5
  import { isInFinalState } from './stateUtils.js';
6
6
  import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
7
7
  import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
8
- import { isState, State, bindActionToState } from './State.js';
8
+ import { isStateConfig, State, bindActionToState } from './State.js';
9
9
  import { provide, consume } from './serviceScope.js';
10
10
  import { isSpawnedActor, createDeferredActor } from './Actor.js';
11
11
  import { Scheduler } from './scheduler.js';
@@ -459,7 +459,7 @@ function () {
459
459
  this.initialized = true;
460
460
  this.status = InterpreterStatus.Running;
461
461
  var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
462
- return isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
462
+ return isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
463
463
  });
464
464
 
465
465
  if (this.options.devTools) {
@@ -997,6 +997,8 @@ function () {
997
997
  };
998
998
 
999
999
  Interpreter.prototype.spawnPromise = function (promise, id) {
1000
+ var _a;
1001
+
1000
1002
  var _this = this;
1001
1003
 
1002
1004
  var canceled = false;
@@ -1039,8 +1041,7 @@ function () {
1039
1041
  }
1040
1042
  }
1041
1043
  });
1042
-
1043
- var actor = __assign({
1044
+ var actor = (_a = {
1044
1045
  id: id,
1045
1046
  send: function () {
1046
1047
  return void 0;
@@ -1084,13 +1085,16 @@ function () {
1084
1085
  getSnapshot: function () {
1085
1086
  return resolvedData;
1086
1087
  }
1087
- }, interopSymbols);
1088
-
1088
+ }, _a[symbolObservable] = function () {
1089
+ return this;
1090
+ }, _a);
1089
1091
  this.children.set(id, actor);
1090
1092
  return actor;
1091
1093
  };
1092
1094
 
1093
1095
  Interpreter.prototype.spawnCallback = function (callback, id) {
1096
+ var _a;
1097
+
1094
1098
  var _this = this;
1095
1099
 
1096
1100
  var canceled = false;
@@ -1129,7 +1133,7 @@ function () {
1129
1133
  return this.spawnPromise(callbackStop, id);
1130
1134
  }
1131
1135
 
1132
- var actor = __assign({
1136
+ var actor = (_a = {
1133
1137
  id: id,
1134
1138
  send: function (event) {
1135
1139
  return receivers.forEach(function (receiver) {
@@ -1137,10 +1141,11 @@ function () {
1137
1141
  });
1138
1142
  },
1139
1143
  subscribe: function (next) {
1140
- listeners.add(next);
1144
+ var observer = toObserver(next);
1145
+ listeners.add(observer.next);
1141
1146
  return {
1142
1147
  unsubscribe: function () {
1143
- listeners.delete(next);
1148
+ listeners.delete(observer.next);
1144
1149
  }
1145
1150
  };
1146
1151
  },
@@ -1159,13 +1164,16 @@ function () {
1159
1164
  getSnapshot: function () {
1160
1165
  return emitted;
1161
1166
  }
1162
- }, interopSymbols);
1163
-
1167
+ }, _a[symbolObservable] = function () {
1168
+ return this;
1169
+ }, _a);
1164
1170
  this.children.set(id, actor);
1165
1171
  return actor;
1166
1172
  };
1167
1173
 
1168
1174
  Interpreter.prototype.spawnObservable = function (source, id) {
1175
+ var _a;
1176
+
1169
1177
  var _this = this;
1170
1178
 
1171
1179
  var emitted;
@@ -1188,8 +1196,7 @@ function () {
1188
1196
  origin: id
1189
1197
  }));
1190
1198
  });
1191
-
1192
- var actor = __assign({
1199
+ var actor = (_a = {
1193
1200
  id: id,
1194
1201
  send: function () {
1195
1202
  return void 0;
@@ -1208,8 +1215,9 @@ function () {
1208
1215
  id: id
1209
1216
  };
1210
1217
  }
1211
- }, interopSymbols);
1212
-
1218
+ }, _a[symbolObservable] = function () {
1219
+ return this;
1220
+ }, _a);
1213
1221
  this.children.set(id, actor);
1214
1222
  return actor;
1215
1223
  };
@@ -1237,7 +1245,9 @@ function () {
1237
1245
  };
1238
1246
 
1239
1247
  Interpreter.prototype.spawnEffect = function (id, dispose) {
1240
- this.children.set(id, __assign({
1248
+ var _a;
1249
+
1250
+ this.children.set(id, (_a = {
1241
1251
  id: id,
1242
1252
  send: function () {
1243
1253
  return void 0;
@@ -1258,7 +1268,9 @@ function () {
1258
1268
  id: id
1259
1269
  };
1260
1270
  }
1261
- }, interopSymbols));
1271
+ }, _a[symbolObservable] = function () {
1272
+ return this;
1273
+ }, _a));
1262
1274
  };
1263
1275
 
1264
1276
  Interpreter.prototype.attachDev = function () {
@@ -1299,9 +1311,7 @@ function () {
1299
1311
 
1300
1312
  Interpreter.prototype[symbolObservable] = function () {
1301
1313
  return this;
1302
- }; // this gets stripped by Babel to avoid having "undefined" property in environments without this non-standard Symbol
1303
- // it has to be here to be included in the generated .d.ts
1304
-
1314
+ };
1305
1315
 
1306
1316
  Interpreter.prototype.getSnapshot = function () {
1307
1317
  if (this.status === InterpreterStatus.NotStarted) {
package/es/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { EventObject, BaseActionObject } from './types';
2
- import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
1
+ import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
2
+ import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
3
3
  export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
4
  export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
5
  //# sourceMappingURL=model.d.ts.map
@@ -1,18 +1,17 @@
1
- import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine, BaseActionObject } from './types';
2
- export declare type AnyFunction = (...args: any[]) => any;
3
- export declare type IsNever<T> = [T] extends [never] ? true : false;
4
- export declare type Cast<T extends any, TCastType extends any> = T extends TCastType ? T : TCastType;
5
- export declare type Compute<A extends any> = {
6
- [K in keyof A]: A[K];
7
- } & unknown;
8
- export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
1
+ import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
2
+ import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
9
3
  export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
10
4
  initialContext: TContext;
11
5
  assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
12
6
  events: Prop<TModelCreators, 'events'>;
13
7
  actions: Prop<TModelCreators, 'actions'>;
14
8
  reset: () => AssignAction<TContext, any>;
15
- createMachine: (config: MachineConfig<TContext, any, TEvent, TAction>, implementations?: Partial<MachineOptions<TContext, TEvent, TAction>>) => StateMachine<TContext, any, TEvent>;
9
+ createMachine: {
10
+ <TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
11
+ value: any;
12
+ context: TContext;
13
+ }, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
14
+ };
16
15
  }
17
16
  export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
18
17
  export declare type ModelEventsFrom<TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
package/es/schema.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare function createSchema<T>(schema?: any): T;
2
+ export declare const t: typeof createSchema;
2
3
  //# sourceMappingURL=schema.d.ts.map
package/es/schema.js CHANGED
@@ -1,5 +1,6 @@
1
1
  function createSchema(schema) {
2
2
  return schema;
3
3
  }
4
+ var t = createSchema;
4
5
 
5
- export { createSchema };
6
+ export { createSchema, t };
package/es/scxml.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { StateNode } from './index';
1
+ import { AnyStateMachine } from './index';
2
2
  export interface ScxmlToMachineOptions {
3
3
  delimiter?: string;
4
4
  }
5
- export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
5
+ export declare function toMachine(xml: string, options: ScxmlToMachineOptions): AnyStateMachine;
6
6
  //# sourceMappingURL=scxml.d.ts.map