xstate 5.0.0-beta.49 → 5.0.0-beta.51
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 +11 -10
- package/actions/dist/xstate-actions.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.cjs.js +11 -10
- package/actions/dist/xstate-actions.development.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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 +2 -4
- package/actors/dist/xstate-actors.development.cjs.js +2 -4
- package/actors/dist/xstate-actors.development.esm.js +2 -4
- package/actors/dist/xstate-actors.esm.js +2 -4
- 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/actions/enqueueActions.d.ts +32 -0
- package/dist/declarations/src/actions/pure.d.ts +7 -10
- package/dist/declarations/src/actions.d.ts +3 -2
- package/dist/declarations/src/actors/callback.d.ts +5 -5
- package/dist/declarations/src/actors/observable.d.ts +5 -5
- package/dist/declarations/src/actors/promise.d.ts +2 -2
- package/dist/declarations/src/actors/transition.d.ts +3 -3
- package/dist/declarations/src/interpreter.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +2 -2
- package/dist/declarations/src/types.d.ts +5 -3
- package/dist/declarations/src/utils.d.ts +1 -20
- package/dist/{send-0a381ca2.development.esm.js → pure-296f8ebd.development.esm.js} +114 -77
- package/dist/{send-8d30b415.development.cjs.js → pure-a0f16134.development.cjs.js} +114 -76
- package/dist/{send-22880315.esm.js → pure-aefddc19.esm.js} +108 -71
- package/dist/{send-8ed5c8b2.cjs.js → pure-c5f1b46c.cjs.js} +108 -70
- package/dist/{raise-e4cc6d4f.esm.js → raise-4742bf04.esm.js} +98 -38
- package/dist/{raise-495f4b9f.development.cjs.js → raise-528386de.development.cjs.js} +97 -38
- package/dist/{raise-1873c645.development.esm.js → raise-acaa3884.development.esm.js} +98 -38
- package/dist/{raise-8f9c4a5a.cjs.js → raise-d5633a02.cjs.js} +97 -38
- package/dist/xstate.cjs.js +14 -23
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +14 -23
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +5 -15
- package/dist/xstate.esm.js +5 -15
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- 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.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, e as evaluateGuard, t as toArray, U as XSTATE_ERROR, V as createErrorActorEvent, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-4742bf04.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -47,12 +47,7 @@ function createSpawner(actorScope, {
|
|
|
47
47
|
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
actorRef.start?.();
|
|
52
|
-
} catch (err) {
|
|
53
|
-
actorScope.self.send(createErrorActorEvent(actorRef.id, err));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
50
|
+
actorRef.start();
|
|
56
51
|
});
|
|
57
52
|
return actorRef;
|
|
58
53
|
};
|
|
@@ -121,69 +116,6 @@ function choose(branches) {
|
|
|
121
116
|
return choose;
|
|
122
117
|
}
|
|
123
118
|
|
|
124
|
-
function resolveLog(_, state, actionArgs, actionParams, {
|
|
125
|
-
value,
|
|
126
|
-
label
|
|
127
|
-
}) {
|
|
128
|
-
return [state, {
|
|
129
|
-
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
130
|
-
label
|
|
131
|
-
}];
|
|
132
|
-
}
|
|
133
|
-
function executeLog({
|
|
134
|
-
logger
|
|
135
|
-
}, {
|
|
136
|
-
value,
|
|
137
|
-
label
|
|
138
|
-
}) {
|
|
139
|
-
if (label) {
|
|
140
|
-
logger(label, value);
|
|
141
|
-
} else {
|
|
142
|
-
logger(value);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
* @param expr The expression function to evaluate which will be logged.
|
|
148
|
-
* Takes in 2 arguments:
|
|
149
|
-
* - `ctx` - the current state context
|
|
150
|
-
* - `event` - the event that caused this action to be executed.
|
|
151
|
-
* @param label The label to give to the logged expression.
|
|
152
|
-
*/
|
|
153
|
-
function log(value = ({
|
|
154
|
-
context,
|
|
155
|
-
event
|
|
156
|
-
}) => ({
|
|
157
|
-
context,
|
|
158
|
-
event
|
|
159
|
-
}), label) {
|
|
160
|
-
function log(args, params) {
|
|
161
|
-
}
|
|
162
|
-
log.type = 'xstate.log';
|
|
163
|
-
log.value = value;
|
|
164
|
-
log.label = label;
|
|
165
|
-
log.resolve = resolveLog;
|
|
166
|
-
log.execute = executeLog;
|
|
167
|
-
return log;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function resolvePure(_, state, args, _actionParams, {
|
|
171
|
-
get
|
|
172
|
-
}) {
|
|
173
|
-
return [state, undefined, toArray(get({
|
|
174
|
-
context: args.context,
|
|
175
|
-
event: args.event
|
|
176
|
-
}))];
|
|
177
|
-
}
|
|
178
|
-
function pure(getActions) {
|
|
179
|
-
function pure(args, params) {
|
|
180
|
-
}
|
|
181
|
-
pure.type = 'xstate.pure';
|
|
182
|
-
pure.get = getActions;
|
|
183
|
-
pure.resolve = resolvePure;
|
|
184
|
-
return pure;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
119
|
/**
|
|
188
120
|
*
|
|
189
121
|
* @remarks
|
|
@@ -374,4 +306,109 @@ function escalate(errorData, options) {
|
|
|
374
306
|
}, options);
|
|
375
307
|
}
|
|
376
308
|
|
|
377
|
-
|
|
309
|
+
function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
310
|
+
collect
|
|
311
|
+
}) {
|
|
312
|
+
const actions = [];
|
|
313
|
+
const enqueue = function enqueue(action) {
|
|
314
|
+
actions.push(action);
|
|
315
|
+
};
|
|
316
|
+
enqueue.assign = (...args) => {
|
|
317
|
+
actions.push(assign(...args));
|
|
318
|
+
};
|
|
319
|
+
enqueue.cancel = (...args) => {
|
|
320
|
+
actions.push(cancel(...args));
|
|
321
|
+
};
|
|
322
|
+
enqueue.raise = (...args) => {
|
|
323
|
+
actions.push(raise(...args));
|
|
324
|
+
};
|
|
325
|
+
enqueue.sendTo = (...args) => {
|
|
326
|
+
actions.push(sendTo(...args));
|
|
327
|
+
};
|
|
328
|
+
enqueue.spawnChild = (...args) => {
|
|
329
|
+
actions.push(spawnChild(...args));
|
|
330
|
+
};
|
|
331
|
+
enqueue.stopChild = (...args) => {
|
|
332
|
+
actions.push(stopChild(...args));
|
|
333
|
+
};
|
|
334
|
+
collect({
|
|
335
|
+
context: args.context,
|
|
336
|
+
event: args.event,
|
|
337
|
+
enqueue,
|
|
338
|
+
check: guard => evaluateGuard(guard, state.context, args.event, state)
|
|
339
|
+
});
|
|
340
|
+
return [state, undefined, actions];
|
|
341
|
+
}
|
|
342
|
+
function enqueueActions(collect) {
|
|
343
|
+
function enqueueActions(args, params) {
|
|
344
|
+
}
|
|
345
|
+
enqueueActions.type = 'xstate.enqueueActions';
|
|
346
|
+
enqueueActions.collect = collect;
|
|
347
|
+
enqueueActions.resolve = resolveEnqueueActions;
|
|
348
|
+
return enqueueActions;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function resolveLog(_, state, actionArgs, actionParams, {
|
|
352
|
+
value,
|
|
353
|
+
label
|
|
354
|
+
}) {
|
|
355
|
+
return [state, {
|
|
356
|
+
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
357
|
+
label
|
|
358
|
+
}];
|
|
359
|
+
}
|
|
360
|
+
function executeLog({
|
|
361
|
+
logger
|
|
362
|
+
}, {
|
|
363
|
+
value,
|
|
364
|
+
label
|
|
365
|
+
}) {
|
|
366
|
+
if (label) {
|
|
367
|
+
logger(label, value);
|
|
368
|
+
} else {
|
|
369
|
+
logger(value);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
*
|
|
374
|
+
* @param expr The expression function to evaluate which will be logged.
|
|
375
|
+
* Takes in 2 arguments:
|
|
376
|
+
* - `ctx` - the current state context
|
|
377
|
+
* - `event` - the event that caused this action to be executed.
|
|
378
|
+
* @param label The label to give to the logged expression.
|
|
379
|
+
*/
|
|
380
|
+
function log(value = ({
|
|
381
|
+
context,
|
|
382
|
+
event
|
|
383
|
+
}) => ({
|
|
384
|
+
context,
|
|
385
|
+
event
|
|
386
|
+
}), label) {
|
|
387
|
+
function log(args, params) {
|
|
388
|
+
}
|
|
389
|
+
log.type = 'xstate.log';
|
|
390
|
+
log.value = value;
|
|
391
|
+
log.label = label;
|
|
392
|
+
log.resolve = resolveLog;
|
|
393
|
+
log.execute = executeLog;
|
|
394
|
+
return log;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
* @deprecated Use `enqueueActions(...)` instead
|
|
400
|
+
*/
|
|
401
|
+
function pure(getActions) {
|
|
402
|
+
return enqueueActions(({
|
|
403
|
+
context,
|
|
404
|
+
event,
|
|
405
|
+
enqueue
|
|
406
|
+
}) => {
|
|
407
|
+
toArray(getActions({
|
|
408
|
+
context,
|
|
409
|
+
event
|
|
410
|
+
})).forEach(enqueue);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export { SpecialTargets as S, assign as a, escalate as b, choose as c, sendTo as d, enqueueActions as e, forwardTo as f, log as l, pure as p, sendParent as s };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-d5633a02.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -49,12 +49,7 @@ function createSpawner(actorScope, {
|
|
|
49
49
|
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
actorRef.start?.();
|
|
54
|
-
} catch (err) {
|
|
55
|
-
actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
52
|
+
actorRef.start();
|
|
58
53
|
});
|
|
59
54
|
return actorRef;
|
|
60
55
|
};
|
|
@@ -123,69 +118,6 @@ function choose(branches) {
|
|
|
123
118
|
return choose;
|
|
124
119
|
}
|
|
125
120
|
|
|
126
|
-
function resolveLog(_, state, actionArgs, actionParams, {
|
|
127
|
-
value,
|
|
128
|
-
label
|
|
129
|
-
}) {
|
|
130
|
-
return [state, {
|
|
131
|
-
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
132
|
-
label
|
|
133
|
-
}];
|
|
134
|
-
}
|
|
135
|
-
function executeLog({
|
|
136
|
-
logger
|
|
137
|
-
}, {
|
|
138
|
-
value,
|
|
139
|
-
label
|
|
140
|
-
}) {
|
|
141
|
-
if (label) {
|
|
142
|
-
logger(label, value);
|
|
143
|
-
} else {
|
|
144
|
-
logger(value);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
* @param expr The expression function to evaluate which will be logged.
|
|
150
|
-
* Takes in 2 arguments:
|
|
151
|
-
* - `ctx` - the current state context
|
|
152
|
-
* - `event` - the event that caused this action to be executed.
|
|
153
|
-
* @param label The label to give to the logged expression.
|
|
154
|
-
*/
|
|
155
|
-
function log(value = ({
|
|
156
|
-
context,
|
|
157
|
-
event
|
|
158
|
-
}) => ({
|
|
159
|
-
context,
|
|
160
|
-
event
|
|
161
|
-
}), label) {
|
|
162
|
-
function log(args, params) {
|
|
163
|
-
}
|
|
164
|
-
log.type = 'xstate.log';
|
|
165
|
-
log.value = value;
|
|
166
|
-
log.label = label;
|
|
167
|
-
log.resolve = resolveLog;
|
|
168
|
-
log.execute = executeLog;
|
|
169
|
-
return log;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function resolvePure(_, state, args, _actionParams, {
|
|
173
|
-
get
|
|
174
|
-
}) {
|
|
175
|
-
return [state, undefined, guards_dist_xstateGuards.toArray(get({
|
|
176
|
-
context: args.context,
|
|
177
|
-
event: args.event
|
|
178
|
-
}))];
|
|
179
|
-
}
|
|
180
|
-
function pure(getActions) {
|
|
181
|
-
function pure(args, params) {
|
|
182
|
-
}
|
|
183
|
-
pure.type = 'xstate.pure';
|
|
184
|
-
pure.get = getActions;
|
|
185
|
-
pure.resolve = resolvePure;
|
|
186
|
-
return pure;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
121
|
/**
|
|
190
122
|
*
|
|
191
123
|
* @remarks
|
|
@@ -376,9 +308,115 @@ function escalate(errorData, options) {
|
|
|
376
308
|
}, options);
|
|
377
309
|
}
|
|
378
310
|
|
|
311
|
+
function resolveEnqueueActions(_, state, args, _actionParams, {
|
|
312
|
+
collect
|
|
313
|
+
}) {
|
|
314
|
+
const actions = [];
|
|
315
|
+
const enqueue = function enqueue(action) {
|
|
316
|
+
actions.push(action);
|
|
317
|
+
};
|
|
318
|
+
enqueue.assign = (...args) => {
|
|
319
|
+
actions.push(assign(...args));
|
|
320
|
+
};
|
|
321
|
+
enqueue.cancel = (...args) => {
|
|
322
|
+
actions.push(guards_dist_xstateGuards.cancel(...args));
|
|
323
|
+
};
|
|
324
|
+
enqueue.raise = (...args) => {
|
|
325
|
+
actions.push(guards_dist_xstateGuards.raise(...args));
|
|
326
|
+
};
|
|
327
|
+
enqueue.sendTo = (...args) => {
|
|
328
|
+
actions.push(sendTo(...args));
|
|
329
|
+
};
|
|
330
|
+
enqueue.spawnChild = (...args) => {
|
|
331
|
+
actions.push(guards_dist_xstateGuards.spawnChild(...args));
|
|
332
|
+
};
|
|
333
|
+
enqueue.stopChild = (...args) => {
|
|
334
|
+
actions.push(guards_dist_xstateGuards.stopChild(...args));
|
|
335
|
+
};
|
|
336
|
+
collect({
|
|
337
|
+
context: args.context,
|
|
338
|
+
event: args.event,
|
|
339
|
+
enqueue,
|
|
340
|
+
check: guard => guards_dist_xstateGuards.evaluateGuard(guard, state.context, args.event, state)
|
|
341
|
+
});
|
|
342
|
+
return [state, undefined, actions];
|
|
343
|
+
}
|
|
344
|
+
function enqueueActions(collect) {
|
|
345
|
+
function enqueueActions(args, params) {
|
|
346
|
+
}
|
|
347
|
+
enqueueActions.type = 'xstate.enqueueActions';
|
|
348
|
+
enqueueActions.collect = collect;
|
|
349
|
+
enqueueActions.resolve = resolveEnqueueActions;
|
|
350
|
+
return enqueueActions;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function resolveLog(_, state, actionArgs, actionParams, {
|
|
354
|
+
value,
|
|
355
|
+
label
|
|
356
|
+
}) {
|
|
357
|
+
return [state, {
|
|
358
|
+
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
359
|
+
label
|
|
360
|
+
}];
|
|
361
|
+
}
|
|
362
|
+
function executeLog({
|
|
363
|
+
logger
|
|
364
|
+
}, {
|
|
365
|
+
value,
|
|
366
|
+
label
|
|
367
|
+
}) {
|
|
368
|
+
if (label) {
|
|
369
|
+
logger(label, value);
|
|
370
|
+
} else {
|
|
371
|
+
logger(value);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
*
|
|
376
|
+
* @param expr The expression function to evaluate which will be logged.
|
|
377
|
+
* Takes in 2 arguments:
|
|
378
|
+
* - `ctx` - the current state context
|
|
379
|
+
* - `event` - the event that caused this action to be executed.
|
|
380
|
+
* @param label The label to give to the logged expression.
|
|
381
|
+
*/
|
|
382
|
+
function log(value = ({
|
|
383
|
+
context,
|
|
384
|
+
event
|
|
385
|
+
}) => ({
|
|
386
|
+
context,
|
|
387
|
+
event
|
|
388
|
+
}), label) {
|
|
389
|
+
function log(args, params) {
|
|
390
|
+
}
|
|
391
|
+
log.type = 'xstate.log';
|
|
392
|
+
log.value = value;
|
|
393
|
+
log.label = label;
|
|
394
|
+
log.resolve = resolveLog;
|
|
395
|
+
log.execute = executeLog;
|
|
396
|
+
return log;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
*
|
|
401
|
+
* @deprecated Use `enqueueActions(...)` instead
|
|
402
|
+
*/
|
|
403
|
+
function pure(getActions) {
|
|
404
|
+
return enqueueActions(({
|
|
405
|
+
context,
|
|
406
|
+
event,
|
|
407
|
+
enqueue
|
|
408
|
+
}) => {
|
|
409
|
+
guards_dist_xstateGuards.toArray(getActions({
|
|
410
|
+
context,
|
|
411
|
+
event
|
|
412
|
+
})).forEach(enqueue);
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
379
416
|
exports.SpecialTargets = SpecialTargets;
|
|
380
417
|
exports.assign = assign;
|
|
381
418
|
exports.choose = choose;
|
|
419
|
+
exports.enqueueActions = enqueueActions;
|
|
382
420
|
exports.escalate = escalate;
|
|
383
421
|
exports.forwardTo = forwardTo;
|
|
384
422
|
exports.log = log;
|
|
@@ -203,14 +203,10 @@ function matchesState(parentStateId, childStateId) {
|
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
function toStatePath(stateId) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return stateId;
|
|
209
|
-
}
|
|
210
|
-
return stateId.split(STATE_DELIMITER);
|
|
211
|
-
} catch (e) {
|
|
212
|
-
throw new Error(`'${stateId}' is not a valid state path.`);
|
|
206
|
+
if (isArray(stateId)) {
|
|
207
|
+
return stateId;
|
|
213
208
|
}
|
|
209
|
+
return stateId.split(STATE_DELIMITER);
|
|
214
210
|
}
|
|
215
211
|
function toStateValue(stateValue) {
|
|
216
212
|
if (isMachineSnapshot(stateValue)) {
|
|
@@ -449,7 +445,18 @@ class Actor {
|
|
|
449
445
|
}
|
|
450
446
|
}
|
|
451
447
|
_initState(persistedState) {
|
|
452
|
-
|
|
448
|
+
try {
|
|
449
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
450
|
+
} catch (err) {
|
|
451
|
+
// if we get here then it means that we assign a value to this._state that is not of the correct type
|
|
452
|
+
// we can't get the true `TSnapshot & { status: 'error'; }`, it's impossible
|
|
453
|
+
// so right now this is a lie of sorts
|
|
454
|
+
this._state = {
|
|
455
|
+
status: 'error',
|
|
456
|
+
output: undefined,
|
|
457
|
+
error: err
|
|
458
|
+
};
|
|
459
|
+
}
|
|
453
460
|
}
|
|
454
461
|
update(snapshot, event) {
|
|
455
462
|
// Update state
|
|
@@ -458,17 +465,46 @@ class Actor {
|
|
|
458
465
|
// Execute deferred effects
|
|
459
466
|
let deferredFn;
|
|
460
467
|
while (deferredFn = this._deferred.shift()) {
|
|
461
|
-
deferredFn();
|
|
462
|
-
}
|
|
463
|
-
for (const observer of this.observers) {
|
|
464
468
|
try {
|
|
465
|
-
|
|
469
|
+
deferredFn();
|
|
466
470
|
} catch (err) {
|
|
467
|
-
|
|
471
|
+
// this error can only be caught when executing *initial* actions
|
|
472
|
+
// it's the only time when we call actions provided by the user through those deferreds
|
|
473
|
+
// when the actor is already running we always execute them synchronously while transitioning
|
|
474
|
+
// no "builtin deferred" should actually throw an error since they are either safe
|
|
475
|
+
// or the control flow is passed through the mailbox and errors should be caught by the `_process` used by the mailbox
|
|
476
|
+
this._deferred.length = 0;
|
|
477
|
+
this._state = {
|
|
478
|
+
...snapshot,
|
|
479
|
+
status: 'error',
|
|
480
|
+
error: err
|
|
481
|
+
};
|
|
468
482
|
}
|
|
469
483
|
}
|
|
470
484
|
switch (this._state.status) {
|
|
485
|
+
case 'active':
|
|
486
|
+
for (const observer of this.observers) {
|
|
487
|
+
try {
|
|
488
|
+
observer.next?.(snapshot);
|
|
489
|
+
} catch (err) {
|
|
490
|
+
reportUnhandledError(err);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
break;
|
|
471
494
|
case 'done':
|
|
495
|
+
// next observers are meant to be notified about done snapshots
|
|
496
|
+
// this can be seen as something that is different from how observable work
|
|
497
|
+
// but with observables `complete` callback is called without any arguments
|
|
498
|
+
// it's more ergonomic for XState to treat a done snapshot as a "next" value
|
|
499
|
+
// and the completion event as something that is separate,
|
|
500
|
+
// something that merely follows emitting that done snapshot
|
|
501
|
+
for (const observer of this.observers) {
|
|
502
|
+
try {
|
|
503
|
+
observer.next?.(snapshot);
|
|
504
|
+
} catch (err) {
|
|
505
|
+
reportUnhandledError(err);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
472
508
|
this._stopProcedure();
|
|
473
509
|
this._complete();
|
|
474
510
|
this._doneEvent = createDoneActorEvent(this.id, this._state.output);
|
|
@@ -477,11 +513,7 @@ class Actor {
|
|
|
477
513
|
}
|
|
478
514
|
break;
|
|
479
515
|
case 'error':
|
|
480
|
-
this._stopProcedure();
|
|
481
516
|
this._error(this._state.error);
|
|
482
|
-
if (this._parent) {
|
|
483
|
-
this.system._relay(this, this._parent, createErrorActorEvent(this.id, this._state.error));
|
|
484
|
-
}
|
|
485
517
|
break;
|
|
486
518
|
}
|
|
487
519
|
this.system._sendInspectionEvent({
|
|
@@ -571,7 +603,7 @@ class Actor {
|
|
|
571
603
|
this.subscribe({
|
|
572
604
|
next: snapshot => {
|
|
573
605
|
if (snapshot.status === 'active') {
|
|
574
|
-
this.
|
|
606
|
+
this.system._relay(this, this._parent, {
|
|
575
607
|
type: `xstate.snapshot.${this.id}`,
|
|
576
608
|
snapshot
|
|
577
609
|
});
|
|
@@ -600,18 +632,22 @@ class Actor {
|
|
|
600
632
|
// a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
|
|
601
633
|
// we still need to complete observers, flush deferreds etc
|
|
602
634
|
this.update(this._state, initEvent);
|
|
603
|
-
// fallthrough
|
|
604
|
-
case 'error':
|
|
605
635
|
// TODO: rethink cleanup of observers, mailbox, etc
|
|
606
636
|
return this;
|
|
637
|
+
case 'error':
|
|
638
|
+
this._error(this._state.error);
|
|
639
|
+
return this;
|
|
607
640
|
}
|
|
608
641
|
if (this.logic.start) {
|
|
609
642
|
try {
|
|
610
643
|
this.logic.start(this._state, this._actorScope);
|
|
611
644
|
} catch (err) {
|
|
612
|
-
this.
|
|
645
|
+
this._state = {
|
|
646
|
+
...this._state,
|
|
647
|
+
status: 'error',
|
|
648
|
+
error: err
|
|
649
|
+
};
|
|
613
650
|
this._error(err);
|
|
614
|
-
this._parent?.send(createErrorActorEvent(this.id, err));
|
|
615
651
|
return this;
|
|
616
652
|
}
|
|
617
653
|
}
|
|
@@ -627,7 +663,6 @@ class Actor {
|
|
|
627
663
|
return this;
|
|
628
664
|
}
|
|
629
665
|
_process(event) {
|
|
630
|
-
// TODO: reexamine what happens when an action (or a guard or smth) throws
|
|
631
666
|
let nextState;
|
|
632
667
|
let caughtError;
|
|
633
668
|
try {
|
|
@@ -642,9 +677,12 @@ class Actor {
|
|
|
642
677
|
const {
|
|
643
678
|
err
|
|
644
679
|
} = caughtError;
|
|
645
|
-
this.
|
|
680
|
+
this._state = {
|
|
681
|
+
...this._state,
|
|
682
|
+
status: 'error',
|
|
683
|
+
error: err
|
|
684
|
+
};
|
|
646
685
|
this._error(err);
|
|
647
|
-
this._parent?.send(createErrorActorEvent(this.id, err));
|
|
648
686
|
return;
|
|
649
687
|
}
|
|
650
688
|
this.update(nextState, event);
|
|
@@ -687,7 +725,7 @@ class Actor {
|
|
|
687
725
|
}
|
|
688
726
|
this.observers.clear();
|
|
689
727
|
}
|
|
690
|
-
|
|
728
|
+
_reportError(err) {
|
|
691
729
|
if (!this.observers.size) {
|
|
692
730
|
if (!this._parent) {
|
|
693
731
|
reportUnhandledError(err);
|
|
@@ -709,6 +747,18 @@ class Actor {
|
|
|
709
747
|
reportUnhandledError(err);
|
|
710
748
|
}
|
|
711
749
|
}
|
|
750
|
+
_error(err) {
|
|
751
|
+
this._stopProcedure();
|
|
752
|
+
this._reportError(err);
|
|
753
|
+
if (this._parent) {
|
|
754
|
+
this.system._relay(this, this._parent, createErrorActorEvent(this.id, err));
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
// TODO: atm children don't belong entirely to the actor so
|
|
758
|
+
// in a way - it's not even super aware of them
|
|
759
|
+
// so we can't stop them from here but we really should!
|
|
760
|
+
// right now, they are being stopped within the machine's transition
|
|
761
|
+
// but that could throw and leave us with "orphaned" active actors
|
|
712
762
|
_stopProcedure() {
|
|
713
763
|
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
714
764
|
// Actor already stopped; do nothing
|
|
@@ -954,12 +1004,7 @@ function executeSpawn(actorScope, {
|
|
|
954
1004
|
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
955
1005
|
return;
|
|
956
1006
|
}
|
|
957
|
-
|
|
958
|
-
actorRef.start?.();
|
|
959
|
-
} catch (err) {
|
|
960
|
-
actorScope.self.send(createErrorActorEvent(id, err));
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
1007
|
+
actorRef.start();
|
|
963
1008
|
});
|
|
964
1009
|
}
|
|
965
1010
|
function spawnChild(...[src, {
|
|
@@ -1283,8 +1328,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1283
1328
|
return [];
|
|
1284
1329
|
}
|
|
1285
1330
|
const mutateEntryExit = (delay, i) => {
|
|
1286
|
-
const
|
|
1287
|
-
const afterEvent = createAfterEvent(delayRef, stateNode.id);
|
|
1331
|
+
const afterEvent = createAfterEvent(delay, stateNode.id);
|
|
1288
1332
|
const eventType = afterEvent.type;
|
|
1289
1333
|
stateNode.entry.push(raise(afterEvent, {
|
|
1290
1334
|
id: eventType,
|
|
@@ -1298,8 +1342,8 @@ function getDelayedTransitions(stateNode) {
|
|
|
1298
1342
|
const resolvedTransition = typeof configTransition === 'string' ? {
|
|
1299
1343
|
target: configTransition
|
|
1300
1344
|
} : configTransition;
|
|
1301
|
-
const resolvedDelay =
|
|
1302
|
-
const eventType = mutateEntryExit(resolvedDelay
|
|
1345
|
+
const resolvedDelay = Number.isNaN(+delay) ? delay : +delay;
|
|
1346
|
+
const eventType = mutateEntryExit(resolvedDelay);
|
|
1303
1347
|
return toArray(resolvedTransition).map(transition => ({
|
|
1304
1348
|
...transition,
|
|
1305
1349
|
event: eventType,
|
|
@@ -2014,7 +2058,23 @@ function macrostep(state, event, actorScope, internalQueue = []) {
|
|
|
2014
2058
|
// Assume the state is at rest (no raised events)
|
|
2015
2059
|
// Determine the next state based on the next microstep
|
|
2016
2060
|
if (nextEvent.type !== XSTATE_INIT) {
|
|
2017
|
-
const
|
|
2061
|
+
const currentEvent = nextEvent;
|
|
2062
|
+
const isErr = isErrorActorEvent(currentEvent);
|
|
2063
|
+
const transitions = selectTransitions(currentEvent, nextState);
|
|
2064
|
+
if (isErr && !transitions.length) {
|
|
2065
|
+
// TODO: we should likely only allow transitions selected by very explicit descriptors
|
|
2066
|
+
// `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
|
|
2067
|
+
// similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
|
|
2068
|
+
nextState = cloneMachineSnapshot(state, {
|
|
2069
|
+
status: 'error',
|
|
2070
|
+
error: currentEvent.data
|
|
2071
|
+
});
|
|
2072
|
+
states.push(nextState);
|
|
2073
|
+
return {
|
|
2074
|
+
state: nextState,
|
|
2075
|
+
microstates: states
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2018
2078
|
nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
|
|
2019
2079
|
states.push(nextState);
|
|
2020
2080
|
}
|
|
@@ -2254,4 +2314,4 @@ function raise(eventOrExpr, options) {
|
|
|
2254
2314
|
return raise;
|
|
2255
2315
|
}
|
|
2256
2316
|
|
|
2257
|
-
export { $$ACTOR_TYPE as $,
|
|
2317
|
+
export { $$ACTOR_TYPE as $, Actor as A, interpret as B, isMachineSnapshot as C, matchesState as D, pathToStateValue as E, toObserver as F, getAllOwnEventDescriptors as G, and as H, not as I, or as J, stateIn as K, cancel as L, raise as M, NULL_EVENT as N, spawnChild as O, stop as P, stopChild as Q, ProcessingStatus as R, STATE_DELIMITER as S, cloneMachineSnapshot as T, XSTATE_ERROR as U, createErrorActorEvent as V, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, isStateId as v, getStateNodeByPath as w, getPersistedState as x, resolveReferencedActor as y, createActor as z };
|