xstate 5.0.0-beta.31 → 5.0.0-beta.33
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 +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- 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 +29 -18
- package/actors/dist/xstate-actors.development.cjs.js +29 -18
- package/actors/dist/xstate-actors.development.esm.js +29 -18
- package/actors/dist/xstate-actors.esm.js +29 -18
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/system.d.ts +22 -0
- package/dist/declarations/src/types.d.ts +4 -5
- package/dist/declarations/src/utils.d.ts +0 -1
- package/dist/{interpreter-d5fa7ce0.esm.js → interpreter-03737810.esm.js} +70 -25
- package/dist/{interpreter-05e11c15.cjs.js → interpreter-054e9fb7.cjs.js} +70 -25
- package/dist/{interpreter-a2236840.development.cjs.js → interpreter-0c630f66.development.cjs.js} +73 -25
- package/dist/{interpreter-e4d2487f.development.esm.js → interpreter-825f3d6e.development.esm.js} +73 -25
- package/dist/{raise-6a68d0cc.esm.js → raise-2d92eae8.esm.js} +11 -9
- package/dist/{raise-6fbd4513.development.esm.js → raise-46f122aa.development.esm.js} +11 -9
- package/dist/{raise-b4bfe138.development.cjs.js → raise-4c6a5a96.development.cjs.js} +11 -9
- package/dist/{raise-90808d65.cjs.js → raise-987c242e.cjs.js} +11 -9
- package/dist/{send-4163d2af.development.cjs.js → send-0e8675c8.development.cjs.js} +3 -3
- package/dist/{send-e5f0f3f6.esm.js → send-0edee2b4.esm.js} +3 -3
- package/dist/{send-7baeedcb.development.esm.js → send-4d5b92dc.development.esm.js} +3 -3
- package/dist/{send-72e85cc6.cjs.js → send-bd1bd0e3.cjs.js} +3 -3
- package/dist/xstate.cjs.js +9 -29
- package/dist/xstate.development.cjs.js +9 -29
- package/dist/xstate.development.esm.js +12 -32
- package/dist/xstate.esm.js +12 -32
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/{interpreter-e4d2487f.development.esm.js → interpreter-825f3d6e.development.esm.js}
RENAMED
|
@@ -147,13 +147,14 @@ function reportUnhandledError(err) {
|
|
|
147
147
|
|
|
148
148
|
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
let idCounter = 0;
|
|
151
|
+
function createSystem(rootActor) {
|
|
152
152
|
const children = new Map();
|
|
153
153
|
const keyedActors = new Map();
|
|
154
154
|
const reverseKeyedActors = new WeakMap();
|
|
155
|
+
const observers = new Set();
|
|
155
156
|
const system = {
|
|
156
|
-
_bookId: () => `x:${
|
|
157
|
+
_bookId: () => `x:${idCounter++}`,
|
|
157
158
|
_register: (sessionId, actorRef) => {
|
|
158
159
|
children.set(sessionId, actorRef);
|
|
159
160
|
return sessionId;
|
|
@@ -176,6 +177,25 @@ function createSystem() {
|
|
|
176
177
|
}
|
|
177
178
|
keyedActors.set(systemId, actorRef);
|
|
178
179
|
reverseKeyedActors.set(actorRef, systemId);
|
|
180
|
+
},
|
|
181
|
+
inspect: observer => {
|
|
182
|
+
observers.add(observer);
|
|
183
|
+
},
|
|
184
|
+
_sendInspectionEvent: event => {
|
|
185
|
+
const resolvedInspectionEvent = {
|
|
186
|
+
...event,
|
|
187
|
+
rootId: rootActor.sessionId
|
|
188
|
+
};
|
|
189
|
+
observers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
190
|
+
},
|
|
191
|
+
_relay: (source, target, event) => {
|
|
192
|
+
system._sendInspectionEvent({
|
|
193
|
+
type: '@xstate.event',
|
|
194
|
+
sourceRef: source,
|
|
195
|
+
targetRef: target,
|
|
196
|
+
event
|
|
197
|
+
});
|
|
198
|
+
target._send(event);
|
|
179
199
|
}
|
|
180
200
|
};
|
|
181
201
|
return system;
|
|
@@ -406,10 +426,14 @@ class Actor {
|
|
|
406
426
|
logger,
|
|
407
427
|
parent,
|
|
408
428
|
id,
|
|
409
|
-
systemId
|
|
429
|
+
systemId,
|
|
430
|
+
inspect
|
|
410
431
|
} = resolvedOptions;
|
|
411
|
-
|
|
412
|
-
|
|
432
|
+
this.system = parent?.system ?? createSystem(this);
|
|
433
|
+
if (inspect && !parent) {
|
|
434
|
+
// Always inspect at the system-level
|
|
435
|
+
this.system.inspect(toObserver(inspect));
|
|
436
|
+
}
|
|
413
437
|
if (systemId) {
|
|
414
438
|
this._systemId = systemId;
|
|
415
439
|
this.system._set(systemId, this);
|
|
@@ -423,7 +447,7 @@ class Actor {
|
|
|
423
447
|
this.src = resolvedOptions.src;
|
|
424
448
|
this.ref = this;
|
|
425
449
|
this._actorContext = {
|
|
426
|
-
self,
|
|
450
|
+
self: this,
|
|
427
451
|
id: this.id,
|
|
428
452
|
sessionId: this.sessionId,
|
|
429
453
|
logger: this.logger,
|
|
@@ -442,6 +466,10 @@ class Actor {
|
|
|
442
466
|
// Ensure that the send method is bound to this Actor instance
|
|
443
467
|
// if destructured
|
|
444
468
|
this.send = this.send.bind(this);
|
|
469
|
+
this.system._sendInspectionEvent({
|
|
470
|
+
type: '@xstate.actor',
|
|
471
|
+
actorRef: this
|
|
472
|
+
});
|
|
445
473
|
this._initState();
|
|
446
474
|
}
|
|
447
475
|
_initState() {
|
|
@@ -450,7 +478,7 @@ class Actor {
|
|
|
450
478
|
|
|
451
479
|
// array of functions to defer
|
|
452
480
|
|
|
453
|
-
update(snapshot) {
|
|
481
|
+
update(snapshot, event) {
|
|
454
482
|
// Update state
|
|
455
483
|
this._state = snapshot;
|
|
456
484
|
|
|
@@ -472,14 +500,24 @@ class Actor {
|
|
|
472
500
|
this._stopProcedure();
|
|
473
501
|
this._complete();
|
|
474
502
|
this._doneEvent = createDoneActorEvent(this.id, this._state.output);
|
|
475
|
-
this._parent
|
|
503
|
+
if (this._parent) {
|
|
504
|
+
this.system._relay(this, this._parent, this._doneEvent);
|
|
505
|
+
}
|
|
476
506
|
break;
|
|
477
507
|
case 'error':
|
|
478
508
|
this._stopProcedure();
|
|
479
509
|
this._error(this._state.error);
|
|
480
|
-
this._parent
|
|
510
|
+
if (this._parent) {
|
|
511
|
+
this.system._relay(this, this._parent, createErrorActorEvent(this.id, this._state.error));
|
|
512
|
+
}
|
|
481
513
|
break;
|
|
482
514
|
}
|
|
515
|
+
this.system._sendInspectionEvent({
|
|
516
|
+
type: '@xstate.snapshot',
|
|
517
|
+
actorRef: this,
|
|
518
|
+
event,
|
|
519
|
+
snapshot
|
|
520
|
+
});
|
|
483
521
|
}
|
|
484
522
|
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
485
523
|
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
@@ -512,12 +550,19 @@ class Actor {
|
|
|
512
550
|
this.system._set(this._systemId, this);
|
|
513
551
|
}
|
|
514
552
|
this.status = ActorStatus.Running;
|
|
553
|
+
const initEvent = createInitEvent(this.options.input);
|
|
554
|
+
this.system._sendInspectionEvent({
|
|
555
|
+
type: '@xstate.event',
|
|
556
|
+
sourceRef: this._parent,
|
|
557
|
+
targetRef: this,
|
|
558
|
+
event: initEvent
|
|
559
|
+
});
|
|
515
560
|
const status = this._state.status;
|
|
516
561
|
switch (status) {
|
|
517
562
|
case 'done':
|
|
518
563
|
// a state machine can be "done" upon intialization (it could reach a final state using initial microsteps)
|
|
519
564
|
// we still need to complete observers, flush deferreds etc
|
|
520
|
-
this.update(this._state);
|
|
565
|
+
this.update(this._state, initEvent);
|
|
521
566
|
// fallthrough
|
|
522
567
|
case 'error':
|
|
523
568
|
// TODO: rethink cleanup of observers, mailbox, etc
|
|
@@ -537,7 +582,7 @@ class Actor {
|
|
|
537
582
|
// TODO: this notifies all subscribers but usually this is redundant
|
|
538
583
|
// there is no real change happening here
|
|
539
584
|
// we need to rethink if this needs to be refactored
|
|
540
|
-
this.update(this._state);
|
|
585
|
+
this.update(this._state, initEvent);
|
|
541
586
|
if (this.options.devTools) {
|
|
542
587
|
this.attachDevTools();
|
|
543
588
|
}
|
|
@@ -565,7 +610,7 @@ class Actor {
|
|
|
565
610
|
this._parent?.send(createErrorActorEvent(this.id, err));
|
|
566
611
|
return;
|
|
567
612
|
}
|
|
568
|
-
this.update(nextState);
|
|
613
|
+
this.update(nextState, event);
|
|
569
614
|
if (event.type === XSTATE_STOP) {
|
|
570
615
|
this._stopProcedure();
|
|
571
616
|
this._complete();
|
|
@@ -651,14 +696,9 @@ class Actor {
|
|
|
651
696
|
}
|
|
652
697
|
|
|
653
698
|
/**
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
* @param event The event to send
|
|
699
|
+
* @internal
|
|
657
700
|
*/
|
|
658
|
-
|
|
659
|
-
if (typeof event === 'string') {
|
|
660
|
-
throw new Error(`Only event objects may be sent to actors; use .send({ type: "${event}" }) instead`);
|
|
661
|
-
}
|
|
701
|
+
_send(event) {
|
|
662
702
|
if (this.status === ActorStatus.Stopped) {
|
|
663
703
|
// do nothing
|
|
664
704
|
{
|
|
@@ -670,6 +710,18 @@ class Actor {
|
|
|
670
710
|
this.mailbox.enqueue(event);
|
|
671
711
|
}
|
|
672
712
|
|
|
713
|
+
/**
|
|
714
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
715
|
+
*
|
|
716
|
+
* @param event The event to send
|
|
717
|
+
*/
|
|
718
|
+
send(event) {
|
|
719
|
+
if (typeof event === 'string') {
|
|
720
|
+
throw new Error(`Only event objects may be sent to actors; use .send({ type: "${event}" }) instead`);
|
|
721
|
+
}
|
|
722
|
+
this.system._relay(undefined, this, event);
|
|
723
|
+
}
|
|
724
|
+
|
|
673
725
|
// TODO: make private (and figure out a way to do this within the machine)
|
|
674
726
|
delaySend({
|
|
675
727
|
event,
|
|
@@ -678,11 +730,7 @@ class Actor {
|
|
|
678
730
|
to
|
|
679
731
|
}) {
|
|
680
732
|
const timerId = this.clock.setTimeout(() => {
|
|
681
|
-
|
|
682
|
-
to.send(event);
|
|
683
|
-
} else {
|
|
684
|
-
this.send(event);
|
|
685
|
-
}
|
|
733
|
+
this.system._relay(this, to ?? this, event);
|
|
686
734
|
}, delay);
|
|
687
735
|
|
|
688
736
|
// TODO: consider the rehydration story here
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as resolveOutput, j as XSTATE_STOP, X as XSTATE_INIT, W as WILDCARD, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as resolveOutput, j as XSTATE_STOP, X as XSTATE_INIT, W as WILDCARD, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-03737810.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -1073,12 +1073,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1073
1073
|
});
|
|
1074
1074
|
for (const action of actions) {
|
|
1075
1075
|
const isInline = typeof action === 'function';
|
|
1076
|
-
const
|
|
1076
|
+
const resolvedAction = isInline ? action :
|
|
1077
1077
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
1078
1078
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
1079
1079
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
1080
1080
|
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
1081
|
-
if (!
|
|
1081
|
+
if (!resolvedAction) {
|
|
1082
1082
|
continue;
|
|
1083
1083
|
}
|
|
1084
1084
|
const actionArgs = {
|
|
@@ -1098,20 +1098,22 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1098
1098
|
// TS isn't able to narrow it down here
|
|
1099
1099
|
action
|
|
1100
1100
|
};
|
|
1101
|
-
if (!('resolve' in
|
|
1101
|
+
if (!('resolve' in resolvedAction)) {
|
|
1102
1102
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1103
|
-
|
|
1103
|
+
resolvedAction(actionArgs);
|
|
1104
1104
|
} else {
|
|
1105
|
-
actorCtx?.defer(() =>
|
|
1105
|
+
actorCtx?.defer(() => {
|
|
1106
|
+
resolvedAction(actionArgs);
|
|
1107
|
+
});
|
|
1106
1108
|
}
|
|
1107
1109
|
continue;
|
|
1108
1110
|
}
|
|
1109
|
-
const builtinAction =
|
|
1110
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs,
|
|
1111
|
+
const builtinAction = resolvedAction;
|
|
1112
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction // this holds all params
|
|
1111
1113
|
);
|
|
1112
1114
|
|
|
1113
1115
|
intermediateState = nextState;
|
|
1114
|
-
if ('execute' in
|
|
1116
|
+
if ('execute' in resolvedAction) {
|
|
1115
1117
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1116
1118
|
builtinAction.execute(actorCtx, params);
|
|
1117
1119
|
} else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as resolveOutput, W as WILDCARD, j as XSTATE_STOP, X as XSTATE_INIT, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as resolveOutput, W as WILDCARD, j as XSTATE_STOP, X as XSTATE_INIT, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-825f3d6e.development.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -1104,12 +1104,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1104
1104
|
});
|
|
1105
1105
|
for (const action of actions) {
|
|
1106
1106
|
const isInline = typeof action === 'function';
|
|
1107
|
-
const
|
|
1107
|
+
const resolvedAction = isInline ? action :
|
|
1108
1108
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
1109
1109
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
1110
1110
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
1111
1111
|
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
1112
|
-
if (!
|
|
1112
|
+
if (!resolvedAction) {
|
|
1113
1113
|
continue;
|
|
1114
1114
|
}
|
|
1115
1115
|
const actionArgs = {
|
|
@@ -1129,20 +1129,22 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1129
1129
|
// TS isn't able to narrow it down here
|
|
1130
1130
|
action
|
|
1131
1131
|
};
|
|
1132
|
-
if (!('resolve' in
|
|
1132
|
+
if (!('resolve' in resolvedAction)) {
|
|
1133
1133
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1134
|
-
|
|
1134
|
+
resolvedAction(actionArgs);
|
|
1135
1135
|
} else {
|
|
1136
|
-
actorCtx?.defer(() =>
|
|
1136
|
+
actorCtx?.defer(() => {
|
|
1137
|
+
resolvedAction(actionArgs);
|
|
1138
|
+
});
|
|
1137
1139
|
}
|
|
1138
1140
|
continue;
|
|
1139
1141
|
}
|
|
1140
|
-
const builtinAction =
|
|
1141
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs,
|
|
1142
|
+
const builtinAction = resolvedAction;
|
|
1143
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction // this holds all params
|
|
1142
1144
|
);
|
|
1143
1145
|
|
|
1144
1146
|
intermediateState = nextState;
|
|
1145
|
-
if ('execute' in
|
|
1147
|
+
if ('execute' in resolvedAction) {
|
|
1146
1148
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1147
1149
|
builtinAction.execute(actorCtx, params);
|
|
1148
1150
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-0c630f66.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -1106,12 +1106,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1106
1106
|
});
|
|
1107
1107
|
for (const action of actions) {
|
|
1108
1108
|
const isInline = typeof action === 'function';
|
|
1109
|
-
const
|
|
1109
|
+
const resolvedAction = isInline ? action :
|
|
1110
1110
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
1111
1111
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
1112
1112
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
1113
1113
|
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
1114
|
-
if (!
|
|
1114
|
+
if (!resolvedAction) {
|
|
1115
1115
|
continue;
|
|
1116
1116
|
}
|
|
1117
1117
|
const actionArgs = {
|
|
@@ -1131,20 +1131,22 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1131
1131
|
// TS isn't able to narrow it down here
|
|
1132
1132
|
action
|
|
1133
1133
|
};
|
|
1134
|
-
if (!('resolve' in
|
|
1134
|
+
if (!('resolve' in resolvedAction)) {
|
|
1135
1135
|
if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
|
|
1136
|
-
|
|
1136
|
+
resolvedAction(actionArgs);
|
|
1137
1137
|
} else {
|
|
1138
|
-
actorCtx?.defer(() =>
|
|
1138
|
+
actorCtx?.defer(() => {
|
|
1139
|
+
resolvedAction(actionArgs);
|
|
1140
|
+
});
|
|
1139
1141
|
}
|
|
1140
1142
|
continue;
|
|
1141
1143
|
}
|
|
1142
|
-
const builtinAction =
|
|
1143
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs,
|
|
1144
|
+
const builtinAction = resolvedAction;
|
|
1145
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction // this holds all params
|
|
1144
1146
|
);
|
|
1145
1147
|
|
|
1146
1148
|
intermediateState = nextState;
|
|
1147
|
-
if ('execute' in
|
|
1149
|
+
if ('execute' in resolvedAction) {
|
|
1148
1150
|
if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
|
|
1149
1151
|
builtinAction.execute(actorCtx, params);
|
|
1150
1152
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-054e9fb7.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -1075,12 +1075,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1075
1075
|
});
|
|
1076
1076
|
for (const action of actions) {
|
|
1077
1077
|
const isInline = typeof action === 'function';
|
|
1078
|
-
const
|
|
1078
|
+
const resolvedAction = isInline ? action :
|
|
1079
1079
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
1080
1080
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
1081
1081
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
1082
1082
|
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
1083
|
-
if (!
|
|
1083
|
+
if (!resolvedAction) {
|
|
1084
1084
|
continue;
|
|
1085
1085
|
}
|
|
1086
1086
|
const actionArgs = {
|
|
@@ -1100,20 +1100,22 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1100
1100
|
// TS isn't able to narrow it down here
|
|
1101
1101
|
action
|
|
1102
1102
|
};
|
|
1103
|
-
if (!('resolve' in
|
|
1103
|
+
if (!('resolve' in resolvedAction)) {
|
|
1104
1104
|
if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
|
|
1105
|
-
|
|
1105
|
+
resolvedAction(actionArgs);
|
|
1106
1106
|
} else {
|
|
1107
|
-
actorCtx?.defer(() =>
|
|
1107
|
+
actorCtx?.defer(() => {
|
|
1108
|
+
resolvedAction(actionArgs);
|
|
1109
|
+
});
|
|
1108
1110
|
}
|
|
1109
1111
|
continue;
|
|
1110
1112
|
}
|
|
1111
|
-
const builtinAction =
|
|
1112
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs,
|
|
1113
|
+
const builtinAction = resolvedAction;
|
|
1114
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction // this holds all params
|
|
1113
1115
|
);
|
|
1114
1116
|
|
|
1115
1117
|
intermediateState = nextState;
|
|
1116
|
-
if ('execute' in
|
|
1118
|
+
if ('execute' in resolvedAction) {
|
|
1117
1119
|
if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
|
|
1118
1120
|
builtinAction.execute(actorCtx, params);
|
|
1119
1121
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-4c6a5a96.development.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-0c630f66.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorContext, {
|
|
7
7
|
machine,
|
|
@@ -320,7 +320,7 @@ function executeSendTo(actorContext, params) {
|
|
|
320
320
|
event
|
|
321
321
|
} = params;
|
|
322
322
|
actorContext.defer(() => {
|
|
323
|
-
|
|
323
|
+
actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-
|
|
1
|
+
import { j as cloneState, e as evaluateGuard } from './raise-2d92eae8.esm.js';
|
|
2
|
+
import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-03737810.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorContext, {
|
|
5
5
|
machine,
|
|
@@ -306,7 +306,7 @@ function executeSendTo(actorContext, params) {
|
|
|
306
306
|
event
|
|
307
307
|
} = params;
|
|
308
308
|
actorContext.defer(() => {
|
|
309
|
-
|
|
309
|
+
actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
312
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-
|
|
1
|
+
import { j as cloneState, e as evaluateGuard } from './raise-46f122aa.development.esm.js';
|
|
2
|
+
import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-825f3d6e.development.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorContext, {
|
|
5
5
|
machine,
|
|
@@ -318,7 +318,7 @@ function executeSendTo(actorContext, params) {
|
|
|
318
318
|
event
|
|
319
319
|
} = params;
|
|
320
320
|
actorContext.defer(() => {
|
|
321
|
-
|
|
321
|
+
actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
322
322
|
});
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-987c242e.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-054e9fb7.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorContext, {
|
|
7
7
|
machine,
|
|
@@ -308,7 +308,7 @@ function executeSendTo(actorContext, params) {
|
|
|
308
308
|
event
|
|
309
309
|
} = params;
|
|
310
310
|
actorContext.defer(() => {
|
|
311
|
-
|
|
311
|
+
actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
314
|
/**
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-054e9fb7.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-987c242e.cjs.js');
|
|
8
|
+
var send = require('./send-bd1bd0e3.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -408,6 +408,10 @@ class StateMachine {
|
|
|
408
408
|
this.version = this.config.version;
|
|
409
409
|
this.types = this.config.types ?? {};
|
|
410
410
|
this.transition = this.transition.bind(this);
|
|
411
|
+
this.getInitialState = this.getInitialState.bind(this);
|
|
412
|
+
this.restoreState = this.restoreState.bind(this);
|
|
413
|
+
this.start = this.start.bind(this);
|
|
414
|
+
this.getPersistedState = this.getPersistedState.bind(this);
|
|
411
415
|
this.root = new StateNode(config, {
|
|
412
416
|
_key: this.id,
|
|
413
417
|
_machine: this
|
|
@@ -602,39 +606,15 @@ class StateMachine {
|
|
|
602
606
|
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
603
607
|
const actorRef = interpreter.createActor(logic, {
|
|
604
608
|
id: actorId,
|
|
609
|
+
parent: _actorCtx?.self,
|
|
605
610
|
state: actorState
|
|
606
611
|
});
|
|
607
612
|
children[actorId] = actorRef;
|
|
608
613
|
});
|
|
609
|
-
|
|
614
|
+
return this.createState(new guards_dist_xstateGuards.State({
|
|
610
615
|
...snapshot,
|
|
611
616
|
children
|
|
612
617
|
}, this));
|
|
613
|
-
|
|
614
|
-
// TODO: DRY this up
|
|
615
|
-
restoredSnapshot.configuration.forEach(stateNode => {
|
|
616
|
-
if (stateNode.invoke) {
|
|
617
|
-
stateNode.invoke.forEach(invokeConfig => {
|
|
618
|
-
const {
|
|
619
|
-
id,
|
|
620
|
-
src
|
|
621
|
-
} = invokeConfig;
|
|
622
|
-
if (children[id]) {
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
const referenced = interpreter.resolveReferencedActor(this.implementations.actors[src]);
|
|
626
|
-
if (referenced) {
|
|
627
|
-
const actorRef = interpreter.createActor(referenced.src, {
|
|
628
|
-
id,
|
|
629
|
-
parent: _actorCtx?.self,
|
|
630
|
-
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
|
631
|
-
});
|
|
632
|
-
children[id] = actorRef;
|
|
633
|
-
}
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
return restoredSnapshot;
|
|
638
618
|
}
|
|
639
619
|
|
|
640
620
|
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-0c630f66.development.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-4c6a5a96.development.cjs.js');
|
|
8
|
+
var send = require('./send-0e8675c8.development.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -408,6 +408,10 @@ class StateMachine {
|
|
|
408
408
|
this.version = this.config.version;
|
|
409
409
|
this.types = this.config.types ?? {};
|
|
410
410
|
this.transition = this.transition.bind(this);
|
|
411
|
+
this.getInitialState = this.getInitialState.bind(this);
|
|
412
|
+
this.restoreState = this.restoreState.bind(this);
|
|
413
|
+
this.start = this.start.bind(this);
|
|
414
|
+
this.getPersistedState = this.getPersistedState.bind(this);
|
|
411
415
|
this.root = new StateNode(config, {
|
|
412
416
|
_key: this.id,
|
|
413
417
|
_machine: this
|
|
@@ -605,39 +609,15 @@ class StateMachine {
|
|
|
605
609
|
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
606
610
|
const actorRef = interpreter.createActor(logic, {
|
|
607
611
|
id: actorId,
|
|
612
|
+
parent: _actorCtx?.self,
|
|
608
613
|
state: actorState
|
|
609
614
|
});
|
|
610
615
|
children[actorId] = actorRef;
|
|
611
616
|
});
|
|
612
|
-
|
|
617
|
+
return this.createState(new guards_dist_xstateGuards.State({
|
|
613
618
|
...snapshot,
|
|
614
619
|
children
|
|
615
620
|
}, this));
|
|
616
|
-
|
|
617
|
-
// TODO: DRY this up
|
|
618
|
-
restoredSnapshot.configuration.forEach(stateNode => {
|
|
619
|
-
if (stateNode.invoke) {
|
|
620
|
-
stateNode.invoke.forEach(invokeConfig => {
|
|
621
|
-
const {
|
|
622
|
-
id,
|
|
623
|
-
src
|
|
624
|
-
} = invokeConfig;
|
|
625
|
-
if (children[id]) {
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
const referenced = interpreter.resolveReferencedActor(this.implementations.actors[src]);
|
|
629
|
-
if (referenced) {
|
|
630
|
-
const actorRef = interpreter.createActor(referenced.src, {
|
|
631
|
-
id,
|
|
632
|
-
parent: _actorCtx?.self,
|
|
633
|
-
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
|
634
|
-
});
|
|
635
|
-
children[id] = actorRef;
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
return restoredSnapshot;
|
|
641
621
|
}
|
|
642
622
|
|
|
643
623
|
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|