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
|
*
|
|
@@ -230,7 +230,6 @@ function resolve$7(_, state, actionArgs, {
|
|
|
230
230
|
function execute$4(actorContext, resolvedSendId) {
|
|
231
231
|
actorContext.self.cancel(resolvedSendId);
|
|
232
232
|
}
|
|
233
|
-
|
|
234
233
|
/**
|
|
235
234
|
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
236
235
|
* be executed, nor will its event be sent, unless it has already been sent
|
|
@@ -318,32 +317,53 @@ class Mailbox {
|
|
|
318
317
|
}
|
|
319
318
|
}
|
|
320
319
|
|
|
321
|
-
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
322
|
-
|
|
323
320
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
321
|
+
* This function makes sure that unhandled errors are thrown in a separate macrotask.
|
|
322
|
+
* It allows those errors to be detected by global error handlers and reported to bug tracking services
|
|
323
|
+
* without interrupting our own stack of execution.
|
|
327
324
|
*
|
|
328
|
-
* @param
|
|
329
|
-
* @param initialState The initial state of the transition function.
|
|
330
|
-
* @returns Actor logic
|
|
325
|
+
* @param err error to be thrown
|
|
331
326
|
*/
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
327
|
+
function reportUnhandledError(err) {
|
|
328
|
+
setTimeout(() => {
|
|
329
|
+
throw err;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
334
|
+
|
|
335
|
+
function createSystem() {
|
|
336
|
+
let sessionIdCounter = 0;
|
|
337
|
+
const children = new Map();
|
|
338
|
+
const keyedActors = new Map();
|
|
339
|
+
const reverseKeyedActors = new WeakMap();
|
|
340
|
+
const system = {
|
|
341
|
+
_bookId: () => `x:${sessionIdCounter++}`,
|
|
342
|
+
_register: (sessionId, actorRef) => {
|
|
343
|
+
children.set(sessionId, actorRef);
|
|
344
|
+
return sessionId;
|
|
345
|
+
},
|
|
346
|
+
_unregister: actorRef => {
|
|
347
|
+
children.delete(actorRef.sessionId);
|
|
348
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
349
|
+
if (systemId !== undefined) {
|
|
350
|
+
keyedActors.delete(systemId);
|
|
351
|
+
reverseKeyedActors.delete(actorRef);
|
|
352
|
+
}
|
|
337
353
|
},
|
|
338
|
-
|
|
339
|
-
return
|
|
340
|
-
input
|
|
341
|
-
}) : initialState;
|
|
354
|
+
get: systemId => {
|
|
355
|
+
return keyedActors.get(systemId);
|
|
342
356
|
},
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
357
|
+
_set: (systemId, actorRef) => {
|
|
358
|
+
const existing = keyedActors.get(systemId);
|
|
359
|
+
if (existing && existing !== actorRef) {
|
|
360
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
361
|
+
}
|
|
362
|
+
keyedActors.set(systemId, actorRef);
|
|
363
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
364
|
+
}
|
|
346
365
|
};
|
|
366
|
+
return system;
|
|
347
367
|
}
|
|
348
368
|
|
|
349
369
|
function matchesState(parentStateId, childStateId) {
|
|
@@ -479,23 +499,6 @@ function normalizeTarget(target) {
|
|
|
479
499
|
}
|
|
480
500
|
return toArray(target);
|
|
481
501
|
}
|
|
482
|
-
function toInvokeConfig(invocable, id) {
|
|
483
|
-
if (typeof invocable === 'object') {
|
|
484
|
-
if ('src' in invocable) {
|
|
485
|
-
return invocable;
|
|
486
|
-
}
|
|
487
|
-
if ('transition' in invocable) {
|
|
488
|
-
return {
|
|
489
|
-
id,
|
|
490
|
-
src: invocable
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
return {
|
|
495
|
-
id,
|
|
496
|
-
src: invocable
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
502
|
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
500
503
|
const isObserver = typeof nextHandler === 'object';
|
|
501
504
|
const self = isObserver ? nextHandler : undefined;
|
|
@@ -515,482 +518,6 @@ function resolveReferencedActor(referenced) {
|
|
|
515
518
|
} : referenced : undefined;
|
|
516
519
|
}
|
|
517
520
|
|
|
518
|
-
function fromCallback(invokeCallback) {
|
|
519
|
-
return {
|
|
520
|
-
config: invokeCallback,
|
|
521
|
-
start: (_state, {
|
|
522
|
-
self
|
|
523
|
-
}) => {
|
|
524
|
-
self.send({
|
|
525
|
-
type: startSignalType
|
|
526
|
-
});
|
|
527
|
-
},
|
|
528
|
-
transition: (state, event, {
|
|
529
|
-
self,
|
|
530
|
-
id,
|
|
531
|
-
system
|
|
532
|
-
}) => {
|
|
533
|
-
if (event.type === startSignalType) {
|
|
534
|
-
const sendBack = eventForParent => {
|
|
535
|
-
if (state.canceled) {
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
self._parent?.send(eventForParent);
|
|
539
|
-
};
|
|
540
|
-
const receive = newListener => {
|
|
541
|
-
state.receivers.add(newListener);
|
|
542
|
-
};
|
|
543
|
-
state.dispose = invokeCallback({
|
|
544
|
-
input: state.input,
|
|
545
|
-
system,
|
|
546
|
-
self: self,
|
|
547
|
-
sendBack,
|
|
548
|
-
receive
|
|
549
|
-
});
|
|
550
|
-
if (isPromiseLike(state.dispose)) {
|
|
551
|
-
state.dispose.then(resolved => {
|
|
552
|
-
self._parent?.send(doneInvoke(id, resolved));
|
|
553
|
-
state.canceled = true;
|
|
554
|
-
}, errorData => {
|
|
555
|
-
state.canceled = true;
|
|
556
|
-
self._parent?.send(error(id, errorData));
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
return state;
|
|
560
|
-
}
|
|
561
|
-
if (event.type === stopSignalType) {
|
|
562
|
-
state.canceled = true;
|
|
563
|
-
if (typeof state.dispose === 'function') {
|
|
564
|
-
state.dispose();
|
|
565
|
-
}
|
|
566
|
-
return state;
|
|
567
|
-
}
|
|
568
|
-
if (isSignal(event)) {
|
|
569
|
-
// TODO: unrecognized signal
|
|
570
|
-
return state;
|
|
571
|
-
}
|
|
572
|
-
state.receivers.forEach(receiver => receiver(event));
|
|
573
|
-
return state;
|
|
574
|
-
},
|
|
575
|
-
getInitialState: (_, input) => {
|
|
576
|
-
return {
|
|
577
|
-
canceled: false,
|
|
578
|
-
receivers: new Set(),
|
|
579
|
-
dispose: undefined,
|
|
580
|
-
input
|
|
581
|
-
};
|
|
582
|
-
},
|
|
583
|
-
getSnapshot: () => undefined,
|
|
584
|
-
getPersistedState: ({
|
|
585
|
-
input,
|
|
586
|
-
canceled
|
|
587
|
-
}) => ({
|
|
588
|
-
input,
|
|
589
|
-
canceled
|
|
590
|
-
})
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
function fromObservable(observableCreator) {
|
|
595
|
-
const nextEventType = '$$xstate.next';
|
|
596
|
-
const errorEventType = '$$xstate.error';
|
|
597
|
-
const completeEventType = '$$xstate.complete';
|
|
598
|
-
return {
|
|
599
|
-
config: observableCreator,
|
|
600
|
-
transition: (state, event, {
|
|
601
|
-
self,
|
|
602
|
-
id,
|
|
603
|
-
defer
|
|
604
|
-
}) => {
|
|
605
|
-
if (state.status !== 'active') {
|
|
606
|
-
return state;
|
|
607
|
-
}
|
|
608
|
-
switch (event.type) {
|
|
609
|
-
case nextEventType:
|
|
610
|
-
// match the exact timing of events sent by machines
|
|
611
|
-
// send actions are not executed immediately
|
|
612
|
-
defer(() => {
|
|
613
|
-
self._parent?.send({
|
|
614
|
-
type: `xstate.snapshot.${id}`,
|
|
615
|
-
data: event.data
|
|
616
|
-
});
|
|
617
|
-
});
|
|
618
|
-
return {
|
|
619
|
-
...state,
|
|
620
|
-
data: event.data
|
|
621
|
-
};
|
|
622
|
-
case errorEventType:
|
|
623
|
-
return {
|
|
624
|
-
...state,
|
|
625
|
-
status: 'error',
|
|
626
|
-
input: undefined,
|
|
627
|
-
data: event.data,
|
|
628
|
-
// TODO: if we keep this as `data` we should reflect this in the type
|
|
629
|
-
subscription: undefined
|
|
630
|
-
};
|
|
631
|
-
case completeEventType:
|
|
632
|
-
return {
|
|
633
|
-
...state,
|
|
634
|
-
status: 'done',
|
|
635
|
-
input: undefined,
|
|
636
|
-
subscription: undefined
|
|
637
|
-
};
|
|
638
|
-
case stopSignalType:
|
|
639
|
-
state.subscription.unsubscribe();
|
|
640
|
-
return {
|
|
641
|
-
...state,
|
|
642
|
-
status: 'canceled',
|
|
643
|
-
input: undefined,
|
|
644
|
-
subscription: undefined
|
|
645
|
-
};
|
|
646
|
-
default:
|
|
647
|
-
return state;
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
getInitialState: (_, input) => {
|
|
651
|
-
return {
|
|
652
|
-
subscription: undefined,
|
|
653
|
-
status: 'active',
|
|
654
|
-
data: undefined,
|
|
655
|
-
input
|
|
656
|
-
};
|
|
657
|
-
},
|
|
658
|
-
start: (state, {
|
|
659
|
-
self,
|
|
660
|
-
system
|
|
661
|
-
}) => {
|
|
662
|
-
if (state.status === 'done') {
|
|
663
|
-
// Do not restart a completed observable
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
state.subscription = observableCreator({
|
|
667
|
-
input: state.input,
|
|
668
|
-
system,
|
|
669
|
-
self
|
|
670
|
-
}).subscribe({
|
|
671
|
-
next: value => {
|
|
672
|
-
self.send({
|
|
673
|
-
type: nextEventType,
|
|
674
|
-
data: value
|
|
675
|
-
});
|
|
676
|
-
},
|
|
677
|
-
error: err => {
|
|
678
|
-
self.send({
|
|
679
|
-
type: errorEventType,
|
|
680
|
-
data: err
|
|
681
|
-
});
|
|
682
|
-
},
|
|
683
|
-
complete: () => {
|
|
684
|
-
self.send({
|
|
685
|
-
type: completeEventType
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
},
|
|
690
|
-
getSnapshot: state => state.data,
|
|
691
|
-
getPersistedState: ({
|
|
692
|
-
status,
|
|
693
|
-
data,
|
|
694
|
-
input
|
|
695
|
-
}) => ({
|
|
696
|
-
status,
|
|
697
|
-
data,
|
|
698
|
-
input
|
|
699
|
-
}),
|
|
700
|
-
getStatus: state => state,
|
|
701
|
-
restoreState: state => ({
|
|
702
|
-
...state,
|
|
703
|
-
subscription: undefined
|
|
704
|
-
})
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Creates event observable logic that listens to an observable
|
|
710
|
-
* that delivers event objects.
|
|
711
|
-
*
|
|
712
|
-
*
|
|
713
|
-
* @param lazyObservable A function that creates an observable
|
|
714
|
-
* @returns Event observable logic
|
|
715
|
-
*/
|
|
716
|
-
|
|
717
|
-
function fromEventObservable(lazyObservable) {
|
|
718
|
-
const errorEventType = '$$xstate.error';
|
|
719
|
-
const completeEventType = '$$xstate.complete';
|
|
720
|
-
|
|
721
|
-
// TODO: event types
|
|
722
|
-
return {
|
|
723
|
-
config: lazyObservable,
|
|
724
|
-
transition: (state, event) => {
|
|
725
|
-
if (state.status !== 'active') {
|
|
726
|
-
return state;
|
|
727
|
-
}
|
|
728
|
-
switch (event.type) {
|
|
729
|
-
case errorEventType:
|
|
730
|
-
return {
|
|
731
|
-
...state,
|
|
732
|
-
status: 'error',
|
|
733
|
-
input: undefined,
|
|
734
|
-
data: event.data,
|
|
735
|
-
// TODO: if we keep this as `data` we should reflect this in the type
|
|
736
|
-
subscription: undefined
|
|
737
|
-
};
|
|
738
|
-
case completeEventType:
|
|
739
|
-
return {
|
|
740
|
-
...state,
|
|
741
|
-
status: 'done',
|
|
742
|
-
input: undefined,
|
|
743
|
-
subscription: undefined
|
|
744
|
-
};
|
|
745
|
-
case stopSignalType:
|
|
746
|
-
state.subscription.unsubscribe();
|
|
747
|
-
return {
|
|
748
|
-
...state,
|
|
749
|
-
status: 'canceled',
|
|
750
|
-
input: undefined,
|
|
751
|
-
subscription: undefined
|
|
752
|
-
};
|
|
753
|
-
default:
|
|
754
|
-
return state;
|
|
755
|
-
}
|
|
756
|
-
},
|
|
757
|
-
getInitialState: (_, input) => {
|
|
758
|
-
return {
|
|
759
|
-
subscription: undefined,
|
|
760
|
-
status: 'active',
|
|
761
|
-
data: undefined,
|
|
762
|
-
input
|
|
763
|
-
};
|
|
764
|
-
},
|
|
765
|
-
start: (state, {
|
|
766
|
-
self,
|
|
767
|
-
system
|
|
768
|
-
}) => {
|
|
769
|
-
if (state.status === 'done') {
|
|
770
|
-
// Do not restart a completed observable
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
state.subscription = lazyObservable({
|
|
774
|
-
input: state.input,
|
|
775
|
-
system,
|
|
776
|
-
self
|
|
777
|
-
}).subscribe({
|
|
778
|
-
next: value => {
|
|
779
|
-
self._parent?.send(value);
|
|
780
|
-
},
|
|
781
|
-
error: err => {
|
|
782
|
-
self.send({
|
|
783
|
-
type: errorEventType,
|
|
784
|
-
data: err
|
|
785
|
-
});
|
|
786
|
-
},
|
|
787
|
-
complete: () => {
|
|
788
|
-
self.send({
|
|
789
|
-
type: completeEventType
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
},
|
|
794
|
-
getSnapshot: _ => undefined,
|
|
795
|
-
getPersistedState: ({
|
|
796
|
-
status,
|
|
797
|
-
data,
|
|
798
|
-
input
|
|
799
|
-
}) => ({
|
|
800
|
-
status,
|
|
801
|
-
data,
|
|
802
|
-
input
|
|
803
|
-
}),
|
|
804
|
-
getStatus: state => state,
|
|
805
|
-
restoreState: state => ({
|
|
806
|
-
...state,
|
|
807
|
-
subscription: undefined
|
|
808
|
-
})
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
const resolveEventType = '$$xstate.resolve';
|
|
813
|
-
const rejectEventType = '$$xstate.reject';
|
|
814
|
-
function fromPromise(
|
|
815
|
-
// TODO: add types
|
|
816
|
-
promiseCreator) {
|
|
817
|
-
// TODO: add event types
|
|
818
|
-
const logic = {
|
|
819
|
-
config: promiseCreator,
|
|
820
|
-
transition: (state, event) => {
|
|
821
|
-
if (state.status !== 'active') {
|
|
822
|
-
return state;
|
|
823
|
-
}
|
|
824
|
-
switch (event.type) {
|
|
825
|
-
case resolveEventType:
|
|
826
|
-
return {
|
|
827
|
-
...state,
|
|
828
|
-
status: 'done',
|
|
829
|
-
data: event.data,
|
|
830
|
-
input: undefined
|
|
831
|
-
};
|
|
832
|
-
case rejectEventType:
|
|
833
|
-
return {
|
|
834
|
-
...state,
|
|
835
|
-
status: 'error',
|
|
836
|
-
data: event.data,
|
|
837
|
-
// TODO: if we keep this as `data` we should reflect this in the type
|
|
838
|
-
input: undefined
|
|
839
|
-
};
|
|
840
|
-
case stopSignalType:
|
|
841
|
-
return {
|
|
842
|
-
...state,
|
|
843
|
-
status: 'canceled',
|
|
844
|
-
input: undefined
|
|
845
|
-
};
|
|
846
|
-
default:
|
|
847
|
-
return state;
|
|
848
|
-
}
|
|
849
|
-
},
|
|
850
|
-
start: (state, {
|
|
851
|
-
self,
|
|
852
|
-
system
|
|
853
|
-
}) => {
|
|
854
|
-
// TODO: determine how to allow customizing this so that promises
|
|
855
|
-
// can be restarted if necessary
|
|
856
|
-
if (state.status !== 'active') {
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
const resolvedPromise = Promise.resolve(promiseCreator({
|
|
860
|
-
input: state.input,
|
|
861
|
-
system,
|
|
862
|
-
self
|
|
863
|
-
}));
|
|
864
|
-
resolvedPromise.then(response => {
|
|
865
|
-
// TODO: remove this condition once dead letter queue lands
|
|
866
|
-
if (self._state.status !== 'active') {
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
self.send({
|
|
870
|
-
type: resolveEventType,
|
|
871
|
-
data: response
|
|
872
|
-
});
|
|
873
|
-
}, errorData => {
|
|
874
|
-
// TODO: remove this condition once dead letter queue lands
|
|
875
|
-
if (self._state.status !== 'active') {
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
self.send({
|
|
879
|
-
type: rejectEventType,
|
|
880
|
-
data: errorData
|
|
881
|
-
});
|
|
882
|
-
});
|
|
883
|
-
},
|
|
884
|
-
getInitialState: (_, input) => {
|
|
885
|
-
return {
|
|
886
|
-
status: 'active',
|
|
887
|
-
data: undefined,
|
|
888
|
-
input
|
|
889
|
-
};
|
|
890
|
-
},
|
|
891
|
-
getSnapshot: state => state.data,
|
|
892
|
-
getStatus: state => state,
|
|
893
|
-
getPersistedState: state => state,
|
|
894
|
-
restoreState: state => state
|
|
895
|
-
};
|
|
896
|
-
return logic;
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
const startSignalType = 'xstate.init';
|
|
900
|
-
const stopSignalType = 'xstate.stop';
|
|
901
|
-
const startSignal = {
|
|
902
|
-
type: 'xstate.init'
|
|
903
|
-
};
|
|
904
|
-
const stopSignal = {
|
|
905
|
-
type: 'xstate.stop'
|
|
906
|
-
};
|
|
907
|
-
/**
|
|
908
|
-
* An object that expresses the actor logic in reaction to received events,
|
|
909
|
-
* as well as an optionally emitted stream of values.
|
|
910
|
-
*
|
|
911
|
-
* @template TReceived The received event
|
|
912
|
-
* @template TSnapshot The emitted value
|
|
913
|
-
*/
|
|
914
|
-
|
|
915
|
-
function isSignal(event) {
|
|
916
|
-
return event.type === startSignalType || event.type === stopSignalType;
|
|
917
|
-
}
|
|
918
|
-
function isActorRef(item) {
|
|
919
|
-
return !!item && typeof item === 'object' && typeof item.send === 'function';
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
// TODO: refactor the return type, this could be written in a better way
|
|
923
|
-
// but it's best to avoid unneccessary breaking changes now
|
|
924
|
-
// @deprecated use `interpret(actorLogic)` instead
|
|
925
|
-
function toActorRef(actorRefLike) {
|
|
926
|
-
return {
|
|
927
|
-
subscribe: () => ({
|
|
928
|
-
unsubscribe: () => void 0
|
|
929
|
-
}),
|
|
930
|
-
id: 'anonymous',
|
|
931
|
-
sessionId: '',
|
|
932
|
-
getSnapshot: () => undefined,
|
|
933
|
-
// TODO: this isn't safe
|
|
934
|
-
[symbolObservable]: function () {
|
|
935
|
-
return this;
|
|
936
|
-
},
|
|
937
|
-
status: ActorStatus.Running,
|
|
938
|
-
stop: () => void 0,
|
|
939
|
-
...actorRefLike
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
const emptyLogic = fromTransition(_ => undefined, undefined);
|
|
943
|
-
function createEmptyActor() {
|
|
944
|
-
return createActor(emptyLogic);
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* This function makes sure that unhandled errors are thrown in a separate macrotask.
|
|
949
|
-
* It allows those errors to be detected by global error handlers and reported to bug tracking services
|
|
950
|
-
* without interrupting our own stack of execution.
|
|
951
|
-
*
|
|
952
|
-
* @param err error to be thrown
|
|
953
|
-
*/
|
|
954
|
-
function reportUnhandledError(err) {
|
|
955
|
-
setTimeout(() => {
|
|
956
|
-
throw err;
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
function createSystem() {
|
|
961
|
-
let sessionIdCounter = 0;
|
|
962
|
-
const children = new Map();
|
|
963
|
-
const keyedActors = new Map();
|
|
964
|
-
const reverseKeyedActors = new WeakMap();
|
|
965
|
-
const system = {
|
|
966
|
-
_bookId: () => `x:${sessionIdCounter++}`,
|
|
967
|
-
_register: (sessionId, actorRef) => {
|
|
968
|
-
children.set(sessionId, actorRef);
|
|
969
|
-
return sessionId;
|
|
970
|
-
},
|
|
971
|
-
_unregister: actorRef => {
|
|
972
|
-
children.delete(actorRef.sessionId);
|
|
973
|
-
const systemId = reverseKeyedActors.get(actorRef);
|
|
974
|
-
if (systemId !== undefined) {
|
|
975
|
-
keyedActors.delete(systemId);
|
|
976
|
-
reverseKeyedActors.delete(actorRef);
|
|
977
|
-
}
|
|
978
|
-
},
|
|
979
|
-
get: systemId => {
|
|
980
|
-
return keyedActors.get(systemId);
|
|
981
|
-
},
|
|
982
|
-
_set: (systemId, actorRef) => {
|
|
983
|
-
const existing = keyedActors.get(systemId);
|
|
984
|
-
if (existing && existing !== actorRef) {
|
|
985
|
-
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
986
|
-
}
|
|
987
|
-
keyedActors.set(systemId, actorRef);
|
|
988
|
-
reverseKeyedActors.set(actorRef, systemId);
|
|
989
|
-
}
|
|
990
|
-
};
|
|
991
|
-
return system;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
521
|
let ActorStatus = /*#__PURE__*/function (ActorStatus) {
|
|
995
522
|
ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
|
|
996
523
|
ActorStatus[ActorStatus["Running"] = 1] = "Running";
|
|
@@ -1237,7 +764,7 @@ class Actor {
|
|
|
1237
764
|
return;
|
|
1238
765
|
}
|
|
1239
766
|
this.update(nextState);
|
|
1240
|
-
if (event.type ===
|
|
767
|
+
if (event.type === XSTATE_STOP) {
|
|
1241
768
|
this._stopProcedure();
|
|
1242
769
|
this._complete();
|
|
1243
770
|
}
|
|
@@ -1252,7 +779,7 @@ class Actor {
|
|
|
1252
779
|
return this;
|
|
1253
780
|
}
|
|
1254
781
|
this.mailbox.enqueue({
|
|
1255
|
-
type:
|
|
782
|
+
type: XSTATE_STOP
|
|
1256
783
|
});
|
|
1257
784
|
return this;
|
|
1258
785
|
}
|
|
@@ -1475,6 +1002,9 @@ function execute$3(actorContext, {
|
|
|
1475
1002
|
}
|
|
1476
1003
|
});
|
|
1477
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
// we don't export this since it's an internal action that is not meant to be used in the user's code
|
|
1007
|
+
|
|
1478
1008
|
function invoke({
|
|
1479
1009
|
id,
|
|
1480
1010
|
systemId,
|
|
@@ -1587,6 +1117,12 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
1587
1117
|
event,
|
|
1588
1118
|
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1589
1119
|
type: guard
|
|
1120
|
+
} : typeof guard.params === 'function' ? {
|
|
1121
|
+
type: guard.type,
|
|
1122
|
+
params: guard.params({
|
|
1123
|
+
context,
|
|
1124
|
+
event
|
|
1125
|
+
})
|
|
1590
1126
|
} : guard
|
|
1591
1127
|
};
|
|
1592
1128
|
if (!('check' in resolved)) {
|
|
@@ -1925,7 +1461,7 @@ function resolveTarget(stateNode, targets) {
|
|
|
1925
1461
|
});
|
|
1926
1462
|
}
|
|
1927
1463
|
function resolveHistoryTarget(stateNode) {
|
|
1928
|
-
const normalizedTarget = normalizeTarget(stateNode.target);
|
|
1464
|
+
const normalizedTarget = normalizeTarget(stateNode.config.target);
|
|
1929
1465
|
if (!normalizedTarget) {
|
|
1930
1466
|
return stateNode.parent.initial.target;
|
|
1931
1467
|
}
|
|
@@ -2414,7 +1950,15 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2414
1950
|
system: actorCtx?.system,
|
|
2415
1951
|
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2416
1952
|
type: action
|
|
2417
|
-
} : action
|
|
1953
|
+
} : typeof action.params === 'function' ? {
|
|
1954
|
+
type: action.type,
|
|
1955
|
+
params: action.params({
|
|
1956
|
+
context: intermediateState.context,
|
|
1957
|
+
event
|
|
1958
|
+
})
|
|
1959
|
+
} :
|
|
1960
|
+
// TS isn't able to narrow it down here
|
|
1961
|
+
action
|
|
2418
1962
|
};
|
|
2419
1963
|
if (!('resolve' in resolved)) {
|
|
2420
1964
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
@@ -2450,7 +1994,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
2450
1994
|
const states = [];
|
|
2451
1995
|
|
|
2452
1996
|
// Handle stop event
|
|
2453
|
-
if (event.type ===
|
|
1997
|
+
if (event.type === XSTATE_STOP) {
|
|
2454
1998
|
nextState = stopStep(event, nextState, actorCtx);
|
|
2455
1999
|
states.push(nextState);
|
|
2456
2000
|
return {
|
|
@@ -2462,7 +2006,7 @@ function macrostep(state, event, actorCtx) {
|
|
|
2462
2006
|
|
|
2463
2007
|
// Assume the state is at rest (no raised events)
|
|
2464
2008
|
// Determine the next state based on the next microstep
|
|
2465
|
-
if (nextEvent.type !==
|
|
2009
|
+
if (nextEvent.type !== XSTATE_INIT) {
|
|
2466
2010
|
const transitions = selectTransitions(nextEvent, nextState);
|
|
2467
2011
|
nextState = microstep(transitions, state, actorCtx, nextEvent, false);
|
|
2468
2012
|
states.push(nextState);
|
|
@@ -2756,13 +2300,11 @@ function execute$2(actorContext, actorRef) {
|
|
|
2756
2300
|
actorContext.stopChild(actorRef);
|
|
2757
2301
|
});
|
|
2758
2302
|
}
|
|
2759
|
-
|
|
2760
2303
|
/**
|
|
2761
2304
|
* Stops an actor.
|
|
2762
2305
|
*
|
|
2763
2306
|
* @param actorRef The actor to stop.
|
|
2764
2307
|
*/
|
|
2765
|
-
|
|
2766
2308
|
function stop(actorRef) {
|
|
2767
2309
|
function stop(_) {
|
|
2768
2310
|
{
|
|
@@ -2797,7 +2339,6 @@ function execute$1({
|
|
|
2797
2339
|
logger(value);
|
|
2798
2340
|
}
|
|
2799
2341
|
}
|
|
2800
|
-
|
|
2801
2342
|
/**
|
|
2802
2343
|
*
|
|
2803
2344
|
* @param expr The expression function to evaluate which will be logged.
|
|
@@ -2915,7 +2456,6 @@ function resolve$3(actorContext, state, actionArgs, {
|
|
|
2915
2456
|
} : state.children
|
|
2916
2457
|
})];
|
|
2917
2458
|
}
|
|
2918
|
-
|
|
2919
2459
|
/**
|
|
2920
2460
|
* Updates the current context of the machine.
|
|
2921
2461
|
*
|
|
@@ -2964,14 +2504,12 @@ function execute(actorContext, params) {
|
|
|
2964
2504
|
return;
|
|
2965
2505
|
}
|
|
2966
2506
|
}
|
|
2967
|
-
|
|
2968
2507
|
/**
|
|
2969
2508
|
* Raises an event. This places the event in the internal event queue, so that
|
|
2970
2509
|
* the event is immediately consumed by the machine in the current step.
|
|
2971
2510
|
*
|
|
2972
2511
|
* @param eventType The event to raise.
|
|
2973
2512
|
*/
|
|
2974
|
-
|
|
2975
2513
|
function raise(eventOrExpr, options) {
|
|
2976
2514
|
function raise(_) {
|
|
2977
2515
|
{
|
|
@@ -3055,6 +2593,9 @@ function done(id, output) {
|
|
|
3055
2593
|
eventObject.toString = () => type;
|
|
3056
2594
|
return eventObject;
|
|
3057
2595
|
}
|
|
2596
|
+
function doneInvokeEventType(invokeId) {
|
|
2597
|
+
return `${ConstantPrefix.DoneInvoke}.${invokeId}`;
|
|
2598
|
+
}
|
|
3058
2599
|
|
|
3059
2600
|
/**
|
|
3060
2601
|
* Returns an event that represents that an invoked service has terminated.
|
|
@@ -3066,7 +2607,7 @@ function done(id, output) {
|
|
|
3066
2607
|
* @param output The data to pass into the event
|
|
3067
2608
|
*/
|
|
3068
2609
|
function doneInvoke(invokeId, output) {
|
|
3069
|
-
const type =
|
|
2610
|
+
const type = doneInvokeEventType(invokeId);
|
|
3070
2611
|
const eventObject = {
|
|
3071
2612
|
type,
|
|
3072
2613
|
output
|
|
@@ -3074,8 +2615,11 @@ function doneInvoke(invokeId, output) {
|
|
|
3074
2615
|
eventObject.toString = () => type;
|
|
3075
2616
|
return eventObject;
|
|
3076
2617
|
}
|
|
2618
|
+
function errorEventType(id) {
|
|
2619
|
+
return `${ConstantPrefix.ErrorPlatform}.${id}`;
|
|
2620
|
+
}
|
|
3077
2621
|
function error(id, data) {
|
|
3078
|
-
const type =
|
|
2622
|
+
const type = errorEventType(id);
|
|
3079
2623
|
const eventObject = {
|
|
3080
2624
|
type,
|
|
3081
2625
|
data
|
|
@@ -3085,7 +2629,7 @@ function error(id, data) {
|
|
|
3085
2629
|
}
|
|
3086
2630
|
function createInitEvent(input) {
|
|
3087
2631
|
return {
|
|
3088
|
-
type:
|
|
2632
|
+
type: XSTATE_INIT,
|
|
3089
2633
|
input
|
|
3090
2634
|
};
|
|
3091
2635
|
}
|
|
@@ -3098,6 +2642,8 @@ exports.NULL_EVENT = NULL_EVENT;
|
|
|
3098
2642
|
exports.STATE_DELIMITER = STATE_DELIMITER;
|
|
3099
2643
|
exports.SpecialTargets = SpecialTargets;
|
|
3100
2644
|
exports.State = State;
|
|
2645
|
+
exports.XSTATE_INIT = XSTATE_INIT;
|
|
2646
|
+
exports.XSTATE_STOP = XSTATE_STOP;
|
|
3101
2647
|
exports.after = after;
|
|
3102
2648
|
exports.and = and;
|
|
3103
2649
|
exports.assign = assign;
|
|
@@ -3106,24 +2652,19 @@ exports.choose = choose;
|
|
|
3106
2652
|
exports.cloneState = cloneState;
|
|
3107
2653
|
exports.constantPrefixes = constantPrefixes;
|
|
3108
2654
|
exports.createActor = createActor;
|
|
3109
|
-
exports.createEmptyActor = createEmptyActor;
|
|
3110
2655
|
exports.createInitEvent = createInitEvent;
|
|
3111
2656
|
exports.createInvokeId = createInvokeId;
|
|
3112
2657
|
exports.done = done;
|
|
3113
2658
|
exports.doneInvoke = doneInvoke;
|
|
2659
|
+
exports.doneInvokeEventType = doneInvokeEventType;
|
|
3114
2660
|
exports.error = error;
|
|
2661
|
+
exports.errorEventType = errorEventType;
|
|
3115
2662
|
exports.escalate = escalate;
|
|
3116
2663
|
exports.evaluateGuard = evaluateGuard;
|
|
3117
|
-
exports.flatten = flatten;
|
|
3118
2664
|
exports.formatInitialTransition = formatInitialTransition;
|
|
3119
2665
|
exports.formatTransition = formatTransition;
|
|
3120
2666
|
exports.formatTransitions = formatTransitions;
|
|
3121
2667
|
exports.forwardTo = forwardTo;
|
|
3122
|
-
exports.fromCallback = fromCallback;
|
|
3123
|
-
exports.fromEventObservable = fromEventObservable;
|
|
3124
|
-
exports.fromObservable = fromObservable;
|
|
3125
|
-
exports.fromPromise = fromPromise;
|
|
3126
|
-
exports.fromTransition = fromTransition;
|
|
3127
2668
|
exports.getCandidates = getCandidates;
|
|
3128
2669
|
exports.getConfiguration = getConfiguration;
|
|
3129
2670
|
exports.getDelayedTransitions = getDelayedTransitions;
|
|
@@ -3132,11 +2673,10 @@ exports.getPersistedState = getPersistedState;
|
|
|
3132
2673
|
exports.getStateNodeByPath = getStateNodeByPath;
|
|
3133
2674
|
exports.getStateNodes = getStateNodes;
|
|
3134
2675
|
exports.interpret = interpret;
|
|
3135
|
-
exports.isActorRef = isActorRef;
|
|
3136
2676
|
exports.isAtomicStateNode = isAtomicStateNode;
|
|
3137
2677
|
exports.isErrorEvent = isErrorEvent;
|
|
3138
2678
|
exports.isInFinalState = isInFinalState;
|
|
3139
|
-
exports.
|
|
2679
|
+
exports.isPromiseLike = isPromiseLike;
|
|
3140
2680
|
exports.isStateId = isStateId;
|
|
3141
2681
|
exports.log = log;
|
|
3142
2682
|
exports.macrostep = macrostep;
|
|
@@ -3154,15 +2694,10 @@ exports.resolveReferencedActor = resolveReferencedActor;
|
|
|
3154
2694
|
exports.resolveStateValue = resolveStateValue;
|
|
3155
2695
|
exports.sendParent = sendParent;
|
|
3156
2696
|
exports.sendTo = sendTo;
|
|
3157
|
-
exports.startSignal = startSignal;
|
|
3158
|
-
exports.startSignalType = startSignalType;
|
|
3159
2697
|
exports.stateIn = stateIn;
|
|
3160
2698
|
exports.stop = stop;
|
|
3161
|
-
exports.
|
|
3162
|
-
exports.stopSignalType = stopSignalType;
|
|
3163
|
-
exports.toActorRef = toActorRef;
|
|
2699
|
+
exports.symbolObservable = symbolObservable;
|
|
3164
2700
|
exports.toArray = toArray;
|
|
3165
|
-
exports.toInvokeConfig = toInvokeConfig;
|
|
3166
2701
|
exports.toObserver = toObserver;
|
|
3167
2702
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
3168
2703
|
exports.transitionNode = transitionNode;
|