xstate 4.26.0-pr2674-202191175724 → 4.27.0
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.
- package/CHANGELOG.md +60 -10
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +2 -1
- package/es/Machine.d.ts +4 -5
- package/es/State.d.ts +14 -13
- package/es/State.js +10 -3
- package/es/StateNode.d.ts +15 -15
- package/es/StateNode.js +50 -56
- package/es/_virtual/_tslib.js +8 -4
- package/es/actions.d.ts +21 -4
- package/es/actions.js +7 -7
- package/es/behaviors.d.ts +1 -1
- package/es/devTools.d.ts +2 -3
- package/es/devTools.js +4 -0
- package/es/each.d.ts +1 -1
- package/es/index.d.ts +0 -1
- package/es/interpreter.d.ts +25 -35
- package/es/interpreter.js +23 -17
- package/es/model.d.ts +2 -2
- package/es/model.types.d.ts +9 -8
- package/es/registry.js +1 -1
- package/es/scxml.d.ts +2 -2
- package/es/stateUtils.d.ts +6 -6
- package/es/stateUtils.js +8 -3
- package/es/types.d.ts +55 -69
- package/es/utils.d.ts +1 -1
- package/es/utils.js +10 -10
- package/lib/Actor.d.ts +2 -1
- package/lib/Machine.d.ts +4 -5
- package/lib/SimulatedClock.js +9 -5
- package/lib/State.d.ts +14 -13
- package/lib/State.js +10 -3
- package/lib/StateNode.d.ts +15 -15
- package/lib/StateNode.js +47 -53
- package/lib/_virtual/_tslib.js +8 -4
- package/lib/actions.d.ts +21 -4
- package/lib/actions.js +7 -7
- package/lib/behaviors.d.ts +1 -1
- package/lib/devTools.d.ts +2 -3
- package/lib/devTools.js +4 -0
- package/lib/each.d.ts +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/interpreter.d.ts +25 -35
- package/lib/interpreter.js +23 -17
- package/lib/json.js +7 -7
- package/lib/model.d.ts +2 -2
- package/lib/model.js +14 -10
- package/lib/model.types.d.ts +9 -8
- package/lib/patterns.js +2 -2
- package/lib/registry.js +1 -1
- package/lib/scxml.d.ts +2 -2
- package/lib/scxml.js +29 -25
- package/lib/stateUtils.d.ts +6 -6
- package/lib/stateUtils.js +7 -1
- package/lib/types.d.ts +55 -69
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +10 -10
- package/package.json +4 -8
- package/dist/xstate.cjs.d.ts +0 -11
- package/dist/xstate.cjs.js +0 -16
- package/es/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.js +0 -2
package/lib/interpreter.d.ts
CHANGED
|
@@ -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
|
-
}
|
|
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
|
-
}
|
|
34
|
-
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
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
|
|
91
|
-
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
92
|
-
get state(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
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
|
|
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
|
|
103
|
-
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate
|
|
104
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate
|
|
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):
|
|
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):
|
|
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>):
|
|
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):
|
|
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>):
|
|
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):
|
|
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
|
|
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
|
|
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():
|
|
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
|
|
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
|
|
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
|
|
200
|
-
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate
|
|
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
|
-
}
|
|
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
|
package/lib/interpreter.js
CHANGED
|
@@ -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 \""
|
|
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 \""
|
|
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 '"
|
|
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 '"
|
|
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 ? ""
|
|
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 '"
|
|
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
|
|
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
|
|
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 '"
|
|
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);
|
|
@@ -803,6 +804,10 @@ function () {
|
|
|
803
804
|
|
|
804
805
|
case actionTypes.start:
|
|
805
806
|
{
|
|
807
|
+
if (this.status !== exports.InterpreterStatus.Running) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
|
|
806
811
|
var activity = action.activity; // If the activity will be stopped right after it's started
|
|
807
812
|
// (such as in transient states)
|
|
808
813
|
// don't bother starting the activity.
|
|
@@ -820,7 +825,7 @@ function () {
|
|
|
820
825
|
|
|
821
826
|
if (!environment.IS_PRODUCTION) {
|
|
822
827
|
utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
|
|
823
|
-
"`forward` property is deprecated (found in invocation of '"
|
|
828
|
+
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
|
|
824
829
|
}
|
|
825
830
|
|
|
826
831
|
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
|
|
@@ -828,7 +833,7 @@ function () {
|
|
|
828
833
|
if (!serviceCreator) {
|
|
829
834
|
// tslint:disable-next-line:no-console
|
|
830
835
|
if (!environment.IS_PRODUCTION) {
|
|
831
|
-
utils.warn(false, "No service found for invocation '"
|
|
836
|
+
utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
|
|
832
837
|
}
|
|
833
838
|
|
|
834
839
|
return;
|
|
@@ -843,7 +848,8 @@ function () {
|
|
|
843
848
|
|
|
844
849
|
var source = utils.isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
|
|
845
850
|
data: resolvedData,
|
|
846
|
-
src: invokeSource
|
|
851
|
+
src: invokeSource,
|
|
852
|
+
meta: activity.meta
|
|
847
853
|
}) : serviceCreator;
|
|
848
854
|
|
|
849
855
|
if (!source) {
|
|
@@ -888,7 +894,7 @@ function () {
|
|
|
888
894
|
|
|
889
895
|
default:
|
|
890
896
|
if (!environment.IS_PRODUCTION) {
|
|
891
|
-
utils.warn(false, "No implementation found for action type '"
|
|
897
|
+
utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
|
|
892
898
|
}
|
|
893
899
|
|
|
894
900
|
break;
|
|
@@ -937,7 +943,7 @@ function () {
|
|
|
937
943
|
} else if (utils.isBehavior(entity)) {
|
|
938
944
|
return this.spawnBehavior(entity, name);
|
|
939
945
|
} else {
|
|
940
|
-
throw new Error("Unable to spawn entity \""
|
|
946
|
+
throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
|
|
941
947
|
}
|
|
942
948
|
};
|
|
943
949
|
|
|
@@ -1213,7 +1219,7 @@ function () {
|
|
|
1213
1219
|
|
|
1214
1220
|
if (!implementation) {
|
|
1215
1221
|
if (!environment.IS_PRODUCTION) {
|
|
1216
|
-
utils.warn(false, "No implementation found for activity '"
|
|
1222
|
+
utils.warn(false, "No implementation found for activity '".concat(activity.type, "'"));
|
|
1217
1223
|
} // tslint:disable-next-line:no-console
|
|
1218
1224
|
|
|
1219
1225
|
|
|
@@ -1345,7 +1351,7 @@ function spawn(entity, nameOrOptions) {
|
|
|
1345
1351
|
return serviceScope.consume(function (service) {
|
|
1346
1352
|
if (!environment.IS_PRODUCTION) {
|
|
1347
1353
|
var isLazyEntity = utils.isMachine(entity) || utils.isFunction(entity);
|
|
1348
|
-
utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \""
|
|
1354
|
+
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
1355
|
}
|
|
1350
1356
|
|
|
1351
1357
|
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 "#"
|
|
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 {
|
|
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,
|
|
31
|
-
|
|
32
|
-
|
|
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;
|
package/lib/model.types.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
package/lib/scxml.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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):
|
|
5
|
+
export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
|
|
6
6
|
//# sourceMappingURL=scxml.d.ts.map
|