xstate 4.26.0-pr2674-20219515814 → 4.26.1

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 (65) hide show
  1. package/CHANGELOG.md +37 -10
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.d.ts +2 -1
  6. package/es/Machine.d.ts +4 -5
  7. package/es/State.d.ts +10 -12
  8. package/es/State.js +1 -1
  9. package/es/StateNode.d.ts +14 -15
  10. package/es/StateNode.js +39 -39
  11. package/es/_virtual/_tslib.js +8 -4
  12. package/es/actions.d.ts +5 -4
  13. package/es/actions.js +7 -7
  14. package/es/behaviors.d.ts +1 -1
  15. package/es/devTools.d.ts +2 -3
  16. package/es/devTools.js +4 -0
  17. package/es/each.d.ts +1 -1
  18. package/es/index.d.ts +0 -1
  19. package/es/interpreter.d.ts +25 -35
  20. package/es/interpreter.js +19 -17
  21. package/es/model.d.ts +2 -2
  22. package/es/model.types.d.ts +9 -8
  23. package/es/registry.js +1 -1
  24. package/es/scxml.d.ts +2 -2
  25. package/es/stateUtils.d.ts +6 -6
  26. package/es/stateUtils.js +8 -3
  27. package/es/types.d.ts +46 -60
  28. package/es/utils.d.ts +1 -1
  29. package/es/utils.js +10 -10
  30. package/lib/Actor.d.ts +2 -1
  31. package/lib/Machine.d.ts +4 -5
  32. package/lib/SimulatedClock.js +9 -5
  33. package/lib/State.d.ts +10 -12
  34. package/lib/State.js +1 -1
  35. package/lib/StateNode.d.ts +14 -15
  36. package/lib/StateNode.js +38 -38
  37. package/lib/_virtual/_tslib.js +8 -4
  38. package/lib/actions.d.ts +5 -4
  39. package/lib/actions.js +7 -7
  40. package/lib/behaviors.d.ts +1 -1
  41. package/lib/devTools.d.ts +2 -3
  42. package/lib/devTools.js +4 -0
  43. package/lib/each.d.ts +1 -1
  44. package/lib/index.d.ts +0 -1
  45. package/lib/interpreter.d.ts +25 -35
  46. package/lib/interpreter.js +19 -17
  47. package/lib/json.js +7 -7
  48. package/lib/model.d.ts +2 -2
  49. package/lib/model.js +14 -10
  50. package/lib/model.types.d.ts +9 -8
  51. package/lib/patterns.js +2 -2
  52. package/lib/registry.js +1 -1
  53. package/lib/scxml.d.ts +2 -2
  54. package/lib/scxml.js +29 -25
  55. package/lib/stateUtils.d.ts +6 -6
  56. package/lib/stateUtils.js +7 -1
  57. package/lib/types.d.ts +46 -60
  58. package/lib/utils.d.ts +1 -1
  59. package/lib/utils.js +10 -10
  60. package/package.json +4 -8
  61. package/dist/xstate.cjs.d.ts +0 -11
  62. package/dist/xstate.cjs.js +0 -16
  63. package/es/typegenTypes.d.ts +0 -78
  64. package/lib/typegenTypes.d.ts +0 -78
  65. package/lib/typegenTypes.js +0 -2
