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
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, m as mapValues, t as
|
|
2
|
-
export {
|
|
1
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as macrostep, u as transitionNode, v as getInitialConfiguration, w as resolveActionsAndContext, x as assign, y as createInitEvent, z as microstep, A as isAtomicStateNode, B as error, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as interpret, H as matchesState } from './actions-13190b25.development.esm.js';
|
|
2
|
+
export { a5 as ConstantPrefix, L as Interpreter, M as InterpreterStatus, a6 as SpecialTargets, p as State, a3 as and, x as assign, P as cancel, Q as choose, O as doneInvoke, K as forwardTo, _ as fromCallback, $ as fromEventObservable, Z as fromObservable, Y as fromPromise, a0 as fromTransition, n as getStateNodes, G as interpret, R as log, H as matchesState, a2 as not, a4 as or, W as pathToStateValue, T as pure, U as raise, J as sendParent, I as sendTo, a1 as stateIn, V as stop, X as toObserver } from './actions-13190b25.development.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
6
|
+
const toSerializableActon = action => {
|
|
7
|
+
if (typeof action === 'string') {
|
|
8
|
+
return {
|
|
9
|
+
type: action
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof action === 'function') {
|
|
13
|
+
if ('resolve' in action) {
|
|
14
|
+
return {
|
|
15
|
+
type: action.type
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: action.name
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return action;
|
|
23
|
+
};
|
|
6
24
|
class StateNode {
|
|
7
25
|
/**
|
|
8
26
|
* The relative key of the state node, which represents its location in the overall state value.
|
|
@@ -111,8 +129,8 @@ class StateNode {
|
|
|
111
129
|
|
|
112
130
|
// History config
|
|
113
131
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
114
|
-
this.entry =
|
|
115
|
-
this.exit =
|
|
132
|
+
this.entry = toArray(this.config.entry);
|
|
133
|
+
this.exit = toArray(this.config.exit);
|
|
116
134
|
this.meta = this.config.meta;
|
|
117
135
|
this.output = this.type === 'final' ? this.config.output : undefined;
|
|
118
136
|
this.tags = toArray(config.tags);
|
|
@@ -120,7 +138,7 @@ class StateNode {
|
|
|
120
138
|
_initialize() {
|
|
121
139
|
this.transitions = formatTransitions(this);
|
|
122
140
|
if (this.config.always) {
|
|
123
|
-
this.always = toTransitionConfigArray(
|
|
141
|
+
this.always = toTransitionConfigArray(this.config.always).map(t => formatTransition(this, NULL_EVENT, t));
|
|
124
142
|
}
|
|
125
143
|
Object.keys(this.states).forEach(key => {
|
|
126
144
|
this.states[key]._initialize();
|
|
@@ -139,13 +157,13 @@ class StateNode {
|
|
|
139
157
|
initial: this.initial ? {
|
|
140
158
|
target: this.initial.target,
|
|
141
159
|
source: this,
|
|
142
|
-
actions: this.initial.actions,
|
|
160
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
143
161
|
eventType: null,
|
|
144
162
|
reenter: false,
|
|
145
163
|
toJSON: () => ({
|
|
146
164
|
target: this.initial.target.map(t => `#${t.id}`),
|
|
147
165
|
source: `#${this.id}`,
|
|
148
|
-
actions: this.initial.actions,
|
|
166
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
149
167
|
eventType: null
|
|
150
168
|
})
|
|
151
169
|
} : undefined,
|
|
@@ -154,9 +172,12 @@ class StateNode {
|
|
|
154
172
|
return state.definition;
|
|
155
173
|
}),
|
|
156
174
|
on: this.on,
|
|
157
|
-
transitions: this.transitions
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
transitions: [...this.transitions.values()].flat().map(t => ({
|
|
176
|
+
...t,
|
|
177
|
+
actions: t.actions.map(toSerializableActon)
|
|
178
|
+
})),
|
|
179
|
+
entry: this.entry.map(toSerializableActon),
|
|
180
|
+
exit: this.exit.map(toSerializableActon),
|
|
160
181
|
meta: this.meta,
|
|
161
182
|
order: this.order || -1,
|
|
162
183
|
output: this.output,
|
|
@@ -181,7 +202,9 @@ class StateNode {
|
|
|
181
202
|
const {
|
|
182
203
|
systemId
|
|
183
204
|
} = invokeConfig;
|
|
184
|
-
|
|
205
|
+
|
|
206
|
+
// TODO: resolving should not happen here
|
|
207
|
+
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
185
208
|
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
186
209
|
this.machine.implementations.actors = {
|
|
187
210
|
...this.machine.implementations.actors,
|
|
@@ -190,7 +213,7 @@ class StateNode {
|
|
|
190
213
|
};
|
|
191
214
|
}
|
|
192
215
|
return {
|
|
193
|
-
type: invoke,
|
|
216
|
+
type: 'xstate.invoke',
|
|
194
217
|
...invokeConfig,
|
|
195
218
|
src: resolvedSrc,
|
|
196
219
|
id: resolvedId,
|
|
@@ -203,7 +226,7 @@ class StateNode {
|
|
|
203
226
|
} = invokeConfig;
|
|
204
227
|
return {
|
|
205
228
|
...invokeDefValues,
|
|
206
|
-
type: invoke,
|
|
229
|
+
type: 'xstate.invoke',
|
|
207
230
|
src: resolvedSrc,
|
|
208
231
|
id: resolvedId
|
|
209
232
|
};
|
|
@@ -218,9 +241,9 @@ class StateNode {
|
|
|
218
241
|
get on() {
|
|
219
242
|
return memo(this, 'on', () => {
|
|
220
243
|
const transitions = this.transitions;
|
|
221
|
-
return transitions.reduce((map, transition) => {
|
|
222
|
-
map[
|
|
223
|
-
map[
|
|
244
|
+
return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
|
|
245
|
+
map[descriptor] = map[descriptor] || [];
|
|
246
|
+
map[descriptor].push(transition);
|
|
224
247
|
return map;
|
|
225
248
|
}, {});
|
|
226
249
|
});
|
|
@@ -307,32 +330,15 @@ class StateNode {
|
|
|
307
330
|
* Excludes any inert events.
|
|
308
331
|
*/
|
|
309
332
|
get ownEvents() {
|
|
310
|
-
const events = new Set(this.transitions.filter(
|
|
311
|
-
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
312
|
-
})
|
|
333
|
+
const events = new Set([...this.transitions.keys()].filter(descriptor => {
|
|
334
|
+
return this.transitions.get(descriptor).some(transition => !(!transition.target && !transition.actions.length && !transition.reenter));
|
|
335
|
+
}));
|
|
313
336
|
return Array.from(events);
|
|
314
337
|
}
|
|
315
338
|
}
|
|
316
339
|
|
|
317
340
|
const STATE_IDENTIFIER = '#';
|
|
318
341
|
class StateMachine {
|
|
319
|
-
// TODO: this getter should be removed
|
|
320
|
-
getContext(input) {
|
|
321
|
-
return this.getContextAndActions(undefined, input)[0];
|
|
322
|
-
}
|
|
323
|
-
getContextAndActions(actorCtx, input) {
|
|
324
|
-
const actions = [];
|
|
325
|
-
const {
|
|
326
|
-
context
|
|
327
|
-
} = this.config;
|
|
328
|
-
const resolvedContext = typeof context === 'function' ? context({
|
|
329
|
-
spawn: createSpawner(actorCtx?.self, this, undefined,
|
|
330
|
-
// TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
|
|
331
|
-
createInitEvent(input), actions),
|
|
332
|
-
input
|
|
333
|
-
}) : context;
|
|
334
|
-
return [resolvedContext || {}, actions];
|
|
335
|
-
}
|
|
336
342
|
/**
|
|
337
343
|
* The machine's own version.
|
|
338
344
|
*/
|
|
@@ -429,10 +435,9 @@ class StateMachine {
|
|
|
429
435
|
done: isInFinalState(configuration)
|
|
430
436
|
});
|
|
431
437
|
}
|
|
432
|
-
resolveStateValue(stateValue) {
|
|
438
|
+
resolveStateValue(stateValue, ...[context]) {
|
|
433
439
|
const resolvedStateValue = resolveStateValue(this.root, stateValue);
|
|
434
|
-
|
|
435
|
-
return this.resolveState(State.from(resolvedStateValue, resolvedContext, this));
|
|
440
|
+
return this.resolveState(State.from(resolvedStateValue, context, this));
|
|
436
441
|
}
|
|
437
442
|
|
|
438
443
|
/**
|
|
@@ -471,20 +476,27 @@ class StateMachine {
|
|
|
471
476
|
* The initial state _before_ evaluating any microsteps.
|
|
472
477
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
473
478
|
*/
|
|
474
|
-
getPreInitialState(actorCtx,
|
|
475
|
-
const
|
|
476
|
-
|
|
479
|
+
getPreInitialState(actorCtx, initEvent) {
|
|
480
|
+
const {
|
|
481
|
+
context
|
|
482
|
+
} = this.config;
|
|
477
483
|
const preInitial = this.resolveState(this.createState({
|
|
478
484
|
value: {},
|
|
479
485
|
// TODO: this is computed in state constructor
|
|
480
|
-
context,
|
|
486
|
+
context: typeof context !== 'function' && context ? context : {},
|
|
481
487
|
meta: undefined,
|
|
482
|
-
configuration:
|
|
488
|
+
configuration: getInitialConfiguration(this.root),
|
|
483
489
|
children: {}
|
|
484
490
|
}));
|
|
485
|
-
if (
|
|
486
|
-
const
|
|
487
|
-
|
|
491
|
+
if (typeof context === 'function') {
|
|
492
|
+
const assignment = ({
|
|
493
|
+
spawn,
|
|
494
|
+
event
|
|
495
|
+
}) => context({
|
|
496
|
+
spawn,
|
|
497
|
+
input: event.input
|
|
498
|
+
});
|
|
499
|
+
return resolveActionsAndContext([assign(assignment)], initEvent, preInitial, actorCtx);
|
|
488
500
|
}
|
|
489
501
|
return preInitial;
|
|
490
502
|
}
|
|
@@ -495,7 +507,7 @@ class StateMachine {
|
|
|
495
507
|
getInitialState(actorCtx, input) {
|
|
496
508
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
497
509
|
|
|
498
|
-
const preInitialState = this.getPreInitialState(actorCtx,
|
|
510
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
499
511
|
const nextState = microstep([{
|
|
500
512
|
target: [...preInitialState.configuration].filter(isAtomicStateNode),
|
|
501
513
|
source: this.root,
|
|
@@ -532,10 +544,7 @@ class StateMachine {
|
|
|
532
544
|
return getStateNodeByPath(stateNode, relativePath);
|
|
533
545
|
}
|
|
534
546
|
get definition() {
|
|
535
|
-
return
|
|
536
|
-
context: this.getContext(),
|
|
537
|
-
...this.root.definition
|
|
538
|
-
};
|
|
547
|
+
return this.root.definition;
|
|
539
548
|
}
|
|
540
549
|
toJSON() {
|
|
541
550
|
return this.definition;
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, m as mapValues, t as
|
|
2
|
-
export {
|
|
1
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as macrostep, u as transitionNode, v as getInitialConfiguration, w as resolveActionsAndContext, x as assign, y as createInitEvent, z as microstep, A as isAtomicStateNode, B as error, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as interpret, H as matchesState } from './actions-4d6514d2.esm.js';
|
|
2
|
+
export { a5 as ConstantPrefix, L as Interpreter, M as InterpreterStatus, a6 as SpecialTargets, p as State, a3 as and, x as assign, P as cancel, Q as choose, O as doneInvoke, K as forwardTo, _ as fromCallback, $ as fromEventObservable, Z as fromObservable, Y as fromPromise, a0 as fromTransition, n as getStateNodes, G as interpret, R as log, H as matchesState, a2 as not, a4 as or, W as pathToStateValue, T as pure, U as raise, J as sendParent, I as sendTo, a1 as stateIn, V as stop, X as toObserver } from './actions-4d6514d2.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
6
|
+
const toSerializableActon = action => {
|
|
7
|
+
if (typeof action === 'string') {
|
|
8
|
+
return {
|
|
9
|
+
type: action
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof action === 'function') {
|
|
13
|
+
if ('resolve' in action) {
|
|
14
|
+
return {
|
|
15
|
+
type: action.type
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: action.name
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return action;
|
|
23
|
+
};
|
|
6
24
|
class StateNode {
|
|
7
25
|
/**
|
|
8
26
|
* The relative key of the state node, which represents its location in the overall state value.
|
|
@@ -111,8 +129,8 @@ class StateNode {
|
|
|
111
129
|
|
|
112
130
|
// History config
|
|
113
131
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
114
|
-
this.entry =
|
|
115
|
-
this.exit =
|
|
132
|
+
this.entry = toArray(this.config.entry);
|
|
133
|
+
this.exit = toArray(this.config.exit);
|
|
116
134
|
this.meta = this.config.meta;
|
|
117
135
|
this.output = this.type === 'final' ? this.config.output : undefined;
|
|
118
136
|
this.tags = toArray(config.tags);
|
|
@@ -120,7 +138,7 @@ class StateNode {
|
|
|
120
138
|
_initialize() {
|
|
121
139
|
this.transitions = formatTransitions(this);
|
|
122
140
|
if (this.config.always) {
|
|
123
|
-
this.always = toTransitionConfigArray(
|
|
141
|
+
this.always = toTransitionConfigArray(this.config.always).map(t => formatTransition(this, NULL_EVENT, t));
|
|
124
142
|
}
|
|
125
143
|
Object.keys(this.states).forEach(key => {
|
|
126
144
|
this.states[key]._initialize();
|
|
@@ -139,13 +157,13 @@ class StateNode {
|
|
|
139
157
|
initial: this.initial ? {
|
|
140
158
|
target: this.initial.target,
|
|
141
159
|
source: this,
|
|
142
|
-
actions: this.initial.actions,
|
|
160
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
143
161
|
eventType: null,
|
|
144
162
|
reenter: false,
|
|
145
163
|
toJSON: () => ({
|
|
146
164
|
target: this.initial.target.map(t => `#${t.id}`),
|
|
147
165
|
source: `#${this.id}`,
|
|
148
|
-
actions: this.initial.actions,
|
|
166
|
+
actions: this.initial.actions.map(toSerializableActon),
|
|
149
167
|
eventType: null
|
|
150
168
|
})
|
|
151
169
|
} : undefined,
|
|
@@ -154,9 +172,12 @@ class StateNode {
|
|
|
154
172
|
return state.definition;
|
|
155
173
|
}),
|
|
156
174
|
on: this.on,
|
|
157
|
-
transitions: this.transitions
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
transitions: [...this.transitions.values()].flat().map(t => ({
|
|
176
|
+
...t,
|
|
177
|
+
actions: t.actions.map(toSerializableActon)
|
|
178
|
+
})),
|
|
179
|
+
entry: this.entry.map(toSerializableActon),
|
|
180
|
+
exit: this.exit.map(toSerializableActon),
|
|
160
181
|
meta: this.meta,
|
|
161
182
|
order: this.order || -1,
|
|
162
183
|
output: this.output,
|
|
@@ -181,7 +202,9 @@ class StateNode {
|
|
|
181
202
|
const {
|
|
182
203
|
systemId
|
|
183
204
|
} = invokeConfig;
|
|
184
|
-
|
|
205
|
+
|
|
206
|
+
// TODO: resolving should not happen here
|
|
207
|
+
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
185
208
|
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
186
209
|
this.machine.implementations.actors = {
|
|
187
210
|
...this.machine.implementations.actors,
|
|
@@ -190,7 +213,7 @@ class StateNode {
|
|
|
190
213
|
};
|
|
191
214
|
}
|
|
192
215
|
return {
|
|
193
|
-
type: invoke,
|
|
216
|
+
type: 'xstate.invoke',
|
|
194
217
|
...invokeConfig,
|
|
195
218
|
src: resolvedSrc,
|
|
196
219
|
id: resolvedId,
|
|
@@ -203,7 +226,7 @@ class StateNode {
|
|
|
203
226
|
} = invokeConfig;
|
|
204
227
|
return {
|
|
205
228
|
...invokeDefValues,
|
|
206
|
-
type: invoke,
|
|
229
|
+
type: 'xstate.invoke',
|
|
207
230
|
src: resolvedSrc,
|
|
208
231
|
id: resolvedId
|
|
209
232
|
};
|
|
@@ -218,9 +241,9 @@ class StateNode {
|
|
|
218
241
|
get on() {
|
|
219
242
|
return memo(this, 'on', () => {
|
|
220
243
|
const transitions = this.transitions;
|
|
221
|
-
return transitions.reduce((map, transition) => {
|
|
222
|
-
map[
|
|
223
|
-
map[
|
|
244
|
+
return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
|
|
245
|
+
map[descriptor] = map[descriptor] || [];
|
|
246
|
+
map[descriptor].push(transition);
|
|
224
247
|
return map;
|
|
225
248
|
}, {});
|
|
226
249
|
});
|
|
@@ -307,32 +330,15 @@ class StateNode {
|
|
|
307
330
|
* Excludes any inert events.
|
|
308
331
|
*/
|
|
309
332
|
get ownEvents() {
|
|
310
|
-
const events = new Set(this.transitions.filter(
|
|
311
|
-
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
312
|
-
})
|
|
333
|
+
const events = new Set([...this.transitions.keys()].filter(descriptor => {
|
|
334
|
+
return this.transitions.get(descriptor).some(transition => !(!transition.target && !transition.actions.length && !transition.reenter));
|
|
335
|
+
}));
|
|
313
336
|
return Array.from(events);
|
|
314
337
|
}
|
|
315
338
|
}
|
|
316
339
|
|
|
317
340
|
const STATE_IDENTIFIER = '#';
|
|
318
341
|
class StateMachine {
|
|
319
|
-
// TODO: this getter should be removed
|
|
320
|
-
getContext(input) {
|
|
321
|
-
return this.getContextAndActions(undefined, input)[0];
|
|
322
|
-
}
|
|
323
|
-
getContextAndActions(actorCtx, input) {
|
|
324
|
-
const actions = [];
|
|
325
|
-
const {
|
|
326
|
-
context
|
|
327
|
-
} = this.config;
|
|
328
|
-
const resolvedContext = typeof context === 'function' ? context({
|
|
329
|
-
spawn: createSpawner(actorCtx?.self, this, undefined,
|
|
330
|
-
// TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
|
|
331
|
-
createInitEvent(input), actions),
|
|
332
|
-
input
|
|
333
|
-
}) : context;
|
|
334
|
-
return [resolvedContext || {}, actions];
|
|
335
|
-
}
|
|
336
342
|
/**
|
|
337
343
|
* The machine's own version.
|
|
338
344
|
*/
|
|
@@ -429,10 +435,9 @@ class StateMachine {
|
|
|
429
435
|
done: isInFinalState(configuration)
|
|
430
436
|
});
|
|
431
437
|
}
|
|
432
|
-
resolveStateValue(stateValue) {
|
|
438
|
+
resolveStateValue(stateValue, ...[context]) {
|
|
433
439
|
const resolvedStateValue = resolveStateValue(this.root, stateValue);
|
|
434
|
-
|
|
435
|
-
return this.resolveState(State.from(resolvedStateValue, resolvedContext, this));
|
|
440
|
+
return this.resolveState(State.from(resolvedStateValue, context, this));
|
|
436
441
|
}
|
|
437
442
|
|
|
438
443
|
/**
|
|
@@ -471,20 +476,27 @@ class StateMachine {
|
|
|
471
476
|
* The initial state _before_ evaluating any microsteps.
|
|
472
477
|
* This "pre-initial" state is provided to initial actions executed in the initial state.
|
|
473
478
|
*/
|
|
474
|
-
getPreInitialState(actorCtx,
|
|
475
|
-
const
|
|
476
|
-
|
|
479
|
+
getPreInitialState(actorCtx, initEvent) {
|
|
480
|
+
const {
|
|
481
|
+
context
|
|
482
|
+
} = this.config;
|
|
477
483
|
const preInitial = this.resolveState(this.createState({
|
|
478
484
|
value: {},
|
|
479
485
|
// TODO: this is computed in state constructor
|
|
480
|
-
context,
|
|
486
|
+
context: typeof context !== 'function' && context ? context : {},
|
|
481
487
|
meta: undefined,
|
|
482
|
-
configuration:
|
|
488
|
+
configuration: getInitialConfiguration(this.root),
|
|
483
489
|
children: {}
|
|
484
490
|
}));
|
|
485
|
-
if (
|
|
486
|
-
const
|
|
487
|
-
|
|
491
|
+
if (typeof context === 'function') {
|
|
492
|
+
const assignment = ({
|
|
493
|
+
spawn,
|
|
494
|
+
event
|
|
495
|
+
}) => context({
|
|
496
|
+
spawn,
|
|
497
|
+
input: event.input
|
|
498
|
+
});
|
|
499
|
+
return resolveActionsAndContext([assign(assignment)], initEvent, preInitial, actorCtx);
|
|
488
500
|
}
|
|
489
501
|
return preInitial;
|
|
490
502
|
}
|
|
@@ -495,7 +507,7 @@ class StateMachine {
|
|
|
495
507
|
getInitialState(actorCtx, input) {
|
|
496
508
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
497
509
|
|
|
498
|
-
const preInitialState = this.getPreInitialState(actorCtx,
|
|
510
|
+
const preInitialState = this.getPreInitialState(actorCtx, initEvent);
|
|
499
511
|
const nextState = microstep([{
|
|
500
512
|
target: [...preInitialState.configuration].filter(isAtomicStateNode),
|
|
501
513
|
source: this.root,
|
|
@@ -532,10 +544,7 @@ class StateMachine {
|
|
|
532
544
|
return getStateNodeByPath(stateNode, relativePath);
|
|
533
545
|
}
|
|
534
546
|
get definition() {
|
|
535
|
-
return
|
|
536
|
-
context: this.getContext(),
|
|
537
|
-
...this.root.definition
|
|
538
|
-
};
|
|
547
|
+
return this.root.definition;
|
|
539
548
|
}
|
|
540
549
|
toJSON() {
|
|
541
550
|
return this.definition;
|