xstate 4.33.2 → 4.33.5
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/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/State.d.ts +1 -1
- package/es/StateNode.js +64 -47
- package/es/actions.d.ts +1 -1
- package/es/actions.js +84 -18
- package/es/interpreter.d.ts +4 -3
- package/es/interpreter.js +33 -11
- package/es/types.d.ts +3 -3
- package/lib/State.d.ts +1 -1
- package/lib/StateNode.js +63 -46
- package/lib/actions.d.ts +1 -1
- package/lib/actions.js +82 -16
- package/lib/interpreter.d.ts +4 -3
- package/lib/interpreter.js +33 -11
- package/lib/types.d.ts +3 -3
- package/package.json +2 -2
package/es/actions.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { __assign, __read,
|
|
1
|
+
import { __assign, __spreadArray, __read, __values } from './_virtual/_tslib.js';
|
|
2
2
|
import { SpecialTargets, ActionTypes } from './types.js';
|
|
3
3
|
import { init, send as send$1, raise as raise$1, update, log as log$1, cancel as cancel$1, assign as assign$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1 } from './actionTypes.js';
|
|
4
4
|
import * as actionTypes from './actionTypes.js';
|
|
5
5
|
export { actionTypes };
|
|
6
|
-
import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType,
|
|
6
|
+
import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType, updateContext, flatten, isArray, toArray, toGuard, evaluateGuard, warn } from './utils.js';
|
|
7
7
|
import { IS_PRODUCTION } from './environment.js';
|
|
8
8
|
|
|
9
9
|
var initEvent = /*#__PURE__*/toSCXMLEvent({
|
|
@@ -426,20 +426,53 @@ function choose(conds) {
|
|
|
426
426
|
conds: conds
|
|
427
427
|
};
|
|
428
428
|
}
|
|
429
|
-
|
|
429
|
+
|
|
430
|
+
var pluckAssigns = function (actionBlocks) {
|
|
431
|
+
var e_1, _a;
|
|
432
|
+
|
|
433
|
+
var assignActions = [];
|
|
434
|
+
|
|
435
|
+
try {
|
|
436
|
+
for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
|
|
437
|
+
var block = actionBlocks_1_1.value;
|
|
438
|
+
var i = 0;
|
|
439
|
+
|
|
440
|
+
while (i < block.length) {
|
|
441
|
+
if (block[i].type === assign$1) {
|
|
442
|
+
assignActions.push(block[i]);
|
|
443
|
+
block.splice(i, 1);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
i++;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
} catch (e_1_1) {
|
|
451
|
+
e_1 = {
|
|
452
|
+
error: e_1_1
|
|
453
|
+
};
|
|
454
|
+
} finally {
|
|
455
|
+
try {
|
|
456
|
+
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
|
|
457
|
+
} finally {
|
|
458
|
+
if (e_1) throw e_1.error;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return assignActions;
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
|
|
430
466
|
if (preserveActionOrder === void 0) {
|
|
431
467
|
preserveActionOrder = false;
|
|
432
468
|
}
|
|
433
469
|
|
|
434
|
-
var
|
|
435
|
-
return action.type === assign$1;
|
|
436
|
-
}), 2),
|
|
437
|
-
assignActions = _a[0],
|
|
438
|
-
otherActions = _a[1];
|
|
439
|
-
|
|
470
|
+
var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
|
|
440
471
|
var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
|
|
441
472
|
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
|
|
442
|
-
var
|
|
473
|
+
var deferredToBlockEnd = [];
|
|
474
|
+
|
|
475
|
+
function handleAction(actionObject) {
|
|
443
476
|
var _a;
|
|
444
477
|
|
|
445
478
|
switch (actionObject.type) {
|
|
@@ -457,8 +490,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
457
490
|
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
|
|
458
491
|
}
|
|
459
492
|
|
|
460
|
-
if (sendAction.to !== SpecialTargets.Internal) {
|
|
461
|
-
|
|
493
|
+
if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
|
|
494
|
+
deferredToBlockEnd.push(sendAction);
|
|
462
495
|
}
|
|
463
496
|
|
|
464
497
|
return sendAction;
|
|
@@ -482,7 +515,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
482
515
|
return [];
|
|
483
516
|
}
|
|
484
517
|
|
|
485
|
-
var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
|
|
518
|
+
var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
|
|
486
519
|
resolvedActionsFromChoose = _b[0],
|
|
487
520
|
resolvedContextFromChoose = _b[1];
|
|
488
521
|
|
|
@@ -499,7 +532,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
499
532
|
return [];
|
|
500
533
|
}
|
|
501
534
|
|
|
502
|
-
var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
|
|
535
|
+
var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
|
|
503
536
|
resolvedActionsFromPure = _c[0],
|
|
504
537
|
resolvedContext = _c[1];
|
|
505
538
|
|
|
@@ -511,7 +544,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
511
544
|
case stop$1:
|
|
512
545
|
{
|
|
513
546
|
var resolved = resolveStop(actionObject, updatedContext, _event);
|
|
514
|
-
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved,
|
|
547
|
+
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
|
|
515
548
|
return resolved;
|
|
516
549
|
}
|
|
517
550
|
|
|
@@ -545,9 +578,42 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
|
|
|
545
578
|
|
|
546
579
|
return resolvedActionObject;
|
|
547
580
|
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function processBlock(block) {
|
|
584
|
+
var e_2, _a;
|
|
585
|
+
|
|
586
|
+
var resolvedActions = [];
|
|
587
|
+
|
|
588
|
+
try {
|
|
589
|
+
for (var block_1 = __values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
|
|
590
|
+
var action = block_1_1.value;
|
|
591
|
+
var resolved = handleAction(action);
|
|
592
|
+
|
|
593
|
+
if (resolved) {
|
|
594
|
+
resolvedActions = resolvedActions.concat(resolved);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
} catch (e_2_1) {
|
|
598
|
+
e_2 = {
|
|
599
|
+
error: e_2_1
|
|
600
|
+
};
|
|
601
|
+
} finally {
|
|
602
|
+
try {
|
|
603
|
+
if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
|
|
604
|
+
} finally {
|
|
605
|
+
if (e_2) throw e_2.error;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
deferredToBlockEnd.forEach(function (action) {
|
|
610
|
+
predictableExec(action, updatedContext, _event);
|
|
611
|
+
});
|
|
612
|
+
deferredToBlockEnd.length = 0;
|
|
613
|
+
return resolvedActions;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
var resolvedActions = flatten(actionBlocks.map(processBlock));
|
|
551
617
|
return [resolvedActions, updatedContext];
|
|
552
618
|
}
|
|
553
619
|
|
package/es/interpreter.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
73
73
|
sessionId: string;
|
|
74
74
|
children: Map<string | number, ActorRef<any>>;
|
|
75
75
|
private forwardTo;
|
|
76
|
+
private _outgoingQueue;
|
|
76
77
|
private devTools?;
|
|
77
78
|
/**
|
|
78
79
|
* Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.
|
|
@@ -128,7 +129,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
128
129
|
/**
|
|
129
130
|
* Alias for Interpreter.prototype.start
|
|
130
131
|
*/
|
|
131
|
-
init: (initialState?:
|
|
132
|
+
init: (initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue) => this;
|
|
132
133
|
/**
|
|
133
134
|
* Starts the interpreter from the given state, or the initial state.
|
|
134
135
|
* @param initialState The state to start the statechart from
|
|
@@ -151,7 +152,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
151
152
|
*
|
|
152
153
|
* @param event The event(s) to send
|
|
153
154
|
*/
|
|
154
|
-
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData
|
|
155
|
+
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData) => State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
155
156
|
private batch;
|
|
156
157
|
/**
|
|
157
158
|
* Returns a send function bound to this interpreter instance.
|
|
@@ -177,7 +178,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
177
178
|
private removeChild;
|
|
178
179
|
private stopChild;
|
|
179
180
|
spawn(entity: Spawnable, name: string, options?: SpawnOptions): ActorRef<any>;
|
|
180
|
-
spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
|
|
181
|
+
spawnMachine<TChildContext, TChildStateSchema extends StateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
|
|
181
182
|
id?: string;
|
|
182
183
|
autoForward?: boolean;
|
|
183
184
|
sync?: boolean;
|
package/es/interpreter.js
CHANGED
|
@@ -36,12 +36,12 @@ function () {
|
|
|
36
36
|
* @param options Interpreter options
|
|
37
37
|
*/
|
|
38
38
|
function Interpreter(machine, options) {
|
|
39
|
-
var _this = this;
|
|
40
|
-
|
|
41
39
|
if (options === void 0) {
|
|
42
40
|
options = Interpreter.defaultOptions;
|
|
43
41
|
}
|
|
44
42
|
|
|
43
|
+
var _this = this;
|
|
44
|
+
|
|
45
45
|
this.machine = machine;
|
|
46
46
|
this.delayedEventsMap = {};
|
|
47
47
|
this.listeners = new Set();
|
|
@@ -58,6 +58,7 @@ function () {
|
|
|
58
58
|
this.status = InterpreterStatus.NotStarted;
|
|
59
59
|
this.children = new Map();
|
|
60
60
|
this.forwardTo = new Set();
|
|
61
|
+
this._outgoingQueue = [];
|
|
61
62
|
/**
|
|
62
63
|
* Alias for Interpreter.prototype.start
|
|
63
64
|
*/
|
|
@@ -109,7 +110,7 @@ function () {
|
|
|
109
110
|
// tslint:disable-next-line:semicolon
|
|
110
111
|
};
|
|
111
112
|
|
|
112
|
-
this.sendTo = function (event, to) {
|
|
113
|
+
this.sendTo = function (event, to, immediate) {
|
|
113
114
|
var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
|
|
114
115
|
var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor(to) ? to : undefined;
|
|
115
116
|
|
|
@@ -132,14 +133,24 @@ function () {
|
|
|
132
133
|
if (_this.status !== InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
|
|
133
134
|
_this.state.done) {
|
|
134
135
|
// Send SCXML events to machines
|
|
135
|
-
|
|
136
|
+
var scxmlEvent = __assign(__assign({}, event), {
|
|
136
137
|
name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
|
|
137
138
|
origin: _this.sessionId
|
|
138
|
-
})
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (!immediate && _this.machine.config.predictableActionArguments) {
|
|
142
|
+
_this._outgoingQueue.push([target, scxmlEvent]);
|
|
143
|
+
} else {
|
|
144
|
+
target.send(scxmlEvent);
|
|
145
|
+
}
|
|
139
146
|
}
|
|
140
147
|
} else {
|
|
141
148
|
// Send normal events to other targets
|
|
142
|
-
|
|
149
|
+
if (!immediate && _this.machine.config.predictableActionArguments) {
|
|
150
|
+
_this._outgoingQueue.push([target, event.data]);
|
|
151
|
+
} else {
|
|
152
|
+
target.send(event.data);
|
|
153
|
+
}
|
|
143
154
|
}
|
|
144
155
|
};
|
|
145
156
|
|
|
@@ -183,7 +194,7 @@ function () {
|
|
|
183
194
|
return;
|
|
184
195
|
} else {
|
|
185
196
|
if (sendAction.to) {
|
|
186
|
-
_this.sendTo(sendAction._event, sendAction.to);
|
|
197
|
+
_this.sendTo(sendAction._event, sendAction.to, _event === initEvent);
|
|
187
198
|
} else {
|
|
188
199
|
_this.send(sendAction._event);
|
|
189
200
|
}
|
|
@@ -384,6 +395,12 @@ function () {
|
|
|
384
395
|
// we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
|
|
385
396
|
_event === initEvent) && this.options.execute) {
|
|
386
397
|
this.execute(this.state);
|
|
398
|
+
} else {
|
|
399
|
+
var item = void 0;
|
|
400
|
+
|
|
401
|
+
while (item = this._outgoingQueue.shift()) {
|
|
402
|
+
item[0].send(item[1]);
|
|
403
|
+
}
|
|
387
404
|
} // Update children
|
|
388
405
|
|
|
389
406
|
|
|
@@ -781,7 +798,7 @@ function () {
|
|
|
781
798
|
return toActionObjects(stateNode.onExit, _this.machine.options.actions);
|
|
782
799
|
}));
|
|
783
800
|
|
|
784
|
-
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, exitActions, _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
|
|
801
|
+
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [exitActions], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
|
|
785
802
|
resolvedActions = _a[0],
|
|
786
803
|
updatedContext = _a[1];
|
|
787
804
|
|
|
@@ -830,6 +847,11 @@ function () {
|
|
|
830
847
|
"".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."));
|
|
831
848
|
}
|
|
832
849
|
|
|
850
|
+
if (!events.length) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
var exec = !!this.machine.config.predictableActionArguments && this._exec;
|
|
833
855
|
this.scheduler.schedule(function () {
|
|
834
856
|
var e_11, _a;
|
|
835
857
|
|
|
@@ -843,9 +865,9 @@ function () {
|
|
|
843
865
|
_this.forward(_event);
|
|
844
866
|
|
|
845
867
|
nextState = provide(_this, function () {
|
|
846
|
-
return _this.machine.transition(nextState, _event);
|
|
868
|
+
return _this.machine.transition(nextState, _event, undefined, exec || undefined);
|
|
847
869
|
});
|
|
848
|
-
batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
|
|
870
|
+
batchedActions.push.apply(batchedActions, __spreadArray([], __read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
|
|
849
871
|
return bindActionToState(a, nextState);
|
|
850
872
|
})), false));
|
|
851
873
|
batchChanged = batchChanged || !!nextState.changed;
|
|
@@ -951,7 +973,7 @@ function () {
|
|
|
951
973
|
|
|
952
974
|
this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
|
|
953
975
|
if (sendAction.to) {
|
|
954
|
-
_this.sendTo(sendAction._event, sendAction.to);
|
|
976
|
+
_this.sendTo(sendAction._event, sendAction.to, true);
|
|
955
977
|
} else {
|
|
956
978
|
_this.send(sendAction._event);
|
|
957
979
|
}
|
package/es/types.d.ts
CHANGED
|
@@ -228,13 +228,13 @@ export declare type DelayedTransitions<TContext, TEvent extends EventObject> = R
|
|
|
228
228
|
export declare type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | string;
|
|
229
229
|
export declare type SingleOrArray<T> = T[] | T;
|
|
230
230
|
export declare type StateNodesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
|
|
231
|
-
[K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K], TEvent>;
|
|
231
|
+
[K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K] & {}, TEvent>;
|
|
232
232
|
};
|
|
233
233
|
export declare type StatesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
|
|
234
|
-
[K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K], TEvent, TAction>;
|
|
234
|
+
[K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K] & {}, TEvent, TAction>;
|
|
235
235
|
};
|
|
236
236
|
export declare type StatesDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
|
|
237
|
-
[K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K], TEvent>;
|
|
237
|
+
[K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K] & {}, TEvent>;
|
|
238
238
|
};
|
|
239
239
|
export declare type TransitionConfigTarget<TContext, TEvent extends EventObject> = string | undefined | StateNode<TContext, any, TEvent>;
|
|
240
240
|
export declare type TransitionConfigOrTarget<TContext, TEvent extends EventObject> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TEvent>>;
|
package/lib/State.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
91
91
|
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
92
92
|
*/
|
|
93
93
|
toStrings(stateValue?: StateValue, delimiter?: string): string[];
|
|
94
|
-
toJSON(): Omit<this, "machine" | "configuration" | "transitions" | "tags"> & {
|
|
94
|
+
toJSON(): Omit<this, "machine" | "configuration" | "transitions" | "tags" | "toStrings" | "toJSON" | "matches" | "hasTag" | "can"> & {
|
|
95
95
|
tags: string[];
|
|
96
96
|
};
|
|
97
97
|
/**
|
package/lib/StateNode.js
CHANGED
|
@@ -56,12 +56,12 @@ function () {
|
|
|
56
56
|
*/
|
|
57
57
|
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
|
|
58
58
|
_stateInfo) {
|
|
59
|
-
var _this = this;
|
|
60
|
-
|
|
61
59
|
if (_context === void 0) {
|
|
62
60
|
_context = 'context' in config ? config.context : undefined;
|
|
63
61
|
}
|
|
64
62
|
|
|
63
|
+
var _this = this;
|
|
64
|
+
|
|
65
65
|
var _a;
|
|
66
66
|
|
|
67
67
|
this.config = config;
|
|
@@ -671,9 +671,11 @@ function () {
|
|
|
671
671
|
return nodes;
|
|
672
672
|
};
|
|
673
673
|
|
|
674
|
-
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
|
|
674
|
+
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
|
|
675
675
|
var e_4, _a, e_5, _b;
|
|
676
676
|
|
|
677
|
+
var _this = this;
|
|
678
|
+
|
|
677
679
|
var prevConfig = stateUtils.getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
|
|
678
680
|
|
|
679
681
|
try {
|
|
@@ -751,20 +753,19 @@ function () {
|
|
|
751
753
|
});
|
|
752
754
|
var entryStates = new Set(transition.entrySet);
|
|
753
755
|
var exitStates = new Set(transition.exitSet);
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
756
|
+
var entryActions = Array.from(entryStates).map(function (stateNode) {
|
|
757
|
+
var entryActions = stateNode.onEntry;
|
|
758
|
+
var invokeActions = stateNode.activities.map(function (activity) {
|
|
757
759
|
return actions.start(activity);
|
|
758
|
-
})
|
|
759
|
-
|
|
760
|
-
|
|
760
|
+
});
|
|
761
|
+
return actions.toActionObjects(predictableExec ? _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(entryActions), false), _tslib.__read(invokeActions), false) : _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(invokeActions), false), _tslib.__read(entryActions), false), _this.machine.options.actions);
|
|
762
|
+
}).concat([doneEvents.map(actions.raise)]);
|
|
763
|
+
var exitActions = Array.from(exitStates).map(function (stateNode) {
|
|
764
|
+
return actions.toActionObjects(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
|
|
761
765
|
return actions.stop(activity);
|
|
762
|
-
})), false);
|
|
763
|
-
})
|
|
764
|
-
|
|
765
|
-
exitActions = _c[1];
|
|
766
|
-
|
|
767
|
-
var actions$1 = actions.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
|
|
766
|
+
})), false), _this.machine.options.actions);
|
|
767
|
+
});
|
|
768
|
+
var actions$1 = exitActions.concat([actions.toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
|
|
768
769
|
|
|
769
770
|
if (isDone) {
|
|
770
771
|
var stopActions = actions.toActionObjects(utils.flatten(_tslib.__spreadArray([], _tslib.__read(resolvedConfig), false).sort(function (a, b) {
|
|
@@ -774,7 +775,7 @@ function () {
|
|
|
774
775
|
})), this.machine.options.actions).filter(function (action) {
|
|
775
776
|
return action.type !== actionTypes.raise && (action.type !== actionTypes.send || !!action.to && action.to !== types.SpecialTargets.Internal);
|
|
776
777
|
});
|
|
777
|
-
return actions$1.concat(stopActions);
|
|
778
|
+
return actions$1.concat([stopActions]);
|
|
778
779
|
}
|
|
779
780
|
|
|
780
781
|
return actions$1;
|
|
@@ -845,7 +846,7 @@ function () {
|
|
|
845
846
|
};
|
|
846
847
|
|
|
847
848
|
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
|
|
848
|
-
var e_6, _a;
|
|
849
|
+
var e_6, _a, e_7, _b;
|
|
849
850
|
|
|
850
851
|
var _this = this;
|
|
851
852
|
|
|
@@ -862,17 +863,33 @@ function () {
|
|
|
862
863
|
var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
|
|
863
864
|
var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
|
|
864
865
|
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
|
|
865
|
-
var
|
|
866
|
+
var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
|
|
866
867
|
var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
|
|
867
868
|
|
|
868
869
|
try {
|
|
869
|
-
for (var
|
|
870
|
-
var
|
|
870
|
+
for (var actionBlocks_1 = _tslib.__values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
|
|
871
|
+
var block = actionBlocks_1_1.value;
|
|
871
872
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
873
|
+
try {
|
|
874
|
+
for (var block_1 = (e_7 = void 0, _tslib.__values(block)), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
|
|
875
|
+
var action = block_1_1.value;
|
|
876
|
+
|
|
877
|
+
if (action.type === actionTypes.start) {
|
|
878
|
+
activities[action.activity.id || action.activity.type] = action;
|
|
879
|
+
} else if (action.type === actionTypes.stop) {
|
|
880
|
+
activities[action.activity.id || action.activity.type] = false;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
} catch (e_7_1) {
|
|
884
|
+
e_7 = {
|
|
885
|
+
error: e_7_1
|
|
886
|
+
};
|
|
887
|
+
} finally {
|
|
888
|
+
try {
|
|
889
|
+
if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
|
|
890
|
+
} finally {
|
|
891
|
+
if (e_7) throw e_7.error;
|
|
892
|
+
}
|
|
876
893
|
}
|
|
877
894
|
}
|
|
878
895
|
} catch (e_6_1) {
|
|
@@ -881,21 +898,21 @@ function () {
|
|
|
881
898
|
};
|
|
882
899
|
} finally {
|
|
883
900
|
try {
|
|
884
|
-
if (
|
|
901
|
+
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
|
|
885
902
|
} finally {
|
|
886
903
|
if (e_6) throw e_6.error;
|
|
887
904
|
}
|
|
888
905
|
}
|
|
889
906
|
|
|
890
|
-
var
|
|
891
|
-
resolvedActions =
|
|
892
|
-
updatedContext =
|
|
907
|
+
var _c = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
|
|
908
|
+
resolvedActions = _c[0],
|
|
909
|
+
updatedContext = _c[1];
|
|
893
910
|
|
|
894
|
-
var
|
|
911
|
+
var _d = _tslib.__read(utils.partition(resolvedActions, function (action) {
|
|
895
912
|
return action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal;
|
|
896
913
|
}), 2),
|
|
897
|
-
raisedEvents =
|
|
898
|
-
nonRaisedActions =
|
|
914
|
+
raisedEvents = _d[0],
|
|
915
|
+
nonRaisedActions = _d[1];
|
|
899
916
|
|
|
900
917
|
var invokeActions = resolvedActions.filter(function (action) {
|
|
901
918
|
var _a;
|
|
@@ -1344,7 +1361,7 @@ function () {
|
|
|
1344
1361
|
* All the event types accepted by this state node and its descendants.
|
|
1345
1362
|
*/
|
|
1346
1363
|
get: function () {
|
|
1347
|
-
var
|
|
1364
|
+
var e_8, _a, e_9, _b;
|
|
1348
1365
|
|
|
1349
1366
|
if (this.__cache.events) {
|
|
1350
1367
|
return this.__cache.events;
|
|
@@ -1361,32 +1378,32 @@ function () {
|
|
|
1361
1378
|
|
|
1362
1379
|
if (state.states) {
|
|
1363
1380
|
try {
|
|
1364
|
-
for (var _e = (
|
|
1381
|
+
for (var _e = (e_9 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1365
1382
|
var event_1 = _f.value;
|
|
1366
1383
|
events.add("".concat(event_1));
|
|
1367
1384
|
}
|
|
1368
|
-
} catch (
|
|
1369
|
-
|
|
1370
|
-
error:
|
|
1385
|
+
} catch (e_9_1) {
|
|
1386
|
+
e_9 = {
|
|
1387
|
+
error: e_9_1
|
|
1371
1388
|
};
|
|
1372
1389
|
} finally {
|
|
1373
1390
|
try {
|
|
1374
1391
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1375
1392
|
} finally {
|
|
1376
|
-
if (
|
|
1393
|
+
if (e_9) throw e_9.error;
|
|
1377
1394
|
}
|
|
1378
1395
|
}
|
|
1379
1396
|
}
|
|
1380
1397
|
}
|
|
1381
|
-
} catch (
|
|
1382
|
-
|
|
1383
|
-
error:
|
|
1398
|
+
} catch (e_8_1) {
|
|
1399
|
+
e_8 = {
|
|
1400
|
+
error: e_8_1
|
|
1384
1401
|
};
|
|
1385
1402
|
} finally {
|
|
1386
1403
|
try {
|
|
1387
1404
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1388
1405
|
} finally {
|
|
1389
|
-
if (
|
|
1406
|
+
if (e_8) throw e_8.error;
|
|
1390
1407
|
}
|
|
1391
1408
|
}
|
|
1392
1409
|
}
|
|
@@ -1481,7 +1498,7 @@ function () {
|
|
|
1481
1498
|
};
|
|
1482
1499
|
|
|
1483
1500
|
StateNode.prototype.formatTransitions = function () {
|
|
1484
|
-
var
|
|
1501
|
+
var e_10, _a;
|
|
1485
1502
|
|
|
1486
1503
|
var _this = this;
|
|
1487
1504
|
|
|
@@ -1545,15 +1562,15 @@ function () {
|
|
|
1545
1562
|
var delayedTransition = delayedTransitions_1_1.value;
|
|
1546
1563
|
formattedTransitions.push(delayedTransition);
|
|
1547
1564
|
}
|
|
1548
|
-
} catch (
|
|
1549
|
-
|
|
1550
|
-
error:
|
|
1565
|
+
} catch (e_10_1) {
|
|
1566
|
+
e_10 = {
|
|
1567
|
+
error: e_10_1
|
|
1551
1568
|
};
|
|
1552
1569
|
} finally {
|
|
1553
1570
|
try {
|
|
1554
1571
|
if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
|
|
1555
1572
|
} finally {
|
|
1556
|
-
if (
|
|
1573
|
+
if (e_10) throw e_10.error;
|
|
1557
1574
|
}
|
|
1558
1575
|
}
|
|
1559
1576
|
|
package/lib/actions.d.ts
CHANGED
|
@@ -150,5 +150,5 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
150
150
|
*/
|
|
151
151
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
152
152
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
153
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>,
|
|
153
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<Array<ActionObject<TContext, TEvent>>>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
154
154
|
//# sourceMappingURL=actions.d.ts.map
|