@@ -1,4 +1,4 @@
1
- import { ActorContext, ActorRef, Behavior, EventObject } from './types';
1
+ import { ActorContext, ActorRef, Behavior, EventObject } from '.';
2
2
  /**
3
3
  * Returns an actor behavior from a reducer and its initial state.
4
4
  *
package/lib/devTools.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
1
+ import { Interpreter } from '.';
2
2
  import { AnyInterpreter } from './types';
3
- import { Interpreter } from './interpreter';
4
3
  declare type ServiceListener = (service: AnyInterpreter) => void;
5
4
  export interface XStateDevInterface {
6
5
  register: (service: Interpreter<any>) => void;
@@ -10,7 +9,7 @@ export interface XStateDevInterface {
10
9
  };
11
10
  services: Set<Interpreter<any>>;
12
11
  }
13
- export declare function getGlobal(): (Window & typeof globalThis) | (NodeJS.Global & typeof globalThis) | undefined;
12
+ export declare function getGlobal(): typeof globalThis | undefined;
14
13
  export declare function registerService(service: AnyInterpreter): void;
15
14
  export {};
16
15
  //# sourceMappingURL=devTools.d.ts.map
package/lib/devTools.js CHANGED
@@ -4,6 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6
6
  function getGlobal() {
7
+ if (typeof globalThis !== 'undefined') {
8
+ return globalThis;
9
+ }
10
+
7
11
  if (typeof self !== 'undefined') {
8
12
  return self;
9
13
  }
package/lib/each.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventObject, SingleOrArray, ActionObject } from './types';
1
+ import { EventObject, SingleOrArray, ActionObject } from '.';
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/lib/index.d.ts CHANGED
@@ -28,5 +28,4 @@ declare const actions: {
28
28
  };
29
29
  export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
30
30
  export * from './types';
31
- export * from './typegenTypes';
32
31
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,9 @@
1
1
  import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
2
2
  import { State } from './State';
3
- import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
4
3
  export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
5
4
  value: any;
6
5
  context: TContext;
7
- }, TResolvedTypesMeta = TypegenDisabled> = (state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, event: TEvent) => void;
6
+ }> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
8
7
  export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;
9
8
  export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
10
9
  export declare type Listener = () => void;
@@ -30,24 +29,15 @@ declare global {
30
29
  export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
31
30
  value: any;
32
31
  context: TContext;
33
- }, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>> {
34
- machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta>;
32
+ }> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
33
+ machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
35
34
  /**
36
35
  * The default interpreter options:
37
36
  *
38
37
  * - `clock` uses the global `setTimeout` and `clearTimeout` functions
39
38
  * - `logger` uses the global `console.log()` method
40
39
  */
41
- static defaultOptions: {
42
- execute: boolean;
43
- deferEvents: boolean;
44
- clock: {
45
- setTimeout: (fn: any, ms: any) => number;
46
- clearTimeout: (id: any) => void;
47
- };
48
- logger: any;
49
- devTools: boolean;
50
- };
40
+ static defaultOptions: InterpreterOptions;
51
41
  /**
52
42
  * The current state of the interpreted machine.
53
43
  */
@@ -87,9 +77,9 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
87
77
  * @param machine The machine to be interpreted
88
78
  * @param options Interpreter options
89
79
  */
