xstate 5.0.0-beta.15 → 5.0.0-beta.17
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/actions/dist/xstate-actions.cjs.js +2 -7
- package/actions/dist/xstate-actions.cjs.mjs +2 -7
- package/actions/dist/xstate-actions.development.cjs.js +2 -7
- package/actions/dist/xstate-actions.development.esm.js +1 -1
- package/actions/dist/xstate-actions.esm.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/{actions-98f362b9.development.esm.js → actions-13190b25.development.esm.js} +1335 -1537
- package/dist/{actions-d71ac253.development.cjs.js → actions-40bd643f.development.cjs.js} +1336 -1546
- package/dist/{actions-6884fae8.esm.js → actions-4d6514d2.esm.js} +1310 -1539
- package/dist/{actions-81cc7f2b.cjs.js → actions-5fb9f10d.cjs.js} +1311 -1548
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateMachine.d.ts +2 -4
- package/dist/declarations/src/StateNode.d.ts +4 -4
- package/dist/declarations/src/actions/assign.d.ts +11 -2
- package/dist/declarations/src/actions/cancel.d.ts +14 -3
- package/dist/declarations/src/actions/choose.d.ts +11 -3
- package/dist/declarations/src/actions/log.d.ts +22 -3
- package/dist/declarations/src/actions/pure.d.ts +17 -3
- package/dist/declarations/src/actions/raise.d.ts +5 -2
- package/dist/declarations/src/actions/send.d.ts +64 -22
- package/dist/declarations/src/actions/stop.d.ts +14 -2
- package/dist/declarations/src/actions.d.ts +5 -11
- package/dist/declarations/src/constantPrefixes.d.ts +6 -0
- package/dist/declarations/src/interpreter.d.ts +8 -3
- package/dist/declarations/src/stateUtils.d.ts +4 -8
- package/dist/declarations/src/types.d.ts +38 -223
- package/dist/declarations/src/utils.d.ts +1 -6
- package/dist/xstate.cjs.js +61 -52
- package/dist/xstate.cjs.mjs +1 -1
- package/dist/xstate.development.cjs.js +61 -52
- package/dist/xstate.development.esm.js +61 -52
- package/dist/xstate.esm.js +61 -52
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/actions/dynamicAction.ts +0 -42
- package/dist/declarations/src/actionTypes.d.ts +0 -16
- package/dist/declarations/src/constants.d.ts +0 -5
package/dist/xstate.cjs.js
CHANGED
|
@@ -2,10 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-5fb9f10d.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
9
|
+
const toSerializableActon = action => {
|
|
10
|
+
if (typeof action === 'string') {
|
|
11
|
+
return {
|
|
12
|
+
type: action
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (typeof action === 'function') {
|
|
16
|
+
if ('resolve' in action) {
|
|
17
|
+
return {
|
|
18
|
+
type: action.type
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
type: action.name
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return action;
|
|
26
|
+
};
|
|
9
27
|
class StateNode {
|
|
10
28
|
/**
|
|
11
29
|
* The relative key of the state node, which represents its location in the overall state value.
|
|
@@ -114,8 +132,8 @@ class StateNode {
|
|
|
114
132
|
|
|
115
133
|
// History config
|
|
116
134
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
117
|
-
this.entry = actors_dist_xstateActors.
|
|
118
|
-
this.exit = actors_dist_xstateActors.
|
|
135
|
+
this.entry = actors_dist_xstateActors.toArray(this.config.entry);
|
|
136
|
+
this.exit = actors_dist_xstateActors.toArray(this.config.exit);
|
|
119
137
|
this.meta = this.config.meta;
|
|
120
138
|
this.output = this.type === 'final' ? this.config.output : undefined;
|
|
121
139
|
this.tags = actors_dist_xstateActors.toArray(config.tags);
|
|
@@ -123,7 +141,7 @@ class StateNode {
|
|
|
123
141
|
_initialize() {
|
|
124
142
|
this.transitions = actors_dist_xstateActors.formatTransitions(this);
|
|
125
143
|
if (this.config.always) {
|
|
126
|
-
this.always = actors_dist_xstateActors.toTransitionConfigArray(
|
|
144
|
+
this.always = actors_dist_xstateActors.toTransitionConfigArray(this.config.always).map(t => actors_dist_xstateActors.formatTransition(this, actors_dist_xstateActors.NULL_EVENT, t));
|
|
127
145
|
}
|
|
128
146
|
Object.keys(this.states).forEach(key => {
|
|
129
147
|
this.states[key]._initialize();
|
|
@@ -142,13 +160,13 @@ class StateNode {
|
|
|
142
160
|
initial: this.initial ? {
|
|
143
161
|
target: this.initial.target,
|
|
144
162
|
source: this,
|
|
145
|
-
actions: this.initial.actions,
|
|
163
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
146
164
|
eventType: null,
|
|
147
165
|
reenter: false,
|
|
148
166
|
toJSON: () => ({
|
|
149
167
|
target: this.initial.target.map(t => `#${t.id}`),
|
|
150
168
|
source: `#${this.id}`,
|
|
151
|
-
actions: this.initial.actions,
|
|
169
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
152
170
|
eventType: null
|
|
153
171
|
})
|
|
154
172
|
} : undefined,
|
|
@@ -157,9 +175,12 @@ class StateNode {
|
|
|
157
175
|
return state.definition;
|
|
158
176
|
}),
|
|
159
177
|
on: this.on,
|
|
160
|
-
transitions: this.transitions
|
|
161
|
-
|
|
162
|
-
|
|
178
|
+
transitions: [...this.transitions.values()].flat().map(t => ({
|
|
179
|
+
...t,
|
|
180
|
+
actions: t.actions.map(toSerializableActon)
|
|
181
|
+
})),
|
|
182
|
+
entry: this.entry.map(toSerializableActon),
|
|
183
|
+
exit: this.exit.map(toSerializableActon),
|
|
163
184
|
meta: this.meta,
|
|
164
185
|
order: this.order || -1,
|
|
165
186
|
output: this.output,
|
|
@@ -184,7 +205,9 @@ class StateNode {
|
|
|
184
205
|
const {
|
|
185
206
|
systemId
|
|
186
207
|
} = invokeConfig;
|
|
187
|
-
|
|
208
|
+
|
|
209
|
+
// TODO: resolving should not happen here
|
|
210
|
+
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
188
211
|
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
189
212
|
this.machine.implementations.actors = {
|
|
190
213
|
...this.machine.implementations.actors,
|
|
@@ -193,7 +216,7 @@ class StateNode {
|
|
|
193
216
|
};
|
|
194
217
|
}
|
|
195
218
|
return {
|
|
196
|
-
type:
|
|
219
|
+
type: 'xstate.invoke',
|
|
197
220
|
...invokeConfig,
|
|
198
221
|
src: resolvedSrc,
|
|
199
222
|
id: resolvedId,
|
|
@@ -206,7 +229,7 @@ class StateNode {
|
|
|
206
229
|
} = invokeConfig;
|
|
207
230
|
return {
|
|
208
231
|
...invokeDefValues,
|
|
209
|
-
type:
|
|
232
|
+
type: 'xstate.invoke',
|
|
210
233
|
src: resolvedSrc,
|
|
211
234
|
id: resolvedId
|
|
212
235
|
};
|
|
@@ -221,9 +244,9 @@ class StateNode {
|
|
|
221
244
|
get on() {
|
|
222
245
|
return actors_dist_xstateActors.memo(this, 'on', () => {
|
|
223
246
|
const transitions = this.transitions;
|
|
224
|
-
return transitions.reduce((map, transition) => {
|
|
225
|
-
map[
|
|
226
|
-
map[
|
|
247
|
+
return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
|
|
248
|
+
map[descriptor] = map[descriptor] || [];
|
|
249
|
+
map[descriptor].push(transition);
|
|
227
250
|
return map;
|
|
228
251
|
}, {});
|
|
229
252
|
});
|
|
@@ -310,32 +333,15 @@ class StateNode {
|
|
|
310
333
|
* Excludes any inert events.
|
|
311
334
|
*/
|
|
312
335
|
get ownEvents() {
|
|
313
|
-
const events = new Set(this.transitions.filter(
|
|
314
|
-
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
315
|
-
})
|
|
336
|
+
const events = new Set([...this.transitions.keys()].filter(descriptor => {
|
|
337
|
+
return this.transitions.get(descriptor).some(transition => !(!transition.target && !transition.actions.length && !transition.reenter));
|
|
338
|
+
}));
|
|
316
339
|
return Array.from(events);
|
|
317
340
|
}
|
|
318
341
|
}
|
|
319
342
|
|
|
320
343
|
const STATE_IDENTIFIER = '#';
|
|
321
344
|
class StateMachine {
|
|
322
|
-
// TODO: this getter should be removed
|
|
323
|
-
getContext(input) {
|
|
324
|
-
return this.getContextAndActions(undefined, input)[0];
|
|
325
|
-
}
|
|
326
|
-
getContextAndActions(actorCtx, input) {
|
|
327
|
-
const actions = [];
|
|
328
|
-
const {
|
|
329
|
-
context
|
|
330
|
-
} = this.config;
|
|
331
|
-
const resolvedContext = typeof context === 'function' ? context({
|
|
332
|
-
spawn: actors_dist_xstateActors.createSpawner(actorCtx?.self, this, undefined,
|
|
333
|
-
// TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
|
|
334
|
-
actors_dist_xstateActors.createInitEvent(input), actions),
|
|
335
|
-
input
|
|
336
|
-
}) : context;
|
|
337
|
-
return [resolvedContext || {}, actions];
|
|
338
|
-
}
|
|
339
345
|
/**
|
|
340
346
|
* The machine's own version.
|
|
341
347
|
*/
|
|
@@ -432,10 +438,9 @@ class StateMachine {
|
|
|
432
438
|
done: actors_dist_xstateActors.isInFinalState(configuration)
|
|
433
439
|
});
|
|
434
440
|
}
|
|
435
|
-
resolveStateValue(stateValue) {
|
|
441
|
+
resolveStateValue(stateValue, ...[context]) {
|
|
436
442
|
const resolvedStateValue = actors_dist_xstateActors.resolveStateValue(this.root, stateValue);
|
|
437
|
-
|
|
438
|
-
return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, resolvedContext, this));
|
|
443
|
+
return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, context, this));
|
|
439
444
|
}
|
|
440
445
|
|
|
441
446
|
/**
|
|
@@ -474,20 +479,27 @@ class StateMachine {
|
|
|
474
479
|
* The initial state _before_ evaluating any microsteps.
|
|
475
480
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
476
481
|
*/
|
|
477
|
-
getPreInitialState(actorCtx,
|
|
478
|
-
const
|
|
479
|
-
|
|
482
|
+
getPreInitialState(actorCtx, initEvent) {
|
|
483
|
+
const {
|
|
484
|
+
context
|
|
485
|
+
} = this.config;
|
|
480
486
|
const preInitial = this.resolveState(this.createState({
|
|
481
487
|
value: {},
|
|
482
488
|
// TODO: this is computed in state constructor
|
|
483
|
-
context,
|
|
489
|
+
context: typeof context !== 'function' && context ? context : {},
|
|
484
490
|
meta: undefined,
|
|
485
|
-
configuration:
|
|
491
|
+
configuration: actors_dist_xstateActors.getInitialConfiguration(this.root),
|
|
486
492
|
children: {}
|
|
487
493
|
}));
|
|
488
|
-
if (
|
|
489
|
-
const
|
|
490
|
-
|
|
494
|
+
if (typeof context === 'function') {
|
|
495
|
+
const assignment = ({
|
|
496
|
+
spawn,
|
|
497
|
+
event
|
|
498
|
+
}) => context({
|
|
499
|
+
spawn,
|
|
500
|
+
input: event.input
|
|
501
|
+
});
|
|
502
|
+
return actors_dist_xstateActors.resolveActionsAndContext([actors_dist_xstateActors.assign(assignment)], initEvent, preInitial, actorCtx);
|
|
491
503
|
}
|
|
492
504
|
return preInitial;
|
|
493
505
|
}
|
|
@@ -498,7 +510,7 @@ class StateMachine {
|
|
|
498
510
|
getInitialState(actorCtx, input) {
|
|
499
511
|
const initEvent = actors_dist_xstateActors.createInitEvent(input); // TODO: fix;
|
|
500
512
|
|
|
501
|
-
const preInitialState = this.getPreInitialState(actorCtx,
|
|
513
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
502
514
|
const nextState = actors_dist_xstateActors.microstep([{
|
|
503
515
|
target: [...preInitialState.configuration].filter(actors_dist_xstateActors.isAtomicStateNode),
|
|
504
516
|
source: this.root,
|
|
@@ -535,10 +547,7 @@ class StateMachine {
|
|
|
535
547
|
return actors_dist_xstateActors.getStateNodeByPath(stateNode, relativePath);
|
|
536
548
|
}
|
|
537
549
|
get definition() {
|
|
538
|
-
return
|
|
539
|
-
context: this.getContext(),
|
|
540
|
-
...this.root.definition
|
|
541
|
-
};
|
|
550
|
+
return this.root.definition;
|
|
542
551
|
}
|
|
543
552
|
toJSON() {
|
|
544
553
|
return this.definition;
|
|
@@ -742,7 +751,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
742
751
|
});
|
|
743
752
|
}
|
|
744
753
|
|
|
745
|
-
exports.
|
|
754
|
+
exports.ConstantPrefix = actors_dist_xstateActors.ConstantPrefix;
|
|
746
755
|
exports.Interpreter = actors_dist_xstateActors.Interpreter;
|
|
747
756
|
exports.InterpreterStatus = actors_dist_xstateActors.ActorStatus;
|
|
748
757
|
exports.SpecialTargets = actors_dist_xstateActors.SpecialTargets;
|
package/dist/xstate.cjs.mjs
CHANGED
|
@@ -2,10 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-40bd643f.development.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
9
|
+
const toSerializableActon = action => {
|
|
10
|
+
if (typeof action === 'string') {
|
|
11
|
+
return {
|
|
12
|
+
type: action
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (typeof action === 'function') {
|
|
16
|
+
if ('resolve' in action) {
|
|
17
|
+
return {
|
|
18
|
+
type: action.type
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
type: action.name
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return action;
|
|
26
|
+
};
|
|
9
27
|
class StateNode {
|
|
10
28
|
/**
|
|
11
29
|
* The relative key of the state node, which represents its location in the overall state value.
|
|
@@ -114,8 +132,8 @@ class StateNode {
|
|
|
114
132
|
|
|
115
133
|
// History config
|
|
116
134
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
117
|
-
this.entry = actors_dist_xstateActors.
|
|
118
|
-
this.exit = actors_dist_xstateActors.
|
|
135
|
+
this.entry = actors_dist_xstateActors.toArray(this.config.entry);
|
|
136
|
+
this.exit = actors_dist_xstateActors.toArray(this.config.exit);
|
|
119
137
|
this.meta = this.config.meta;
|
|
120
138
|
this.output = this.type === 'final' ? this.config.output : undefined;
|
|
121
139
|
this.tags = actors_dist_xstateActors.toArray(config.tags);
|
|
@@ -123,7 +141,7 @@ class StateNode {
|
|
|
123
141
|
_initialize() {
|
|
124
142
|
this.transitions = actors_dist_xstateActors.formatTransitions(this);
|
|
125
143
|
if (this.config.always) {
|
|
126
|
-
this.always = actors_dist_xstateActors.toTransitionConfigArray(
|
|
144
|
+
this.always = actors_dist_xstateActors.toTransitionConfigArray(this.config.always).map(t => actors_dist_xstateActors.formatTransition(this, actors_dist_xstateActors.NULL_EVENT, t));
|
|
127
145
|
}
|
|
128
146
|
Object.keys(this.states).forEach(key => {
|
|
129
147
|
this.states[key]._initialize();
|
|
@@ -142,13 +160,13 @@ class StateNode {
|
|
|
142
160
|
initial: this.initial ? {
|
|
143
161
|
target: this.initial.target,
|
|
144
162
|
source: this,
|
|
145
|
-
actions: this.initial.actions,
|
|
163
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
146
164
|
eventType: null,
|
|
147
165
|
reenter: false,
|
|
148
166
|
toJSON: () => ({
|
|
149
167
|
target: this.initial.target.map(t => `#${t.id}`),
|
|
150
168
|
source: `#${this.id}`,
|
|
151
|
-
actions: this.initial.actions,
|
|
169
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
152
170
|
eventType: null
|
|
153
171
|
})
|
|
154
172
|
} : undefined,
|
|
@@ -157,9 +175,12 @@ class StateNode {
|
|
|
157
175
|
return state.definition;
|
|
158
176
|
}),
|
|
159
177
|
on: this.on,
|
|
160
|
-
transitions: this.transitions
|
|
161
|
-
|
|
162
|
-
|
|
178
|
+
transitions: [...this.transitions.values()].flat().map(t => ({
|
|
179
|
+
...t,
|
|
180
|
+
actions: t.actions.map(toSerializableActon)
|
|
181
|
+
})),
|
|
182
|
+
entry: this.entry.map(toSerializableActon),
|
|
183
|
+
exit: this.exit.map(toSerializableActon),
|
|
163
184
|
meta: this.meta,
|
|
164
185
|
order: this.order || -1,
|
|
165
186
|
output: this.output,
|
|
@@ -184,7 +205,9 @@ class StateNode {
|
|
|
184
205
|
const {
|
|
185
206
|
systemId
|
|
186
207
|
} = invokeConfig;
|
|
187
|
-
|
|
208
|
+
|
|
209
|
+
// TODO: resolving should not happen here
|
|
210
|
+
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
188
211
|
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
189
212
|
this.machine.implementations.actors = {
|
|
190
213
|
...this.machine.implementations.actors,
|
|
@@ -193,7 +216,7 @@ class StateNode {
|
|
|
193
216
|
};
|
|
194
217
|
}
|
|
195
218
|
return {
|
|
196
|
-
type:
|
|
219
|
+
type: 'xstate.invoke',
|
|
197
220
|
...invokeConfig,
|
|
198
221
|
src: resolvedSrc,
|
|
199
222
|
id: resolvedId,
|
|
@@ -206,7 +229,7 @@ class StateNode {
|
|
|
206
229
|
} = invokeConfig;
|
|
207
230
|
return {
|
|
208
231
|
...invokeDefValues,
|
|
209
|
-
type:
|
|
232
|
+
type: 'xstate.invoke',
|
|
210
233
|
src: resolvedSrc,
|
|
211
234
|
id: resolvedId
|
|
212
235
|
};
|
|
@@ -221,9 +244,9 @@ class StateNode {
|
|
|
221
244
|
get on() {
|
|
222
245
|
return actors_dist_xstateActors.memo(this, 'on', () => {
|
|
223
246
|
const transitions = this.transitions;
|
|
224
|
-
return transitions.reduce((map, transition) => {
|
|
225
|
-
map[
|
|
226
|
-
map[
|
|
247
|
+
return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
|
|
248
|
+
map[descriptor] = map[descriptor] || [];
|
|
249
|
+
map[descriptor].push(transition);
|
|
227
250
|
return map;
|
|
228
251
|
}, {});
|
|
229
252
|
});
|
|
@@ -310,32 +333,15 @@ class StateNode {
|
|
|
310
333
|
* Excludes any inert events.
|
|
311
334
|
*/
|
|
312
335
|
get ownEvents() {
|
|
313
|
-
const events = new Set(this.transitions.filter(
|
|
314
|
-
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
315
|
-
})
|
|
336
|
+
const events = new Set([...this.transitions.keys()].filter(descriptor => {
|
|
337
|
+
return this.transitions.get(descriptor).some(transition => !(!transition.target && !transition.actions.length && !transition.reenter));
|
|
338
|
+
}));
|
|
316
339
|
return Array.from(events);
|
|
317
340
|
}
|
|
318
341
|
}
|
|
319
342
|
|
|
320
343
|
const STATE_IDENTIFIER = '#';
|
|
321
344
|
class StateMachine {
|
|
322
|
-
// TODO: this getter should be removed
|
|
323
|
-
getContext(input) {
|
|
324
|
-
return this.getContextAndActions(undefined, input)[0];
|
|
325
|
-
}
|
|
326
|
-
getContextAndActions(actorCtx, input) {
|
|
327
|
-
const actions = [];
|
|
328
|
-
const {
|
|
329
|
-
context
|
|
330
|
-
} = this.config;
|
|
331
|
-
const resolvedContext = typeof context === 'function' ? context({
|
|
332
|
-
spawn: actors_dist_xstateActors.createSpawner(actorCtx?.self, this, undefined,
|
|
333
|
-
// TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
|
|
334
|
-
actors_dist_xstateActors.createInitEvent(input), actions),
|
|
335
|
-
input
|
|
336
|
-
}) : context;
|
|
337
|
-
return [resolvedContext || {}, actions];
|
|
338
|
-
}
|
|
339
345
|
/**
|
|
340
346
|
* The machine's own version.
|
|
341
347
|
*/
|
|
@@ -432,10 +438,9 @@ class StateMachine {
|
|
|
432
438
|
done: actors_dist_xstateActors.isInFinalState(configuration)
|
|
433
439
|
});
|
|
434
440
|
}
|
|
435
|
-
resolveStateValue(stateValue) {
|
|
441
|
+
resolveStateValue(stateValue, ...[context]) {
|
|
436
442
|
const resolvedStateValue = actors_dist_xstateActors.resolveStateValue(this.root, stateValue);
|
|
437
|
-
|
|
438
|
-
return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, resolvedContext, this));
|
|
443
|
+
return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, context, this));
|
|
439
444
|
}
|
|
440
445
|
|
|
441
446
|
/**
|
|
@@ -474,20 +479,27 @@ class StateMachine {
|
|
|
474
479
|
* The initial state _before_ evaluating any microsteps.
|
|
475
480
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
476
481
|
*/
|
|
477
|
-
getPreInitialState(actorCtx,
|
|
478
|
-
const
|
|
479
|
-
|
|
482
|
+
getPreInitialState(actorCtx, initEvent) {
|
|
483
|
+
const {
|
|
484
|
+
context
|
|
485
|
+
} = this.config;
|
|
480
486
|
const preInitial = this.resolveState(this.createState({
|
|
481
487
|
value: {},
|
|
482
488
|
// TODO: this is computed in state constructor
|
|
483
|
-
context,
|
|
489
|
+
context: typeof context !== 'function' && context ? context : {},
|
|
484
490
|
meta: undefined,
|
|
485
|
-
configuration:
|
|
491
|
+
configuration: actors_dist_xstateActors.getInitialConfiguration(this.root),
|
|
486
492
|
children: {}
|
|
487
493
|
}));
|
|
488
|
-
if (
|
|
489
|
-
const
|
|
490
|
-
|
|
494
|
+
if (typeof context === 'function') {
|
|
495
|
+
const assignment = ({
|
|
496
|
+
spawn,
|
|
497
|
+
event
|
|
498
|
+
}) => context({
|
|
499
|
+
spawn,
|
|
500
|
+
input: event.input
|
|
501
|
+
});
|
|
502
|
+
return actors_dist_xstateActors.resolveActionsAndContext([actors_dist_xstateActors.assign(assignment)], initEvent, preInitial, actorCtx);
|
|
491
503
|
}
|
|
492
504
|
return preInitial;
|
|
493
505
|
}
|
|
@@ -498,7 +510,7 @@ class StateMachine {
|
|
|
498
510
|
getInitialState(actorCtx, input) {
|
|
499
511
|
const initEvent = actors_dist_xstateActors.createInitEvent(input); // TODO: fix;
|
|
500
512
|
|
|
501
|
-
const preInitialState = this.getPreInitialState(actorCtx,
|
|
513
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
502
514
|
const nextState = actors_dist_xstateActors.microstep([{
|
|
503
515
|
target: [...preInitialState.configuration].filter(actors_dist_xstateActors.isAtomicStateNode),
|
|
504
516
|
source: this.root,
|
|
@@ -535,10 +547,7 @@ class StateMachine {
|
|
|
535
547
|
return actors_dist_xstateActors.getStateNodeByPath(stateNode, relativePath);
|
|
536
548
|
}
|
|
537
549
|
get definition() {
|
|
538
|
-
return
|
|
539
|
-
context: this.getContext(),
|
|
540
|
-
...this.root.definition
|
|
541
|
-
};
|
|
550
|
+
return this.root.definition;
|
|
542
551
|
}
|
|
543
552
|
toJSON() {
|
|
544
553
|
return this.definition;
|
|
@@ -745,7 +754,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
745
754
|
});
|
|
746
755
|
}
|
|
747
756
|
|
|
748
|
-
exports.
|
|
757
|
+
exports.ConstantPrefix = actors_dist_xstateActors.ConstantPrefix;
|
|
749
758
|
exports.Interpreter = actors_dist_xstateActors.Interpreter;
|
|
750
759
|
exports.InterpreterStatus = actors_dist_xstateActors.ActorStatus;
|
|
751
760
|
exports.SpecialTargets = actors_dist_xstateActors.SpecialTargets;
|