xstate 5.0.0-beta.26 → 5.0.0-beta.27
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 +20 -18
- package/actions/dist/xstate-actions.cjs.mjs +2 -0
- package/actions/dist/xstate-actions.development.cjs.js +20 -18
- package/actions/dist/xstate-actions.development.cjs.mjs +2 -0
- 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 +37 -14
- package/actors/dist/xstate-actors.cjs.mjs +0 -5
- package/actors/dist/xstate-actors.development.cjs.js +37 -14
- package/actors/dist/xstate-actors.development.cjs.mjs +0 -5
- package/actors/dist/xstate-actors.development.esm.js +34 -1
- package/actors/dist/xstate-actors.esm.js +34 -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-5943a9db.esm.js → actions-020463e9.esm.js} +76 -532
- package/dist/{actions-cf69419d.development.esm.js → actions-9754d2ca.development.esm.js} +76 -532
- package/dist/{actions-0971b43d.development.cjs.js → actions-ca622922.development.cjs.js} +81 -546
- package/dist/{actions-319cefe7.cjs.js → actions-d1dba4ac.cjs.js} +81 -546
- package/dist/declarations/src/Machine.d.ts +4 -3
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateNode.d.ts +0 -9
- package/dist/declarations/src/actions/assign.d.ts +6 -11
- package/dist/declarations/src/actions/cancel.d.ts +5 -12
- package/dist/declarations/src/actions/choose.d.ts +7 -6
- package/dist/declarations/src/actions/log.d.ts +5 -20
- package/dist/declarations/src/actions/pure.d.ts +9 -8
- package/dist/declarations/src/actions/raise.d.ts +6 -5
- package/dist/declarations/src/actions/send.d.ts +7 -12
- package/dist/declarations/src/actions/stop.d.ts +5 -12
- package/dist/declarations/src/actions.d.ts +2 -0
- package/dist/declarations/src/actors/index.d.ts +0 -20
- package/dist/declarations/src/actors/promise.d.ts +2 -1
- package/dist/declarations/src/constants.d.ts +7 -0
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +14 -14
- package/dist/declarations/src/typegenTypes.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +10 -15
- package/dist/declarations/src/utils.d.ts +1 -2
- package/dist/promise-2ad94e3b.development.esm.js +406 -0
- package/dist/promise-3b7e3357.development.cjs.js +412 -0
- package/dist/promise-5b07c38e.esm.js +406 -0
- package/dist/promise-7a8c1768.cjs.js +412 -0
- package/dist/xstate.cjs.js +78 -102
- package/dist/xstate.development.cjs.js +78 -102
- package/dist/xstate.development.esm.js +6 -30
- package/dist/xstate.esm.js +6 -30
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +6 -6
- package/guards/dist/xstate-guards.development.cjs.js +6 -6
- 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
|
@@ -71,7 +71,8 @@ const TARGETLESS_KEY = '';
|
|
|
71
71
|
const NULL_EVENT = '';
|
|
72
72
|
const STATE_IDENTIFIER = '#';
|
|
73
73
|
const WILDCARD = '*';
|
|
74
|
-
const
|
|
74
|
+
const XSTATE_INIT = 'xstate.init';
|
|
75
|
+
const XSTATE_STOP = 'xstate.stop';
|
|
75
76
|
|
|
76
77
|
function resolve$8(actorContext, state, args, {
|
|
77
78
|
to,
|
|
@@ -134,7 +135,6 @@ function execute$5(actorContext, params) {
|
|
|
134
135
|
} : event);
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
|
-
|
|
138
138
|
/**
|
|
139
139
|
* Sends an event to an actor.
|
|
140
140
|
*
|
|
@@ -217,7 +217,6 @@ function resolve$7(_, state, actionArgs, {
|
|
|
217
217
|
function execute$4(actorContext, resolvedSendId) {
|
|
218
218
|
actorContext.self.cancel(resolvedSendId);
|
|
219
219
|
}
|
|
220
|
-
|
|
221
220
|
/**
|
|
222
221
|
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
223
222
|
* be executed, nor will its event be sent, unless it has already been sent
|
|
@@ -302,32 +301,53 @@ class Mailbox {
|
|
|
302
301
|
}
|
|
303
302
|
}
|
|
304
303
|
|
|
305
|
-
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
306
|
-
|
|
307
304
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
305
|
+
* This function makes sure that unhandled errors are thrown in a separate macrotask.
|
|
306
|
+
* It allows those errors to be detected by global error handlers and reported to bug tracking services
|
|
307
|
+
* without interrupting our own stack of execution.
|
|
311
308
|
*
|
|
312
|
-
* @param
|
|
313
|
-
* @param initialState The initial state of the transition function.
|
|
314
|
-
* @returns Actor logic
|
|
309
|
+
* @param err error to be thrown
|
|
315
310
|
*/
|
|
316
|
-
function
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
311
|
+
function reportUnhandledError(err) {
|
|
312
|
+
setTimeout(() => {
|
|
313
|
+
throw err;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
318
|
+
|
|
319
|
+
function createSystem() {
|
|
320
|
+
let sessionIdCounter = 0;
|
|
321
|
+
const children = new Map();
|
|
322
|
+
const keyedActors = new Map();
|
|
323
|
+
const reverseKeyedActors = new WeakMap();
|
|
324
|
+
const system = {
|
|
325
|
+
_bookId: () => `x:${sessionIdCounter++}`,
|
|
326
|
+
_register: (sessionId, actorRef) => {
|
|
327
|
+
children.set(sessionId, actorRef);
|
|
328
|
+
return sessionId;
|
|
329
|
+
},
|
|
330
|
+
_unregister: actorRef => {
|
|
331
|
+
children.delete(actorRef.sessionId);
|
|
332
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
333
|
+
if (systemId !== undefined) {
|
|
334
|
+
keyedActors.delete(systemId);
|
|
335
|
+
reverseKeyedActors.delete(actorRef);
|
|
336
|
+
}
|
|
321
337
|
},
|
|
322
|
-
|
|
323
|
-
return
|
|
324
|
-
input
|
|
325
|
-
}) : initialState;
|
|
338
|
+
get: systemId => {
|
|
339
|
+
return keyedActors.get(systemId);
|
|
326
340
|
},
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
341
|
+
_set: (systemId, actorRef) => {
|
|
342
|
+
const existing = keyedActors.get(systemId);
|
|
343
|
+
if (existing && existing !== actorRef) {
|
|
344
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
345
|
+
}
|
|
346
|
+
keyedActors.set(systemId, actorRef);
|
|
347
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
348
|
+
}
|
|
330
349
|
};
|
|
350
|
+
return system;
|
|
331
351
|
}
|
|
332
352
|
|
|
333
353
|
function matchesState(parentStateId, childStateId) {
|
|
@@ -460,23 +480,6 @@ function normalizeTarget(target) {
|
|
|
460
480
|
}
|
|
461
481
|
return toArray(target);
|
|
462
482
|
}
|
|
463
|
-
function toInvokeConfig(invocable, id) {
|
|
464
|
-
if (typeof invocable === 'object') {
|
|
465
|
-
if ('src' in invocable) {
|
|
466
|
-
return invocable;
|
|
467
|
-
}
|
|
468
|
-
if ('transition' in invocable) {
|
|
469
|
-
return {
|
|
470
|
-
id,
|
|
471
|
-
src: invocable
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
return {
|
|
476
|
-
id,
|
|
477
|
-
src: invocable
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
483
|
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
481
484
|
const isObserver = typeof nextHandler === 'object';
|
|
482
485
|
const self = isObserver ? nextHandler : undefined;
|
|
@@ -496,482 +499,6 @@ function resolveReferencedActor(referenced) {
|
|
|
496
499
|
} : referenced : undefined;
|
|
497
500
|
}
|
|
498
501
|
|
|
499
|
-
function fromCallback(invokeCallback) {
|
|
500
|
-
return {
|
|
501
|
-
config: invokeCallback,
|
|
502
|
-
start: (_state, {
|
|
503
|
-
self
|
|
504
|
-
}) => {
|
|
505
|
-
self.send({
|
|
506
|
-
type: startSignalType
|
|
507
|
-
});
|
|
508
|
-
},
|
|
509
|
-
transition: (state, event, {
|
|
510
|
-
self,
|
|
511
|
-
id,
|
|
512
|
-
system
|
|
513
|
-
}) => {
|
|
514
|
-
if (event.type === startSignalType) {
|
|
515
|
-
const sendBack = eventForParent => {
|
|
516
|
-
if (state.canceled) {
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
self._parent?.send(eventForParent);
|
|
520
|
-
};
|
|
521
|
-
const receive = newListener => {
|
|
522
|
-
state.receivers.add(newListener);
|
|
523
|
-
};
|
|
524
|
-
state.dispose = invokeCallback({
|
|
525
|
-
input: state.input,
|
|
526
|
-
system,
|
|
527
|
-
self: self,
|
|
528
|
-
sendBack,
|
|
529
|
-
receive
|
|
530
|
-
});
|
|
531
|
-
if (isPromiseLike(state.dispose)) {
|
|
532
|
-
state.dispose.then(resolved => {
|
|
533
|
-
self._parent?.send(doneInvoke(id, resolved));
|
|
534
|
-
state.canceled = true;
|
|
535
|
-
}, errorData => {
|
|
536
|
-
state.canceled = true;
|
|
537
|
-
self._parent?.send(error(id, errorData));
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
return state;
|
|
541
|
-
}
|
|
542
|
-
if (event.type === stopSignalType) {
|
|
543
|
-
state.canceled = true;
|
|
544
|
-
if (typeof state.dispose === 'function') {
|
|
545
|
-
state.dispose();
|
|
546
|
-
}
|
|
547
|
-
return state;
|
|
548
|
-
}
|
|
549
|
-
if (isSignal(event)) {
|
|
550
|
-
// TODO: unrecognized signal
|
|
551
|
-
return state;
|
|
552
|
-
}
|
|
553
|
-
state.receivers.forEach(receiver => receiver(event));
|
|
554
|
-
return state;
|
|
555
|
-
},
|
|
556
|
-
getInitialState: (_, input) => {
|
|
557
|
-
return {
|
|
558
|
-
canceled: false,
|
|
559
|
-
receivers: new Set(),
|
|
560
|
-
dispose: undefined,
|
|
561
|
-
input
|
|
562
|
-
};
|
|
563
|
-
},
|
|
564
|
-
getSnapshot: () => undefined,
|
|
565
|
-
getPersistedState: ({
|
|
566
|
-
input,
|
|
567
|
-
canceled
|
|
568
|
-
}) => ({
|
|
569
|
-
input,
|
|
570
|
-
canceled
|
|
571
|
-
})
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
function fromObservable(observableCreator) {
|
|
576
|
-
const nextEventType = '$$xstate.next';
|
|
577
|
-
const errorEventType = '$$xstate.error';
|
|
578
|
-
const completeEventType = '$$xstate.complete';
|
|
579
|
-
return {
|
|
580
|
-
config: observableCreator,
|
|
581
|
-
transition: (state, event, {
|
|
582
|
-
self,
|
|
583
|
-
id,
|
|
584
|
-
defer
|
|
585
|
-
}) => {
|
|
586
|
-
if (state.status !== 'active') {
|
|
587
|
-
return state;
|
|
588
|
-
}
|
|
589
|
-
switch (event.type) {
|
|
590
|
-
case nextEventType:
|
|
591
|
-
// match the exact timing of events sent by machines
|
|
592
|
-
// send actions are not executed immediately
|
|
593
|
-
defer(() => {
|
|
594
|
-
self._parent?.send({
|
|
595
|
-
type: `xstate.snapshot.${id}`,
|
|
596
|
-
data: event.data
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
return {
|
|
600
|
-
...state,
|
|
601
|
-
data: event.data
|
|
602
|
-
};
|
|
603
|
-
case errorEventType:
|
|
604
|
-
return {
|
|
605
|
-
...state,
|
|
606
|
-
status: 'error',
|
|
607
|
-
input: undefined,
|
|
608
|
-
data: event.data,
|
|
609
|
-
// TODO: if we keep this as `data` we should reflect this in the type
|
|
610
|
-
subscription: undefined
|
|
611
|
-
};
|
|
612
|
-
case completeEventType:
|
|
613
|
-
return {
|
|
614
|
-
...state,
|
|
615
|
-
status: 'done',
|
|
616
|
-
input: undefined,
|
|
617
|
-
subscription: undefined
|
|
618
|
-
};
|
|
619
|
-
case stopSignalType:
|
|
620
|
-
state.subscription.unsubscribe();
|
|
621
|
-
return {
|
|
622
|
-
...state,
|
|
623
|
-
status: 'canceled',
|
|
624
|
-
input: undefined,
|
|
625
|
-
subscription: undefined
|
|
626
|
-
};
|
|
627
|
-
default:
|
|
628
|
-
return state;
|
|
629
|
-
}
|
|
630
|
-
},
|
|
631
|
-
getInitialState: (_, input) => {
|
|
632
|
-
return {
|
|
633
|
-
subscription: undefined,
|
|
634
|
-
status: 'active',
|
|
635
|
-
data: undefined,
|
|
636
|
-
input
|
|
637
|
-
};
|
|
638
|
-
},
|
|
639
|
-
start: (state, {
|
|
640
|
-
self,
|
|
641
|
-
system
|
|
642
|
-
}) => {
|
|
643
|
-
if (state.status === 'done') {
|
|
644
|
-
// Do not restart a completed observable
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
state.subscription = observableCreator({
|
|
648
|
-
input: state.input,
|
|
649
|
-
system,
|
|
650
|
-
self
|
|
651
|
-
}).subscribe({
|
|
652
|
-
next: value => {
|
|
653
|
-
self.send({
|
|
654
|
-
type: nextEventType,
|
|
655
|
-
data: value
|
|
656
|
-
});
|
|
657
|
-
},
|
|
658
|
-
error: err => {
|
|
659
|
-
self.send({
|
|
660
|
-
type: errorEventType,
|
|
661
|
-
data: err
|
|
662
|
-
});
|
|
663
|
-
},
|
|
664
|
-
complete: () => {
|
|
665
|
-
self.send({
|
|
666
|
-
type: completeEventType
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
},
|
|
671
|
-
getSnapshot: state => state.data,
|
|
672
|
-
getPersistedState: ({
|
|
673
|
-
status,
|
|
674
|
-
data,
|
|
675
|
-
input
|
|
676
|
-
}) => ({
|
|
677
|
-
status,
|
|
678
|
-
data,
|
|
679
|
-
input
|
|
680
|
-
}),
|
|
681
|
-
getStatus: state => state,
|
|
682
|
-
restoreState: state => ({
|
|
683
|
-
...state,
|
|
684
|
-
subscription: undefined
|
|
685
|
-
})
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* Creates event observable logic that listens to an observable
|
|
691
|
-
* that delivers event objects.
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
* @param lazyObservable A function that creates an observable
|
|
695
|
-
* @returns Event observable logic
|
|
696
|
-
*/
|
|
697
|
-
|
|
698
|
-
function fromEventObservable(lazyObservable) {
|
|
699
|
-
const errorEventType = '$$xstate.error';
|
|
700
|
-
const completeEventType = '$$xstate.complete';
|
|
701
|
-
|
|
702
|
-
// TODO: event types
|
|
703
|
-
return {
|
|
704
|
-
config: lazyObservable,
|
|
705
|
-
transition: (state, event) => {
|
|
706
|
-
if (state.status !== 'active') {
|
|
707
|
-
return state;
|
|
708
|
-
}
|
|
709
|
-
switch (event.type) {
|
|
710
|
-
case errorEventType:
|
|
711
|
-
return {
|
|
712
|
-
...state,
|
|
713
|
-
status: 'error',
|
|
714
|
-
input: undefined,
|
|
715
|
-
data: event.data,
|
|
716
|
-
// TODO: if we keep this as `data` we should reflect this in the type
|
|
717
|
-
subscription: undefined
|
|
718
|
-
};
|
|
719
|
-
case completeEventType:
|
|
720
|
-
return {
|
|
721
|
-
...state,
|
|
722
|
-
status: 'done',
|
|
723
|
-
input: undefined,
|
|
724
|
-
subscription: undefined
|
|
725
|
-
};
|
|
726
|
-
case stopSignalType:
|
|
727
|
-
state.subscription.unsubscribe();
|
|
728
|
-
return {
|
|
729
|
-
...state,
|
|
730
|
-
status: 'canceled',
|
|
731
|
-
input: undefined,
|
|
732
|
-
subscription: undefined
|
|
733
|
-
};
|
|
734
|
-
default:
|
|
735
|
-
return state;
|
|
736
|
-
}
|
|
737
|
-
},
|
|
738
|
-
getInitialState: (_, input) => {
|
|
739
|
-
return {
|
|
740
|
-
subscription: undefined,
|
|
741
|
-
status: 'active',
|
|
742
|
-
data: undefined,
|
|
743
|
-
input
|
|
744
|
-
};
|
|
745
|
-
},
|
|
746
|
-
start: (state, {
|
|
747
|
-
self,
|
|
748
|
-
system
|
|
749
|
-
}) => {
|
|
750
|
-
if (state.status === 'done') {
|
|
751
|
-
// Do not restart a completed observable
|
|
752
|
-
return;
|
|
753
|
-
}
|
|
754
|
-
state.subscription = lazyObservable({
|
|
755
|
-
input: state.input,
|
|
756
|
-
system,
|
|
757
|
-
self
|
|
758
|
-
}).subscribe({
|
|
759
|
-
next: value => {
|
|
760
|
-
self._parent?.send(value);
|
|
761
|
-
},
|
|
762
|
-
error: err => {
|
|
763
|
-
self.send({
|
|
764
|
-
type: errorEventType,
|
|
765
|
-
data: err
|
|
766
|
-
});
|
|
767
|
-
},
|
|
768
|
-
complete: () => {
|
|
769
|
-
self.send({
|
|
770
|
-
type: completeEventType
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
},
|
|
775
|
-
getSnapshot: _ => undefined,
|
|
776
|
-
getPersistedState: ({
|
|
777
|
-
status,
|
|
778
|
-
data,
|
|
779
|
-
input
|
|
780
|
-
}) => ({
|
|
781
|
-
status,
|
|
782
|
-
data,
|
|
783
|
-
input
|
|
784
|
-
}),
|
|
785
|
-
getStatus: state => state,
|
|
786
|
-
restoreState: state => ({
|
|
787
|
-
...state,
|
|
788
|
-
subscription: undefined
|
|
789
|
-
})
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
const resolveEventType = '$$xstate.resolve';
|
|
794
|
-
const rejectEventType = '$$xstate.reject';
|
|
795
|
-
function fromPromise(
|
|
796
|
-
// TODO: add types
|
|
797
|
-
promiseCreator) {
|
|
798
|
-
// TODO: add event types
|
|
799
|
-
const logic = {
|
|
800
|
-
config: promiseCreator,
|
|
801
|
-
transition: (state, event) => {
|
|
802
|
-
if (state.status !== 'active') {
|
|
803
|
-
return state;
|
|
804
|
-
}
|
|
805
|
-
switch (event.type) {
|
|
806
|
-
case resolveEventType:
|
|
807
|
-
return {
|
|
808
|
-
...state,
|
|
809
|
-
status: 'done',
|
|
810
|
-
data: event.data,
|
|
811
|
-
input: undefined
|
|
812
|
-
};
|
|
813
|
-
case rejectEventType:
|
|
814
|
-
return {
|
|
815
|
-
...state,
|
|
816
|
-
status: 'error',
|
|
817
|
-
data: event.data,
|
|
818
|
-
// TODO: if we keep this as `data` we should reflect this in the type
|
|
819
|
-
input: undefined
|
|
820
|
-
};
|
|
821
|
-
case stopSignalType:
|
|
822
|
-
return {
|
|
823
|
-
...state,
|
|
824
|
-
status: 'canceled',
|
|
825
|
-
input: undefined
|
|
826
|
-
};
|
|
827
|
-
default:
|
|
828
|
-
return state;
|
|
829
|
-
}
|
|
830
|
-
},
|
|
831
|
-
start: (state, {
|
|
832
|
-
self,
|
|
833
|
-
system
|
|
834
|
-
}) => {
|
|
835
|
-
// TODO: determine how to allow customizing this so that promises
|
|
836
|
-
// can be restarted if necessary
|
|
837
|
-
if (state.status !== 'active') {
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
const resolvedPromise = Promise.resolve(promiseCreator({
|
|
841
|
-
input: state.input,
|
|
842
|
-
system,
|
|
843
|
-
self
|
|
844
|
-
}));
|
|
845
|
-
resolvedPromise.then(response => {
|
|
846
|
-
// TODO: remove this condition once dead letter queue lands
|
|
847
|
-
if (self._state.status !== 'active') {
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
self.send({
|
|
851
|
-
type: resolveEventType,
|
|
852
|
-
data: response
|
|
853
|
-
});
|
|
854
|
-
}, errorData => {
|
|
855
|
-
// TODO: remove this condition once dead letter queue lands
|
|
856
|
-
if (self._state.status !== 'active') {
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
self.send({
|
|
860
|
-
type: rejectEventType,
|
|
861
|
-
data: errorData
|
|
862
|
-
});
|
|
863
|
-
});
|
|
864
|
-
},
|
|
865
|
-
getInitialState: (_, input) => {
|
|
866
|
-
return {
|
|
867
|
-
status: 'active',
|
|
868
|
-
data: undefined,
|
|
869
|
-
input
|
|
870
|
-
};
|
|
871
|
-
},
|
|
872
|
-
getSnapshot: state => state.data,
|
|
873
|
-
getStatus: state => state,
|
|
874
|
-
getPersistedState: state => state,
|
|
875
|
-
restoreState: state => state
|
|
876
|
-
};
|
|
877
|
-
return logic;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
const startSignalType = 'xstate.init';
|
|
881
|
-
const stopSignalType = 'xstate.stop';
|
|
882
|
-
const startSignal = {
|
|
883
|
-
type: 'xstate.init'
|
|
884
|
-
};
|
|
885
|
-
const stopSignal = {
|
|
886
|
-
type: 'xstate.stop'
|
|
887
|
-
};
|
|
888
|
-
/**
|
|
889
|
-
* An object that expresses the actor logic in reaction to received events,
|
|
890
|
-
* as well as an optionally emitted stream of values.
|
|
891
|
-
*
|
|
892
|
-
* @template TReceived The received event
|
|
893
|
-
* @template TSnapshot The emitted value
|
|
894
|
-
*/
|
|
895
|
-
|
|
896
|
-
function isSignal(event) {
|
|
897
|
-
return event.type === startSignalType || event.type === stopSignalType;
|
|
898
|
-
}
|
|
899
|
-
function isActorRef(item) {
|
|
900
|
-
return !!item && typeof item === 'object' && typeof item.send === 'function';
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
// TODO: refactor the return type, this could be written in a better way
|
|
904
|
-
// but it's best to avoid unneccessary breaking changes now
|
|
905
|
-
// @deprecated use `interpret(actorLogic)` instead
|
|
906
|
-
function toActorRef(actorRefLike) {
|
|
907
|
-
return {
|
|
908
|
-
subscribe: () => ({
|
|
909
|
-
unsubscribe: () => void 0
|
|
910
|
-
}),
|
|
911
|
-
id: 'anonymous',
|
|
912
|
-
sessionId: '',
|
|
913
|
-
getSnapshot: () => undefined,
|
|
914
|
-
// TODO: this isn't safe
|
|
915
|
-
[symbolObservable]: function () {
|
|
916
|
-
return this;
|
|
917
|
-
},
|
|
918
|
-
status: ActorStatus.Running,
|
|
919
|
-
stop: () => void 0,
|
|
920
|
-
...actorRefLike
|
|
921
|
-
};
|
|
922
|
-
}
|
|
923
|
-
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
924
|
-
function createEmptyActor() {
|
|
925
|
-
return createActor(emptyLogic);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
/**
|
|
929
|
-
* This function makes sure that unhandled errors are thrown in a separate macrotask.
|
|
930
|
-
* It allows those errors to be detected by global error handlers and reported to bug tracking services
|
|
931
|
-
* without interrupting our own stack of execution.
|
|
932
|
-
*
|
|
933
|
-
* @param err error to be thrown
|
|
934
|
-
*/
|
|
935
|
-
function reportUnhandledError(err) {
|
|
936
|
-
setTimeout(() => {
|
|
937
|
-
throw err;
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
function createSystem() {
|
|
942
|
-
let sessionIdCounter = 0;
|
|
943
|
-
const children = new Map();
|
|
944
|
-
const keyedActors = new Map();
|
|
945
|
-
const reverseKeyedActors = new WeakMap();
|
|
946
|
-
const system = {
|
|
947
|
-
_bookId: () => `x:${sessionIdCounter++}`,
|
|
948
|
-
_register: (sessionId, actorRef) => {
|
|
949
|
-
children.set(sessionId, actorRef);
|
|
950
|
-
return sessionId;
|
|
951
|
-
},
|
|
952
|
-
_unregister: actorRef => {
|
|
953
|
-
children.delete(actorRef.sessionId);
|
|
954
|
-
const systemId = reverseKeyedActors.get(actorRef);
|
|
955
|
-
if (systemId !== undefined) {
|
|
956
|
-
keyedActors.delete(systemId);
|
|
957
|
-
reverseKeyedActors.delete(actorRef);
|
|
958
|
-
}
|
|
959
|
-
},
|
|
960
|
-
get: systemId => {
|
|
961
|
-
return keyedActors.get(systemId);
|
|
962
|
-
},
|
|
963
|
-
_set: (systemId, actorRef) => {
|
|
964
|
-
const existing = keyedActors.get(systemId);
|
|
965
|
-
if (existing && existing !== actorRef) {
|
|
966
|
-
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
967
|
-
}
|
|
968
|
-
keyedActors.set(systemId, actorRef);
|
|
969
|
-
reverseKeyedActors.set(actorRef, systemId);
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
return system;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
502
|
let ActorStatus = /*#__PURE__*/function (ActorStatus) {
|
|
976
503
|
ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
|
|
977
504
|
ActorStatus[ActorStatus["Running"] = 1] = "Running";
|
|
@@ -1218,7 +745,7 @@ class Actor {
|
|
|
1218
745
|
return;
|
|
1219
746
|
}
|
|
1220
747
|
this.update(nextState);
|
|
1221
|
-
if (event.type ===
|
|
748
|
+
if (event.type === XSTATE_STOP) {
|
|
1222
749
|
this._stopProcedure();
|
|
1223
750
|
this._complete();
|
|
1224
751
|
}
|
|
@@ -1233,7 +760,7 @@ class Actor {
|
|
|
1233
760
|
return this;
|
|
1234
761
|
}
|
|
1235
762
|
this.mailbox.enqueue({
|
|
1236
|
-
type:
|
|
763
|
+
type: XSTATE_STOP
|
|
1237
764
|
});
|
|
1238
765
|
return this;
|
|
1239
766
|
}
|
|
@@ -1448,6 +975,9 @@ function execute$3(actorContext, {
|
|
|
1448
975
|
}
|
|
1449
976
|
});
|
|
1450
977
|
}
|
|
978
|
+
|
|
979
|
+
// we don't export this since it's an internal action that is not meant to be used in the user's code
|
|
980
|
+
|
|
1451
981
|
function invoke({
|
|
1452
982
|
id,
|
|
1453
983
|
systemId,
|
|
@@ -1549,6 +1079,12 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
1549
1079
|
event,
|
|
1550
1080
|
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1551
1081
|
type: guard
|
|
1082
|
+
} : typeof guard.params === 'function' ? {
|
|
1083
|
+
type: guard.type,
|
|
1084
|
+
params: guard.params({
|
|
1085
|
+
context,
|
|
1086
|
+
event
|
|
1087
|
+
})
|
|
1552
1088
|
} : guard
|
|
1553
1089
|
};
|
|
1554
1090
|
if (!('check' in resolved)) {
|
|
@@ -1876,7 +1412,7 @@ function resolveTarget(stateNode, targets) {
|
|
|
1876
1412
|
});
|
|
1877
1413
|
}
|
|
1878
1414
|
function resolveHistoryTarget(stateNode) {
|
|
1879
|
-
const normalizedTarget = normalizeTarget(stateNode.target);
|
|
1415
|
+
const normalizedTarget = normalizeTarget(stateNode.config.target);
|
|
1880
1416
|
if (!normalizedTarget) {
|
|
1881
1417
|
return stateNode.parent.initial.target;
|
|
1882
1418
|
}
|
|
@@ -2365,7 +1901,15 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2365
1901
|
system: actorCtx?.system,
|
|
2366
1902
|
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2367
1903
|
type: action
|
|
2368
|
-
} : action
|
|
1904
|
+
} : typeof action.params === 'function' ? {
|
|
1905
|
+
type: action.type,
|
|
1906
|
+
params: action.params({
|
|
1907
|
+
context: intermediateState.context,
|
|
1908
|
+
event
|
|
1909
|
+
})
|
|
1910
|
+
} :
|
|
1911
|
+
// TS isn't able to narrow it down here
|
|
1912
|
+
action
|
|
2369
1913
|
};
|
|
2370
1914
|
if (!('resolve' in resolved)) {
|
|
2371
1915
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
@@ -2398,7 +1942,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
2398
1942
|
const states = [];
|
|
2399
1943
|
|
|
2400
1944
|
// Handle stop event
|
|
2401
|
-
if (event.type ===
|
|
1945
|
+
if (event.type === XSTATE_STOP) {
|
|
2402
1946
|
nextState = stopStep(event, nextState, actorCtx);
|
|
2403
1947
|
states.push(nextState);
|
|
2404
1948
|
return {
|
|
@@ -2410,7 +1954,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
2410
1954
|
|
|
2411
1955
|
// Assume the state is at rest (no raised events)
|
|
2412
1956
|
// Determine the next state based on the next microstep
|
|
2413
|
-
if (nextEvent.type !==
|
|
1957
|
+
if (nextEvent.type !== XSTATE_INIT) {
|
|
2414
1958
|
const transitions = selectTransitions(nextEvent, nextState);
|
|
2415
1959
|
nextState = microstep(transitions, state, actorCtx, nextEvent, false);
|
|
2416
1960
|
states.push(nextState);
|
|
@@ -2701,13 +2245,11 @@ function execute$2(actorContext, actorRef) {
|
|
|
2701
2245
|
actorContext.stopChild(actorRef);
|
|
2702
2246
|
});
|
|
2703
2247
|
}
|
|
2704
|
-
|
|
2705
2248
|
/**
|
|
2706
2249
|
* Stops an actor.
|
|
2707
2250
|
*
|
|
2708
2251
|
* @param actorRef The actor to stop.
|
|
2709
2252
|
*/
|
|
2710
|
-
|
|
2711
2253
|
function stop(actorRef) {
|
|
2712
2254
|
function stop(_) {
|
|
2713
2255
|
}
|
|
@@ -2739,7 +2281,6 @@ function execute$1({
|
|
|
2739
2281
|
logger(value);
|
|
2740
2282
|
}
|
|
2741
2283
|
}
|
|
2742
|
-
|
|
2743
2284
|
/**
|
|
2744
2285
|
*
|
|
2745
2286
|
* @param expr The expression function to evaluate which will be logged.
|
|
@@ -2854,7 +2395,6 @@ function resolve$3(actorContext, state, actionArgs, {
|
|
|
2854
2395
|
} : state.children
|
|
2855
2396
|
})];
|
|
2856
2397
|
}
|
|
2857
|
-
|
|
2858
2398
|
/**
|
|
2859
2399
|
* Updates the current context of the machine.
|
|
2860
2400
|
*
|
|
@@ -2900,14 +2440,12 @@ function execute(actorContext, params) {
|
|
|
2900
2440
|
return;
|
|
2901
2441
|
}
|
|
2902
2442
|
}
|
|
2903
|
-
|
|
2904
2443
|
/**
|
|
2905
2444
|
* Raises an event. This places the event in the internal event queue, so that
|
|
2906
2445
|
* the event is immediately consumed by the machine in the current step.
|
|
2907
2446
|
*
|
|
2908
2447
|
* @param eventType The event to raise.
|
|
2909
2448
|
*/
|
|
2910
|
-
|
|
2911
2449
|
function raise(eventOrExpr, options) {
|
|
2912
2450
|
function raise(_) {
|
|
2913
2451
|
}
|
|
@@ -2982,6 +2520,9 @@ function done(id, output) {
|
|
|
2982
2520
|
eventObject.toString = () => type;
|
|
2983
2521
|
return eventObject;
|
|
2984
2522
|
}
|
|
2523
|
+
function doneInvokeEventType(invokeId) {
|
|
2524
|
+
return `${ConstantPrefix.DoneInvoke}.${invokeId}`;
|
|
2525
|
+
}
|
|
2985
2526
|
|
|
2986
2527
|
/**
|
|
2987
2528
|
* Returns an event that represents that an invoked service has terminated.
|
|
@@ -2993,7 +2534,7 @@ function done(id, output) {
|
|
|
2993
2534
|
* @param output The data to pass into the event
|
|
2994
2535
|
*/
|
|
2995
2536
|
function doneInvoke(invokeId, output) {
|
|
2996
|
-
const type =
|
|
2537
|
+
const type = doneInvokeEventType(invokeId);
|
|
2997
2538
|
const eventObject = {
|
|
2998
2539
|
type,
|
|
2999
2540
|
output
|
|
@@ -3001,8 +2542,11 @@ function doneInvoke(invokeId, output) {
|
|
|
3001
2542
|
eventObject.toString = () => type;
|
|
3002
2543
|
return eventObject;
|
|
3003
2544
|
}
|
|
2545
|
+
function errorEventType(id) {
|
|
2546
|
+
return `${ConstantPrefix.ErrorPlatform}.${id}`;
|
|
2547
|
+
}
|
|
3004
2548
|
function error(id, data) {
|
|
3005
|
-
const type =
|
|
2549
|
+
const type = errorEventType(id);
|
|
3006
2550
|
const eventObject = {
|
|
3007
2551
|
type,
|
|
3008
2552
|
data
|
|
@@ -3012,7 +2556,7 @@ function error(id, data) {
|
|
|
3012
2556
|
}
|
|
3013
2557
|
function createInitEvent(input) {
|
|
3014
2558
|
return {
|
|
3015
|
-
type:
|
|
2559
|
+
type: XSTATE_INIT,
|
|
3016
2560
|
input
|
|
3017
2561
|
};
|
|
3018
2562
|
}
|
|
@@ -3025,6 +2569,8 @@ exports.NULL_EVENT = NULL_EVENT;
|
|
|
3025
2569
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
3026
2570
|
exports.SpecialTargets = SpecialTargets;
|
|
3027
2571
|
exports.State = State;
|
|
2572
|
+
exports.XSTATE_INIT = XSTATE_INIT;
|
|
2573
|
+
exports.XSTATE_STOP = XSTATE_STOP;
|
|
3028
2574
|
exports.after = after;
|
|
3029
2575
|
exports.and = and;
|
|
3030
2576
|
exports.assign = assign;
|
|
@@ -3033,24 +2579,19 @@ exports.choose = choose;
|
|
|
3033
2579
|
exports.cloneState = cloneState;
|
|
3034
2580
|
exports.constantPrefixes = constantPrefixes;
|
|
3035
2581
|
exports.createActor = createActor;
|
|
3036
|
-
exports.createEmptyActor = createEmptyActor;
|
|
3037
2582
|
exports.createInitEvent = createInitEvent;
|
|
3038
2583
|
exports.createInvokeId = createInvokeId;
|
|
3039
2584
|
exports.done = done;
|
|
3040
2585
|
exports.doneInvoke = doneInvoke;
|
|
2586
|
+
exports.doneInvokeEventType = doneInvokeEventType;
|
|
3041
2587
|
exports.error = error;
|
|
2588
|
+
exports.errorEventType = errorEventType;
|
|
3042
2589
|
exports.escalate = escalate;
|
|
3043
2590
|
exports.evaluateGuard = evaluateGuard;
|
|
3044
|
-
exports.flatten = flatten;
|
|
3045
2591
|
exports.formatInitialTransition = formatInitialTransition;
|
|
3046
2592
|
exports.formatTransition = formatTransition;
|
|
3047
2593
|
exports.formatTransitions = formatTransitions;
|
|
3048
2594
|
exports.forwardTo = forwardTo;
|
|
3049
|
-
exports.fromCallback = fromCallback;
|
|
3050
|
-
exports.fromEventObservable = fromEventObservable;
|
|
3051
|
-
exports.fromObservable = fromObservable;
|
|
3052
|
-
exports.fromPromise = fromPromise;
|
|
3053
|
-
exports.fromTransition = fromTransition;
|
|
3054
2595
|
exports.getCandidates = getCandidates;
|
|
3055
2596
|
exports.getConfiguration = getConfiguration;
|
|
3056
2597
|
exports.getDelayedTransitions = getDelayedTransitions;
|
|
@@ -3059,11 +2600,10 @@ exports.getPersistedState = getPersistedState;
|
|
|
3059
2600
|
exports.getStateNodeByPath = getStateNodeByPath;
|
|
3060
2601
|
exports.getStateNodes = getStateNodes;
|
|
3061
2602
|
exports.interpret = interpret;
|
|
3062
|
-
exports.isActorRef = isActorRef;
|
|
3063
2603
|
exports.isAtomicStateNode = isAtomicStateNode;
|
|
3064
2604
|
exports.isErrorEvent = isErrorEvent;
|
|
3065
2605
|
exports.isInFinalState = isInFinalState;
|
|
3066
|
-
exports.
|
|
2606
|
+
exports.isPromiseLike = isPromiseLike;
|
|
3067
2607
|
exports.isStateId = isStateId;
|
|
3068
2608
|
exports.log = log;
|
|
3069
2609
|
exports.macrostep = macrostep;
|
|
@@ -3081,15 +2621,10 @@ exports.resolveReferencedActor = resolveReferencedActor;
|
|
|
3081
2621
|
exports.resolveStateValue = resolveStateValue;
|
|
3082
2622
|
exports.sendParent = sendParent;
|
|
3083
2623
|
exports.sendTo = sendTo;
|
|
3084
|
-
exports.startSignal = startSignal;
|
|
3085
|
-
exports.startSignalType = startSignalType;
|
|
3086
2624
|
exports.stateIn = stateIn;
|
|
3087
2625
|
exports.stop = stop;
|
|
3088
|
-
exports.
|
|
3089
|
-
exports.stopSignalType = stopSignalType;
|
|
3090
|
-
exports.toActorRef = toActorRef;
|
|
2626
|
+
exports.symbolObservable = symbolObservable;
|
|
3091
2627
|
exports.toArray = toArray;
|
|
3092
|
-
exports.toInvokeConfig = toInvokeConfig;
|
|
3093
2628
|
exports.toObserver = toObserver;
|
|
3094
2629
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
3095
2630
|
exports.transitionNode = transitionNode;
|