90
- constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta>, options?: InterpreterOptions);
91
- get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
92
- get state(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
80
+ constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
81
+ get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
82
+ get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
93
83
  static interpret: typeof interpret;
94
84
  /**
95
85
  * Executes the actions of the given state, with that state's `context` and `event`.
@@ -97,56 +87,56 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
97
87
  * @param state The state whose actions will be executed
98
88
  * @param actionsConfig The action implementations to use
99
89
  */
100
- execute(state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
90
+ execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
101
91
  private update;
102
- onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
103
- subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
104
- subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>): Subscription;
92
+ onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
93
+ subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
94
+ subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
105
95
  /**
106
96
  * Adds an event listener that is notified whenever an event is sent to the running interpreter.
107
97
  * @param listener The event listener
108
98
  */
109
- onEvent(listener: EventListener): this;
99
+ onEvent(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
110
100
  /**
111
101
  * Adds an event listener that is notified whenever a `send` event occurs.
112
102
  * @param listener The event listener
113
103
  */
114
- onSend(listener: EventListener): this;
104
+ onSend(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
115
105
  /**
116
106
  * Adds a context listener that is notified whenever the state context changes.
117
107
  * @param listener The context listener
118
108
  */
119
- onChange(listener: ContextListener<TContext>): this;
109
+ onChange(listener: ContextListener<TContext>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
120
110
  /**
121
111
  * Adds a listener that is notified when the machine is stopped.
122
112
  * @param listener The listener
123
113
  */
124
- onStop(listener: Listener): this;
114
+ onStop(listener: Listener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
125
115
  /**
126
116
  * Adds a state listener that is notified when the statechart has reached its final state.
127
117
  * @param listener The state listener
128
118
  */
129
- onDone(listener: EventListener<DoneEvent>): this;
119
+ onDone(listener: EventListener<DoneEvent>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
130
120
  /**
131
121
  * Removes a listener.
132
122
  * @param listener The listener to remove
133
123
  */
134
- off(listener: (...args: any[]) => void): this;
124
+ off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
135
125
  /**
136
126
  * Alias for Interpreter.prototype.start
137
127
  */
138
- init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | undefined) => this;
128
+ init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
139
129
  /**
140
130
  * Starts the interpreter from the given state, or the initial state.
141
131
  * @param initialState The state to start the statechart from
142
132
  */
143
- start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateValue): this;
133
+ start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
144
134
  /**
145
135
  * Stops the interpreter and unsubscribe all listeners.
146
136
  *
147
137
  * This will also notify the `onStop` listeners.
148
138
  */
149
- stop(): this;
139
+ stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
150
140
  /**
151
141
  * Sends an event to the running interpreter to trigger a transition.
152
142
  *
@@ -156,7 +146,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
156
146
  *
157
147
  * @param event The event(s) to send
158
148
  */
159
- send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
149
+ send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
160
150
  private batch;
161
151
  /**
162
152
  * Returns a send function bound to this interpreter instance.
@@ -172,7 +162,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
172
162
  *
173
163
  * @param event The event to determine the next state
174
164
  */
175
- nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
165
+ nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
176
166
  private forward;
177
167
  private defer;
178
168
  private cancel;
@@ -196,8 +186,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
196
186
  toJSON(): {
197
187
  id: string;
198
188
  };
199
- [Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
200
- getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
189
+ [Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
190
+ getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
201
191
  }
202
192
  export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
203
193
  export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
@@ -211,6 +201,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
211
201
  export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
212
202
  value: any;
213
203
  context: TContext;
214
- }, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta> : 'Some implementations missing', options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
204
+ }>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
215
205
  export {};
216
206
  //# sourceMappingURL=interpreter.d.ts.map
@@ -90,14 +90,15 @@ function () {
90
90
  if (_this.status === exports.InterpreterStatus.Stopped) {
91
91
  // do nothing
92
92
  if (!environment.IS_PRODUCTION) {
93
- utils.warn(false, "Event \"" + _event.name + "\" was sent to stopped service \"" + _this.machine.id + "\". This service has already reached its final state, and will not transition.\nEvent: " + JSON.stringify(_event.data));
93
+ utils.warn(false, "Event \"".concat(_event.name, "\" was sent to stopped service \"").concat(_this.machine.id, "\". This service has already reached its final state, and will not transition.\nEvent: ").concat(JSON.stringify(_event.data)));
94
94
  }
95
95
 
96
96
  return _this.state;
97
97
  }
98
98
 
99
99
  if (_this.status !== exports.InterpreterStatus.Running && !_this.options.deferEvents) {
100
- throw new Error("Event \"" + _event.name + "\" was sent to uninitialized service \"" + _this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: " + JSON.stringify(_event.data));
100
+ throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
101
+ , "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
101
102
  }
102
103
 
103
104
  _this.scheduler.schedule(function () {
@@ -119,12 +120,12 @@ function () {
119
120
 
120
121
  if (!target) {
121
122
  if (!isParent) {
122
- throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
123
+ throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
123
124
  } // tslint:disable-next-line:no-console
124
125
 
125
126
 
126
127
  if (!environment.IS_PRODUCTION) {
127
- utils.warn(false, "Service '" + _this.id + "' has no parent: unable to send event " + event.type);
128
+ utils.warn(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
128
129
  }
129
130
 
130
131
  return;
@@ -133,7 +134,7 @@ function () {
133
134
  if ('machine' in target) {
134
135
  // Send SCXML events to machines
135
136
  target.send(_tslib.__assign(_tslib.__assign({}, event), {
136
- name: event.name === actionTypes.error ? "" + actions.error(_this.id) : event.name,
137
+ name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
137
138
  origin: _this.sessionId
138
139
  }));
139
140
  } else {
@@ -179,7 +180,7 @@ function () {
179
180
  Object.defineProperty(Interpreter.prototype, "state", {
180
181
  get: function () {
181
182
  if (!environment.IS_PRODUCTION) {
182
- utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '" + this.id + "'. Make sure the service is started first.");
183
+ utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
183
184
  }
184
185
 
185
186
  return this._state;
@@ -619,11 +620,11 @@ function () {
619
620
  if (this.status === exports.InterpreterStatus.NotStarted && this.options.deferEvents) {
620
621
  // tslint:disable-next-line:no-console
621
622
  if (!environment.IS_PRODUCTION) {
622
- utils.warn(false, events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\" and are deferred. Make sure .start() is called for this service.\nEvent: " + JSON.stringify(event));
623
+ utils.warn(false, "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\" and are deferred. Make sure .start() is called for this service.\nEvent: ").concat(JSON.stringify(event)));
623
624
  }
624
625
  } else if (this.status !== exports.InterpreterStatus.Running) {
625
626
  throw new Error( // tslint:disable-next-line:max-line-length
626
- events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.");
627
+ "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
627
628
  }
628
629
 
629
630
  this.scheduler.schedule(function () {
@@ -643,7 +644,7 @@ function () {
643
644
  });
644
645
  batchedActions.push.apply(batchedActions, _tslib.__spreadArray([], _tslib.__read(nextState.actions.map(function (a) {
645
646
  return State.bindActionToState(a, nextState);
646
- }))));
647
+ })), false));
647
648
  batchChanged = batchChanged || !!nextState.changed;
648
649
  };
649
650
 
@@ -716,7 +717,7 @@ function () {
716
717
  var child = this.children.get(id);
717
718
 
718
719
  if (!child) {
719
- throw new Error("Unable to forward event '" + event + "' from interpreter '" + this.id + "' to nonexistant child '" + id + "'.");
720
+ throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
720
721
  }
721
722
 
722
723
  child.send(event);
@@ -820,7 +821,7 @@ function () {
820
821
 
821
822
  if (!environment.IS_PRODUCTION) {
822
823
  utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
823
- "`forward` property is deprecated (found in invocation of '" + activity.src + "' in in machine '" + this.machine.id + "'). " + "Please use `autoForward` instead.");
824
+ "`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
824
825
  }
825
826
 
826
827
  var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
@@ -828,7 +829,7 @@ function () {
828
829
  if (!serviceCreator) {
829
830
  // tslint:disable-next-line:no-console
830
831
  if (!environment.IS_PRODUCTION) {
831
- utils.warn(false, "No service found for invocation '" + activity.src + "' in machine '" + this.machine.id + "'.");
832
+ utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
832
833
  }
833
834
 
834
835
  return;
@@ -843,7 +844,8 @@ function () {
843
844
 
844
845
  var source = utils.isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
845
846
  data: resolvedData,
846
- src: invokeSource
847
+ src: invokeSource,
848
+ meta: activity.meta
847
849
  }) : serviceCreator;
848
850
 
849
851
  if (!source) {
@@ -888,7 +890,7 @@ function () {
888
890
 
889
891
  default:
890
892
  if (!environment.IS_PRODUCTION) {
891
- utils.warn(false, "No implementation found for action type '" + action.type + "'");
893
+ utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
892
894
  }
893
895
 
894
896
  break;
@@ -937,7 +939,7 @@ function () {
937
939
  } else if (utils.isBehavior(entity)) {
938
940
  return this.spawnBehavior(entity, name);
939
941
  } else {
940
- throw new Error("Unable to spawn entity \"" + name + "\" of type \"" + typeof entity + "\".");
942
+ throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
941
943
  }
942
944
  };
943
945
 
@@ -1213,7 +1215,7 @@ function () {
1213
1215
 
1214
1216
  if (!implementation) {
1215
1217
  if (!environment.IS_PRODUCTION) {
1216
- utils.warn(false, "No implementation found for activity '" + activity.type + "'");
1218
+ utils.warn(false, "No implementation found for activity '".concat(activity.type, "'"));
1217
1219
  } // tslint:disable-next-line:no-console
1218
1220
 
1219
1221
 
@@ -1345,7 +1347,7 @@ function spawn(entity, nameOrOptions) {
1345
1347
  return serviceScope.consume(function (service) {
1346
1348
  if (!environment.IS_PRODUCTION) {
1347
1349
  var isLazyEntity = utils.isMachine(entity) || utils.isFunction(entity);
1348
- utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"" + (utils.isMachine(entity) ? entity.id : 'undefined') + "\") outside of a service. This will have no effect.");
1350
+ utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat(utils.isMachine(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
1349
1351
  }
1350
1352
 
1351
1353
  if (service) {
package/lib/json.js CHANGED
@@ -10,7 +10,7 @@ function stringifyFunction(fn) {
10
10
  }
11
11
  exports.stringifyFunction = stringifyFunction;
12
12
  function getStateNodeId(stateNode) {
13
- return "#" + stateNode.id;
13
+ return "#".concat(stateNode.id);
14
14
  }
15
15
  // derive config from machine
16
16
  function machineToJSON(stateNode) {
@@ -21,7 +21,7 @@ function machineToJSON(stateNode) {
21
21
  key: stateNode.key,
22
22
  entry: stateNode.onEntry,
23
23
  exit: stateNode.onExit,
24
- on: utils_1.mapValues(stateNode.on, function (transition) {
24
+ on: (0, utils_1.mapValues)(stateNode.on, function (transition) {
25
25
  return transition.map(function (t) {
26
26
  return {
27
27
  target: t.target ? t.target.map(getStateNodeId) : [],
@@ -43,7 +43,7 @@ function machineToJSON(stateNode) {
43
43
  exports.machineToJSON = machineToJSON;
44
44
  function stringify(machine) {
45
45
  return JSON.stringify(machineToJSON(machine), function (_, value) {
46
- if (utils_1.isFunction(value)) {
46
+ if ((0, utils_1.isFunction)(value)) {
47
47
  return { $function: value.toString() };
48
48
  }
49
49
  return value;
@@ -63,14 +63,14 @@ exports.parse = parse;
63
63
  function jsonify(value) {
64
64
  Object.defineProperty(value, 'toJSON', {
65
65
  value: function () {
66
- return utils_1.mapValues(value, function (subValue) {
67
- if (utils_1.isFunction(subValue)) {
66
+ return (0, utils_1.mapValues)(value, function (subValue) {
67
+ if ((0, utils_1.isFunction)(subValue)) {
68
68
  return stringifyFunction(subValue);
69
69
  }
70
70
  else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
71
71
  // mostly for assignments
72
- return utils_1.mapValues(subValue, function (subSubValue) {
73
- if (utils_1.isFunction(subSubValue)) {
72
+ return (0, utils_1.mapValues)(subValue, function (subSubValue) {
73
+ if ((0, utils_1.isFunction)(subSubValue)) {
74
74
  return stringifyFunction(subSubValue);
75
75
  }
76
76
  return subSubValue;
package/lib/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
2
- import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
1
+ import type { EventObject, BaseActionObject } from './types';
2
+ import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } 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
package/lib/model.js CHANGED
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  Object.defineProperty(exports, "__esModule", { value: true });
35
39
  exports.createModel = void 0;
@@ -43,26 +47,26 @@ function createModel(initialContext, creators) {
43
47
  initialContext: initialContext,
44
48
  assign: actions_1.assign,
45
49
  events: (eventCreators
46
- ? utils_1.mapValues(eventCreators, function (fn, eventType) { return function () {
50
+ ? (0, utils_1.mapValues)(eventCreators, function (fn, eventType) { return function () {
47
51
  var args = [];
48
52
  for (var _i = 0; _i < arguments.length; _i++) {
49
53
  args[_i] = arguments[_i];
50
54
  }
51
- return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: eventType }));
55
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: eventType }));
52
56
  }; })
53
57
  : undefined),
54
58
  actions: actionCreators
55
- ? utils_1.mapValues(actionCreators, function (fn, actionType) { return function () {
59
+ ? (0, utils_1.mapValues)(actionCreators, function (fn, actionType) { return function () {
56
60
  var args = [];
57
61
  for (var _i = 0; _i < arguments.length; _i++) {
58
62
  args[_i] = arguments[_i];
59
63
  }
60
- return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: actionType }));
64
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: actionType }));
61
65
  }; })
62
66
  : undefined,
63
- reset: function () { return actions_1.assign(initialContext); },
67
+ reset: function () { return (0, actions_1.assign)(initialContext); },
64
68
  createMachine: function (config, implementations) {
65
- return Machine_1.createMachine('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
69
+ return (0, Machine_1.createMachine)('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
66
70
  }
67
71
  };
68
72
  return model;
@@ -1,17 +1,18 @@
1
- import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine } from './types';
2
- import { MaybeTypegenMachineOptions, ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
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;
3
9
  export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
4
10
  initialContext: TContext;
5
11
  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>>;
6
12
  events: Prop<TModelCreators, 'events'>;
7
13
  actions: Prop<TModelCreators, 'actions'>;
8
14
  reset: () => AssignAction<TContext, any>;
9
- createMachine: {
10
- <TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TTypesMeta>, implementations?: MaybeTypegenMachineOptions<TContext, TEvent, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>): StateMachine<TContext, any, TEvent, {
11
- value: any;
12
- context: TContext;
13
- }, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>;
14
- };
15
+ createMachine: (config: MachineConfig<TContext, any, TEvent, TAction>, implementations?: Partial<MachineOptions<TContext, TEvent, TAction>>) => StateMachine<TContext, any, TEvent>;
15
16
  }
16
17
  export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
17
18
  export declare type ModelEventsFrom<TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
package/lib/patterns.js CHANGED
@@ -34,10 +34,10 @@ function sequence(items, options) {
34
34
  var states = {};
35
35
  var nextEventObject = resolvedOptions.nextEvent === undefined
36
36
  ? undefined
37
- : utils_1.toEventObject(resolvedOptions.nextEvent);
37
+ : (0, utils_1.toEventObject)(resolvedOptions.nextEvent);
38
38
  var prevEventObject = resolvedOptions.prevEvent === undefined
39
39
  ? undefined
40
- : utils_1.toEventObject(resolvedOptions.prevEvent);
40
+ : (0, utils_1.toEventObject)(resolvedOptions.prevEvent);
41
41
  items.forEach(function (item, i) {
42
42
  var state = {
43
43
  on: {}
package/lib/registry.js CHANGED
@@ -6,7 +6,7 @@ var children = /*#__PURE__*/new Map();
6
6
  var sessionIdIndex = 0;
7
7
  var registry = {
8
8
  bookId: function () {
9
- return "x:" + sessionIdIndex++;
9
+ return "x:".concat(sessionIdIndex++);
10
10
  },
11
11
  register: function (id, actor) {
12
12
  children.set(id, actor);
package/lib/scxml.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { StateMachine } from './index';
1
+ import { StateNode } from './index';
2
2
  export interface ScxmlToMachineOptions {
3
3
  delimiter?: string;
4
4
  }
5
- export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateMachine<any, any, any>;
5
+ export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
6
6
  //# sourceMappingURL=scxml.d.ts.map