xstate 5.0.0-alpha.5 → 5.0.0-beta.10
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.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +2 -2
- package/actions/dist/xstate-actions.cjs.mjs +24 -0
- package/actions/dist/xstate-actions.cjs.prod.js +3 -3
- 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.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +2 -1
- package/actors/dist/xstate-actors.cjs.mjs +15 -0
- package/actors/dist/xstate-actors.cjs.prod.js +3 -2
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/dev/dist/xstate-dev.cjs.prod.js +6 -43
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/{actions-96f799fc.cjs.dev.js → actions-109712d3.cjs.dev.js} +397 -379
- package/dist/{actions-7678b87b.esm.js → actions-67f1d04e.esm.js} +351 -366
- package/dist/{actions-2479953d.cjs.prod.js → actions-d0262a43.cjs.prod.js} +420 -388
- package/dist/declarations/src/State.d.ts +2 -3
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +5 -11
- package/dist/declarations/src/actions/send.d.ts +0 -7
- package/dist/declarations/src/actions.d.ts +13 -12
- package/dist/declarations/src/actors/index.d.ts +2 -1
- package/dist/declarations/src/actors/observable.d.ts +1 -2
- package/dist/declarations/src/actors/promise.d.ts +1 -2
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +13 -29
- package/dist/declarations/src/interpreter.d.ts +5 -4
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/stateUtils.d.ts +15 -14
- package/dist/declarations/src/typegenTypes.d.ts +10 -4
- package/dist/declarations/src/types.d.ts +27 -101
- package/dist/declarations/src/utils.d.ts +3 -5
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/index-0f3fdf0c.cjs.prod.js +52 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.dev.js +125 -111
- package/dist/xstate.cjs.mjs +38 -0
- package/dist/xstate.cjs.prod.js +123 -112
- package/dist/xstate.esm.js +108 -99
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.mjs +8 -0
- package/guards/dist/xstate-guards.cjs.prod.js +2 -2
- 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 +7 -1
- package/dist/declarations/src/schema.d.ts +0 -2
package/dist/xstate.cjs.prod.js
CHANGED
|
@@ -2,29 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
6
|
-
require('
|
|
7
|
-
|
|
8
|
-
function pure(getActions) {
|
|
9
|
-
return actors_dist_xstateActors.createDynamicAction({
|
|
10
|
-
type: actors_dist_xstateActors.pure,
|
|
11
|
-
params: {
|
|
12
|
-
get: getActions
|
|
13
|
-
}
|
|
14
|
-
}, function (_event, _ref) {
|
|
15
|
-
var _toArray;
|
|
16
|
-
var state = _ref.state;
|
|
17
|
-
return [state, {
|
|
18
|
-
type: actors_dist_xstateActors.pure,
|
|
19
|
-
params: {
|
|
20
|
-
actions: (_toArray = actors_dist_xstateActors.toArray(actors_dist_xstateActors.toActionObjects(getActions({
|
|
21
|
-
context: state.context,
|
|
22
|
-
event: _event.data
|
|
23
|
-
})))) !== null && _toArray !== void 0 ? _toArray : []
|
|
24
|
-
}
|
|
25
|
-
}];
|
|
26
|
-
});
|
|
27
|
-
}
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-d0262a43.cjs.prod.js');
|
|
6
|
+
require('./index-0f3fdf0c.cjs.prod.js');
|
|
28
7
|
|
|
29
8
|
var _excluded = ["onDone", "onError"];
|
|
30
9
|
var EMPTY_OBJECT = {};
|
|
@@ -83,11 +62,11 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
83
62
|
*/
|
|
84
63
|
|
|
85
64
|
/**
|
|
86
|
-
* The data sent with the "done.state._id_" event if this is a final state node.
|
|
65
|
+
* The output data sent with the "done.state._id_" event if this is a final state node.
|
|
87
66
|
*/
|
|
88
67
|
|
|
89
68
|
/**
|
|
90
|
-
* The order this state node appears. Corresponds to the implicit
|
|
69
|
+
* The order this state node appears. Corresponds to the implicit document order.
|
|
91
70
|
*/
|
|
92
71
|
|
|
93
72
|
function StateNode(
|
|
@@ -109,7 +88,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
109
88
|
actors_dist_xstateActors._defineProperty(this, "parent", void 0);
|
|
110
89
|
actors_dist_xstateActors._defineProperty(this, "machine", void 0);
|
|
111
90
|
actors_dist_xstateActors._defineProperty(this, "meta", void 0);
|
|
112
|
-
actors_dist_xstateActors._defineProperty(this, "
|
|
91
|
+
actors_dist_xstateActors._defineProperty(this, "output", void 0);
|
|
113
92
|
actors_dist_xstateActors._defineProperty(this, "order", -1);
|
|
114
93
|
actors_dist_xstateActors._defineProperty(this, "description", void 0);
|
|
115
94
|
actors_dist_xstateActors._defineProperty(this, "tags", []);
|
|
@@ -141,7 +120,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
141
120
|
this.entry = actors_dist_xstateActors.toActionObjects(this.config.entry);
|
|
142
121
|
this.exit = actors_dist_xstateActors.toActionObjects(this.config.exit);
|
|
143
122
|
this.meta = this.config.meta;
|
|
144
|
-
this.
|
|
123
|
+
this.output = this.type === 'final' ? this.config.output : undefined;
|
|
145
124
|
this.tags = actors_dist_xstateActors.toArray(config.tags);
|
|
146
125
|
}
|
|
147
126
|
actors_dist_xstateActors._createClass(StateNode, [{
|
|
@@ -176,7 +155,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
176
155
|
source: this,
|
|
177
156
|
actions: this.initial.actions,
|
|
178
157
|
eventType: null,
|
|
179
|
-
|
|
158
|
+
reenter: false,
|
|
180
159
|
toJSON: function toJSON() {
|
|
181
160
|
return {
|
|
182
161
|
target: _this3.initial.target.map(function (t) {
|
|
@@ -198,7 +177,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
198
177
|
exit: this.exit,
|
|
199
178
|
meta: this.meta,
|
|
200
179
|
order: this.order || -1,
|
|
201
|
-
|
|
180
|
+
output: this.output,
|
|
202
181
|
invoke: this.invoke,
|
|
203
182
|
description: this.description,
|
|
204
183
|
tags: this.tags
|
|
@@ -235,9 +214,9 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
235
214
|
id: resolvedId,
|
|
236
215
|
systemId: systemId,
|
|
237
216
|
toJSON: function toJSON() {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
|
|
217
|
+
invokeConfig.onDone;
|
|
218
|
+
invokeConfig.onError;
|
|
219
|
+
var invokeDefValues = actors_dist_xstateActors._objectWithoutProperties(invokeConfig, _excluded);
|
|
241
220
|
return actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, invokeDefValues), {}, {
|
|
242
221
|
type: actors_dist_xstateActors.invoke,
|
|
243
222
|
src: resolvedSrc,
|
|
@@ -281,27 +260,15 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
281
260
|
return actors_dist_xstateActors.formatInitialTransition(_this7, _this7.config.initial || []);
|
|
282
261
|
});
|
|
283
262
|
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Returns `true` if this state node explicitly handles the given event.
|
|
287
|
-
*
|
|
288
|
-
* @param event The event in question
|
|
289
|
-
*/
|
|
290
|
-
}, {
|
|
291
|
-
key: "handles",
|
|
292
|
-
value: function handles(event) {
|
|
293
|
-
return this.events.includes(event.type);
|
|
294
|
-
}
|
|
295
263
|
}, {
|
|
296
264
|
key: "next",
|
|
297
|
-
value: function next(state,
|
|
265
|
+
value: function next(state, event) {
|
|
298
266
|
var _this8 = this;
|
|
299
|
-
var
|
|
267
|
+
var eventType = event.type;
|
|
300
268
|
var actions = [];
|
|
301
269
|
var selectedTransition;
|
|
302
|
-
var candidates = actors_dist_xstateActors.memo(this, "candidates-".concat(
|
|
303
|
-
return actors_dist_xstateActors.getCandidates(_this8,
|
|
304
|
-
);
|
|
270
|
+
var candidates = actors_dist_xstateActors.memo(this, "candidates-".concat(eventType), function () {
|
|
271
|
+
return actors_dist_xstateActors.getCandidates(_this8, eventType);
|
|
305
272
|
});
|
|
306
273
|
var _iterator = actors_dist_xstateActors._createForOfIteratorHelper(candidates),
|
|
307
274
|
_step;
|
|
@@ -312,9 +279,9 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
312
279
|
var resolvedContext = state.context;
|
|
313
280
|
var guardPassed = false;
|
|
314
281
|
try {
|
|
315
|
-
guardPassed = !guard || actors_dist_xstateActors.evaluateGuard(guard, resolvedContext,
|
|
282
|
+
guardPassed = !guard || actors_dist_xstateActors.evaluateGuard(guard, resolvedContext, event, state);
|
|
316
283
|
} catch (err) {
|
|
317
|
-
throw new Error("Unable to evaluate guard '".concat(guard.type, "' in transition for event '").concat(
|
|
284
|
+
throw new Error("Unable to evaluate guard '".concat(guard.type, "' in transition for event '").concat(eventType, "' in state node '").concat(this.id, "':\n").concat(err.message));
|
|
318
285
|
}
|
|
319
286
|
if (guardPassed) {
|
|
320
287
|
actions.push.apply(actions, actors_dist_xstateActors._toConsumableArray(candidate.actions));
|
|
@@ -400,7 +367,7 @@ var StateNode = /*#__PURE__*/function () {
|
|
|
400
367
|
key: "ownEvents",
|
|
401
368
|
get: function get() {
|
|
402
369
|
var events = new Set(this.transitions.filter(function (transition) {
|
|
403
|
-
return !(!transition.target && !transition.actions.length && !transition.
|
|
370
|
+
return !(!transition.target && !transition.actions.length && !transition.reenter);
|
|
404
371
|
}).map(function (transition) {
|
|
405
372
|
return transition.eventType;
|
|
406
373
|
}));
|
|
@@ -426,13 +393,13 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
426
393
|
* The raw config used to create the machine.
|
|
427
394
|
*/
|
|
428
395
|
config, options) {
|
|
429
|
-
var _this$config$
|
|
396
|
+
var _this$config$types;
|
|
430
397
|
actors_dist_xstateActors._classCallCheck(this, StateMachine);
|
|
431
398
|
this.config = config;
|
|
432
399
|
actors_dist_xstateActors._defineProperty(this, "version", void 0);
|
|
433
400
|
actors_dist_xstateActors._defineProperty(this, "delimiter", void 0);
|
|
434
401
|
actors_dist_xstateActors._defineProperty(this, "options", void 0);
|
|
435
|
-
actors_dist_xstateActors._defineProperty(this, "
|
|
402
|
+
actors_dist_xstateActors._defineProperty(this, "types", void 0);
|
|
436
403
|
actors_dist_xstateActors._defineProperty(this, "__xstatenode", true);
|
|
437
404
|
actors_dist_xstateActors._defineProperty(this, "idMap", new Map());
|
|
438
405
|
actors_dist_xstateActors._defineProperty(this, "root", void 0);
|
|
@@ -448,7 +415,7 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
448
415
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
449
416
|
this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
|
|
450
417
|
this.version = this.config.version;
|
|
451
|
-
this.
|
|
418
|
+
this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
|
|
452
419
|
this.transition = this.transition.bind(this);
|
|
453
420
|
this.root = new StateNode(config, {
|
|
454
421
|
_key: this.id,
|
|
@@ -548,13 +515,12 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
548
515
|
var actorCtx = arguments.length > 2 ? arguments[2] : undefined;
|
|
549
516
|
var currentState = state instanceof actors_dist_xstateActors.State ? state : this.resolveStateValue(state);
|
|
550
517
|
// TODO: handle error events in a better way
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
return nextEvent === scxmlEvent.name;
|
|
518
|
+
if (actors_dist_xstateActors.isErrorEvent(event) && !currentState.nextEvents.some(function (nextEvent) {
|
|
519
|
+
return nextEvent === event.type;
|
|
554
520
|
})) {
|
|
555
|
-
throw
|
|
521
|
+
throw event.data;
|
|
556
522
|
}
|
|
557
|
-
var _macrostep = actors_dist_xstateActors.macrostep(currentState,
|
|
523
|
+
var _macrostep = actors_dist_xstateActors.macrostep(currentState, event, actorCtx),
|
|
558
524
|
nextState = _macrostep.state;
|
|
559
525
|
return nextState;
|
|
560
526
|
}
|
|
@@ -572,15 +538,12 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
572
538
|
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.initialState;
|
|
573
539
|
var event = arguments.length > 1 ? arguments[1] : undefined;
|
|
574
540
|
var actorCtx = arguments.length > 2 ? arguments[2] : undefined;
|
|
575
|
-
|
|
576
|
-
var _macrostep2 = actors_dist_xstateActors.macrostep(state, scxmlEvent, actorCtx),
|
|
577
|
-
microstates = _macrostep2.microstates;
|
|
578
|
-
return microstates;
|
|
541
|
+
return actors_dist_xstateActors.macrostep(state, event, actorCtx).microstates;
|
|
579
542
|
}
|
|
580
543
|
}, {
|
|
581
544
|
key: "getTransitionData",
|
|
582
|
-
value: function getTransitionData(state,
|
|
583
|
-
return actors_dist_xstateActors.transitionNode(this.root, state.value, state,
|
|
545
|
+
value: function getTransitionData(state, event) {
|
|
546
|
+
return actors_dist_xstateActors.transitionNode(this.root, state.value, state, event) || [];
|
|
584
547
|
}
|
|
585
548
|
|
|
586
549
|
/**
|
|
@@ -600,7 +563,7 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
600
563
|
value: {},
|
|
601
564
|
// TODO: this is computed in state constructor
|
|
602
565
|
context: context,
|
|
603
|
-
|
|
566
|
+
event: actors_dist_xstateActors.createInitEvent({}),
|
|
604
567
|
actions: [],
|
|
605
568
|
meta: undefined,
|
|
606
569
|
configuration: config,
|
|
@@ -640,8 +603,8 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
640
603
|
var preInitialState = this.getPreInitialState(actorCtx, input);
|
|
641
604
|
var nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
|
|
642
605
|
(_nextState$actions = nextState.actions).unshift.apply(_nextState$actions, actors_dist_xstateActors._toConsumableArray(preInitialState.actions));
|
|
643
|
-
var
|
|
644
|
-
macroState =
|
|
606
|
+
var _macrostep2 = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx),
|
|
607
|
+
macroState = _macrostep2.state;
|
|
645
608
|
return macroState;
|
|
646
609
|
}
|
|
647
610
|
}, {
|
|
@@ -666,12 +629,14 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
666
629
|
}, {
|
|
667
630
|
key: "getStateNodeById",
|
|
668
631
|
value: function getStateNodeById(stateId) {
|
|
669
|
-
var
|
|
632
|
+
var fullPath = stateId.split(this.delimiter);
|
|
633
|
+
var relativePath = fullPath.slice(1);
|
|
634
|
+
var resolvedStateId = actors_dist_xstateActors.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
670
635
|
var stateNode = this.idMap.get(resolvedStateId);
|
|
671
636
|
if (!stateNode) {
|
|
672
637
|
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
|
|
673
638
|
}
|
|
674
|
-
return stateNode;
|
|
639
|
+
return actors_dist_xstateActors.getStateNodeByPath(stateNode, relativePath);
|
|
675
640
|
}
|
|
676
641
|
}, {
|
|
677
642
|
key: "definition",
|
|
@@ -694,7 +659,7 @@ var StateMachine = /*#__PURE__*/function () {
|
|
|
694
659
|
key: "createState",
|
|
695
660
|
value: function createState(stateConfig) {
|
|
696
661
|
var state = stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
|
|
697
|
-
var _resolveActionsAndCon2 = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state.
|
|
662
|
+
var _resolveActionsAndCon2 = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state.event, state, undefined),
|
|
698
663
|
resolvedState = _resolveActionsAndCon2.nextState;
|
|
699
664
|
return resolvedState;
|
|
700
665
|
}
|
|
@@ -778,11 +743,6 @@ function mapState(stateMap, stateId) {
|
|
|
778
743
|
return stateMap[foundStateId];
|
|
779
744
|
}
|
|
780
745
|
|
|
781
|
-
function createSchema(schema) {
|
|
782
|
-
return schema;
|
|
783
|
-
}
|
|
784
|
-
var t = createSchema;
|
|
785
|
-
|
|
786
746
|
var SimulatedClock = /*#__PURE__*/function () {
|
|
787
747
|
function SimulatedClock() {
|
|
788
748
|
actors_dist_xstateActors._classCallCheck(this, SimulatedClock);
|
|
@@ -830,12 +790,12 @@ var SimulatedClock = /*#__PURE__*/function () {
|
|
|
830
790
|
value: function flushTimeouts() {
|
|
831
791
|
var _this = this;
|
|
832
792
|
actors_dist_xstateActors._toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
|
|
833
|
-
var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2)
|
|
834
|
-
|
|
835
|
-
timeoutA = _ref3[1];
|
|
836
|
-
var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2)
|
|
837
|
-
|
|
838
|
-
timeoutB = _ref4[1];
|
|
793
|
+
var _ref3 = actors_dist_xstateActors._slicedToArray(_ref, 2);
|
|
794
|
+
_ref3[0];
|
|
795
|
+
var timeoutA = _ref3[1];
|
|
796
|
+
var _ref4 = actors_dist_xstateActors._slicedToArray(_ref2, 2);
|
|
797
|
+
_ref4[0];
|
|
798
|
+
var timeoutB = _ref4[1];
|
|
839
799
|
var endA = timeoutA.start + timeoutA.timeout;
|
|
840
800
|
var endB = timeoutB.start + timeoutB.timeout;
|
|
841
801
|
return endB > endA ? -1 : 1;
|
|
@@ -859,61 +819,112 @@ var SimulatedClock = /*#__PURE__*/function () {
|
|
|
859
819
|
return SimulatedClock;
|
|
860
820
|
}();
|
|
861
821
|
|
|
862
|
-
var
|
|
863
|
-
|
|
864
|
-
send: actors_dist_xstateActors.send,
|
|
865
|
-
sendParent: actors_dist_xstateActors.sendParent,
|
|
866
|
-
sendTo: actors_dist_xstateActors.sendTo,
|
|
867
|
-
log: actors_dist_xstateActors.log,
|
|
868
|
-
cancel: actors_dist_xstateActors.cancel,
|
|
869
|
-
stop: actors_dist_xstateActors.stop,
|
|
870
|
-
assign: actors_dist_xstateActors.assign,
|
|
871
|
-
after: actors_dist_xstateActors.after,
|
|
872
|
-
done: actors_dist_xstateActors.done,
|
|
873
|
-
respond: actors_dist_xstateActors.respond,
|
|
874
|
-
forwardTo: actors_dist_xstateActors.forwardTo,
|
|
875
|
-
escalate: actors_dist_xstateActors.escalate,
|
|
876
|
-
choose: actors_dist_xstateActors.choose,
|
|
877
|
-
pure: pure
|
|
822
|
+
var defaultWaitForOptions = {
|
|
823
|
+
timeout: 10000 // 10 seconds
|
|
878
824
|
};
|
|
879
825
|
|
|
826
|
+
/**
|
|
827
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
828
|
+
* a predicate, and then resolves with that value.
|
|
829
|
+
* Will throw if the desired state is not reached after a timeout
|
|
830
|
+
* (defaults to 10 seconds).
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```js
|
|
834
|
+
* const state = await waitFor(someService, state => {
|
|
835
|
+
* return state.hasTag('loaded');
|
|
836
|
+
* });
|
|
837
|
+
*
|
|
838
|
+
* state.hasTag('loaded'); // true
|
|
839
|
+
* ```
|
|
840
|
+
*
|
|
841
|
+
* @param actorRef The actor ref to subscribe to
|
|
842
|
+
* @param predicate Determines if a value matches the condition to wait for
|
|
843
|
+
* @param options
|
|
844
|
+
* @returns A promise that eventually resolves to the emitted value
|
|
845
|
+
* that matches the condition
|
|
846
|
+
*/
|
|
847
|
+
function waitFor(actorRef, predicate, options) {
|
|
848
|
+
var resolvedOptions = actors_dist_xstateActors._objectSpread2(actors_dist_xstateActors._objectSpread2({}, defaultWaitForOptions), options);
|
|
849
|
+
return new Promise(function (res, rej) {
|
|
850
|
+
var done = false;
|
|
851
|
+
var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
|
|
852
|
+
sub.unsubscribe();
|
|
853
|
+
rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
|
|
854
|
+
}, resolvedOptions.timeout);
|
|
855
|
+
var dispose = function dispose() {
|
|
856
|
+
clearTimeout(handle);
|
|
857
|
+
done = true;
|
|
858
|
+
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
859
|
+
};
|
|
860
|
+
function checkEmitted(emitted) {
|
|
861
|
+
if (predicate(emitted)) {
|
|
862
|
+
dispose();
|
|
863
|
+
res(emitted);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// See if the current snapshot already matches the predicate
|
|
868
|
+
checkEmitted(actorRef.getSnapshot());
|
|
869
|
+
var sub = actorRef.subscribe({
|
|
870
|
+
next: checkEmitted,
|
|
871
|
+
error: function error(err) {
|
|
872
|
+
dispose();
|
|
873
|
+
rej(err);
|
|
874
|
+
},
|
|
875
|
+
complete: function complete() {
|
|
876
|
+
dispose();
|
|
877
|
+
rej(new Error("Actor terminated without satisfying predicate"));
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
if (done) {
|
|
881
|
+
sub.unsubscribe();
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
|
|
880
886
|
Object.defineProperty(exports, 'ActionTypes', {
|
|
881
887
|
enumerable: true,
|
|
882
|
-
get: function () {
|
|
883
|
-
return actors_dist_xstateActors.ActionTypes;
|
|
884
|
-
}
|
|
888
|
+
get: function () { return actors_dist_xstateActors.ActionTypes; }
|
|
885
889
|
});
|
|
886
890
|
exports.Interpreter = actors_dist_xstateActors.Interpreter;
|
|
887
891
|
Object.defineProperty(exports, 'InterpreterStatus', {
|
|
888
892
|
enumerable: true,
|
|
889
|
-
get: function () {
|
|
890
|
-
return actors_dist_xstateActors.ActorStatus;
|
|
891
|
-
}
|
|
893
|
+
get: function () { return actors_dist_xstateActors.ActorStatus; }
|
|
892
894
|
});
|
|
893
895
|
Object.defineProperty(exports, 'SpecialTargets', {
|
|
894
896
|
enumerable: true,
|
|
895
|
-
get: function () {
|
|
896
|
-
return actors_dist_xstateActors.SpecialTargets;
|
|
897
|
-
}
|
|
897
|
+
get: function () { return actors_dist_xstateActors.SpecialTargets; }
|
|
898
898
|
});
|
|
899
899
|
exports.State = actors_dist_xstateActors.State;
|
|
900
|
+
exports.and = actors_dist_xstateActors.and;
|
|
900
901
|
exports.assign = actors_dist_xstateActors.assign;
|
|
902
|
+
exports.cancel = actors_dist_xstateActors.cancel;
|
|
903
|
+
exports.choose = actors_dist_xstateActors.choose;
|
|
901
904
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
902
905
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
906
|
+
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
907
|
+
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
908
|
+
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
909
|
+
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
910
|
+
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
903
911
|
exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
|
|
904
912
|
exports.interpret = actors_dist_xstateActors.interpret;
|
|
913
|
+
exports.log = actors_dist_xstateActors.log;
|
|
905
914
|
exports.matchesState = actors_dist_xstateActors.matchesState;
|
|
915
|
+
exports.not = actors_dist_xstateActors.not;
|
|
916
|
+
exports.or = actors_dist_xstateActors.or;
|
|
906
917
|
exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
|
|
907
|
-
exports.
|
|
918
|
+
exports.pure = actors_dist_xstateActors.pure;
|
|
919
|
+
exports.raise = actors_dist_xstateActors.raise;
|
|
908
920
|
exports.sendParent = actors_dist_xstateActors.sendParent;
|
|
909
921
|
exports.sendTo = actors_dist_xstateActors.sendTo;
|
|
922
|
+
exports.stateIn = actors_dist_xstateActors.stateIn;
|
|
923
|
+
exports.stop = actors_dist_xstateActors.stop;
|
|
910
924
|
exports.toObserver = actors_dist_xstateActors.toObserver;
|
|
911
|
-
exports.toSCXMLEvent = actors_dist_xstateActors.toSCXMLEvent;
|
|
912
925
|
exports.SimulatedClock = SimulatedClock;
|
|
913
926
|
exports.StateMachine = StateMachine;
|
|
914
927
|
exports.StateNode = StateNode;
|
|
915
|
-
exports.actions = actions;
|
|
916
928
|
exports.createMachine = createMachine;
|
|
917
|
-
exports.createSchema = createSchema;
|
|
918
929
|
exports.mapState = mapState;
|
|
919
|
-
exports.
|
|
930
|
+
exports.waitFor = waitFor;
|