xstate 5.0.0-beta.22 → 5.0.0-beta.24
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 +1 -1
- package/actions/dist/xstate-actions.development.cjs.js +1 -1
- 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 +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/{actions-d4305983.development.esm.js → actions-194e6dcc.development.esm.js} +100 -144
- package/dist/{actions-4b70fc8d.development.cjs.js → actions-43f7d40e.development.cjs.js} +99 -144
- package/dist/{actions-8f2e997e.cjs.js → actions-6a8cda73.cjs.js} +95 -148
- package/dist/{actions-fb7384f8.esm.js → actions-7b182232.esm.js} +96 -148
- package/dist/declarations/src/Machine.d.ts +2 -2
- package/dist/declarations/src/State.d.ts +5 -5
- package/dist/declarations/src/StateMachine.d.ts +27 -19
- package/dist/declarations/src/StateNode.d.ts +9 -9
- package/dist/declarations/src/actions/assign.d.ts +6 -6
- package/dist/declarations/src/actions/cancel.d.ts +7 -7
- package/dist/declarations/src/actions/choose.d.ts +4 -10
- package/dist/declarations/src/actions/log.d.ts +7 -7
- package/dist/declarations/src/actions/pure.d.ts +6 -17
- package/dist/declarations/src/actions/raise.d.ts +3 -3
- package/dist/declarations/src/actions/send.d.ts +22 -22
- package/dist/declarations/src/actions/stop.d.ts +7 -7
- package/dist/declarations/src/guards.d.ts +17 -8
- package/dist/declarations/src/interpreter.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +12 -12
- package/dist/declarations/src/typegenTypes.d.ts +6 -2
- package/dist/declarations/src/types.d.ts +130 -192
- package/dist/declarations/src/utils.d.ts +8 -8
- package/dist/xstate.cjs.js +10 -7
- package/dist/xstate.development.cjs.js +10 -7
- package/dist/xstate.development.esm.js +11 -8
- package/dist/xstate.esm.js +11 -8
- 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 -2
- package/guards/dist/xstate-guards.cjs.mjs +1 -2
- package/guards/dist/xstate-guards.development.cjs.js +1 -2
- package/guards/dist/xstate-guards.development.cjs.mjs +1 -2
- 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
|
@@ -1466,148 +1466,101 @@ function invoke({
|
|
|
1466
1466
|
return invoke;
|
|
1467
1467
|
}
|
|
1468
1468
|
|
|
1469
|
+
function checkStateIn(state, _, {
|
|
1470
|
+
stateValue
|
|
1471
|
+
}) {
|
|
1472
|
+
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1473
|
+
return state.configuration.some(sn => sn.id === stateValue.slice(1));
|
|
1474
|
+
}
|
|
1475
|
+
return state.matches(stateValue);
|
|
1476
|
+
}
|
|
1469
1477
|
function stateIn(stateValue) {
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1478
|
+
function stateIn(_) {
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
stateIn.check = checkStateIn;
|
|
1482
|
+
stateIn.stateValue = stateValue;
|
|
1483
|
+
return stateIn;
|
|
1484
|
+
}
|
|
1485
|
+
function checkNot(state, {
|
|
1486
|
+
context,
|
|
1487
|
+
event
|
|
1488
|
+
}, {
|
|
1489
|
+
guards
|
|
1490
|
+
}) {
|
|
1491
|
+
return !evaluateGuard(guards[0], context, event, state);
|
|
1484
1492
|
}
|
|
1485
1493
|
function not(guard) {
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
}
|
|
1501
|
-
};
|
|
1494
|
+
function not(_) {
|
|
1495
|
+
return false;
|
|
1496
|
+
}
|
|
1497
|
+
not.check = checkNot;
|
|
1498
|
+
not.guards = [guard];
|
|
1499
|
+
return not;
|
|
1500
|
+
}
|
|
1501
|
+
function checkAnd(state, {
|
|
1502
|
+
context,
|
|
1503
|
+
event
|
|
1504
|
+
}, {
|
|
1505
|
+
guards
|
|
1506
|
+
}) {
|
|
1507
|
+
return guards.every(guard => evaluateGuard(guard, context, event, state));
|
|
1502
1508
|
}
|
|
1503
1509
|
function and(guards) {
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
return evaluate(childGuard, context, event, state);
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1510
|
+
function and(_) {
|
|
1511
|
+
return false;
|
|
1512
|
+
}
|
|
1513
|
+
and.check = checkAnd;
|
|
1514
|
+
and.guards = guards;
|
|
1515
|
+
return and;
|
|
1516
|
+
}
|
|
1517
|
+
function checkOr(state, {
|
|
1518
|
+
context,
|
|
1519
|
+
event
|
|
1520
|
+
}, {
|
|
1521
|
+
guards
|
|
1522
|
+
}) {
|
|
1523
|
+
return guards.some(guard => evaluateGuard(guard, context, event, state));
|
|
1522
1524
|
}
|
|
1523
1525
|
function or(guards) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
predicate: ({
|
|
1531
|
-
evaluate,
|
|
1532
|
-
guard,
|
|
1533
|
-
context,
|
|
1534
|
-
event,
|
|
1535
|
-
state
|
|
1536
|
-
}) => {
|
|
1537
|
-
return guard.children.some(childGuard => {
|
|
1538
|
-
return evaluate(childGuard, context, event, state);
|
|
1539
|
-
});
|
|
1540
|
-
}
|
|
1541
|
-
};
|
|
1526
|
+
function or(_) {
|
|
1527
|
+
return false;
|
|
1528
|
+
}
|
|
1529
|
+
or.check = checkOr;
|
|
1530
|
+
or.guards = guards;
|
|
1531
|
+
return or;
|
|
1542
1532
|
}
|
|
1533
|
+
|
|
1534
|
+
// TODO: throw on cycles (depth check should be enough)
|
|
1543
1535
|
function evaluateGuard(guard, context, event, state) {
|
|
1544
1536
|
const {
|
|
1545
1537
|
machine
|
|
1546
1538
|
} = state;
|
|
1547
|
-
const
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1539
|
+
const isInline = typeof guard === 'function';
|
|
1540
|
+
const resolved = isInline ? guard :
|
|
1541
|
+
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
1542
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
1543
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
1544
|
+
machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
|
|
1545
|
+
if (!isInline && !resolved) {
|
|
1546
|
+
throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
|
|
1547
|
+
}
|
|
1548
|
+
if (typeof resolved !== 'function') {
|
|
1549
|
+
return evaluateGuard(resolved, context, event, state);
|
|
1550
|
+
}
|
|
1551
|
+
const guardArgs = {
|
|
1552
1552
|
context,
|
|
1553
1553
|
event,
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
// TODO: check for cycles and consider a refactor to more lazily evaluated guards
|
|
1561
|
-
// TODO: resolve this more recursively: https://github.com/statelyai/xstate/pull/4064#discussion_r1229915724
|
|
1562
|
-
if (typeof guardConfig === 'string') {
|
|
1563
|
-
const predicateOrDef = getPredicate?.(guardConfig);
|
|
1564
|
-
if (typeof predicateOrDef === 'function') {
|
|
1565
|
-
return {
|
|
1566
|
-
type: guardConfig,
|
|
1567
|
-
predicate: predicateOrDef,
|
|
1568
|
-
params: {
|
|
1569
|
-
type: guardConfig
|
|
1570
|
-
}
|
|
1571
|
-
};
|
|
1572
|
-
} else if (predicateOrDef) {
|
|
1573
|
-
return predicateOrDef;
|
|
1574
|
-
} else {
|
|
1575
|
-
return {
|
|
1576
|
-
type: guardConfig,
|
|
1577
|
-
params: {
|
|
1578
|
-
type: guardConfig
|
|
1579
|
-
}
|
|
1580
|
-
};
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
if (typeof guardConfig === 'function') {
|
|
1584
|
-
return {
|
|
1585
|
-
type: guardConfig.name,
|
|
1586
|
-
predicate: guardConfig,
|
|
1587
|
-
params: {
|
|
1588
|
-
type: guardConfig.name,
|
|
1589
|
-
name: guardConfig.name
|
|
1590
|
-
}
|
|
1591
|
-
};
|
|
1592
|
-
}
|
|
1593
|
-
const predicateOrDef = getPredicate?.(guardConfig.type);
|
|
1594
|
-
if (typeof predicateOrDef === 'function') {
|
|
1595
|
-
return {
|
|
1596
|
-
type: guardConfig.type,
|
|
1597
|
-
params: guardConfig.params || guardConfig,
|
|
1598
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1599
|
-
predicate: getPredicate?.(guardConfig.type) || guardConfig.predicate
|
|
1600
|
-
};
|
|
1601
|
-
} else if (predicateOrDef) {
|
|
1602
|
-
return predicateOrDef;
|
|
1603
|
-
} else {
|
|
1604
|
-
return {
|
|
1605
|
-
type: guardConfig.type,
|
|
1606
|
-
params: guardConfig.params || guardConfig,
|
|
1607
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1608
|
-
predicate: guardConfig.predicate
|
|
1609
|
-
};
|
|
1554
|
+
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1555
|
+
type: guard
|
|
1556
|
+
} : guard
|
|
1557
|
+
};
|
|
1558
|
+
if (!('check' in resolved)) {
|
|
1559
|
+
return resolved(guardArgs);
|
|
1610
1560
|
}
|
|
1561
|
+
const builtinGuard = resolved;
|
|
1562
|
+
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
1563
|
+
);
|
|
1611
1564
|
}
|
|
1612
1565
|
|
|
1613
1566
|
function getOutput(configuration, context, event, self) {
|
|
@@ -1797,14 +1750,11 @@ function getDelayedTransitions(stateNode) {
|
|
|
1797
1750
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
1798
1751
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1799
1752
|
const reenter = transitionConfig.reenter ?? false;
|
|
1800
|
-
const {
|
|
1801
|
-
guards
|
|
1802
|
-
} = stateNode.machine.implementations;
|
|
1803
1753
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1804
1754
|
const transition = {
|
|
1805
1755
|
...transitionConfig,
|
|
1806
1756
|
actions: toArray(transitionConfig.actions),
|
|
1807
|
-
guard: transitionConfig.guard
|
|
1757
|
+
guard: transitionConfig.guard,
|
|
1808
1758
|
target,
|
|
1809
1759
|
source: stateNode,
|
|
1810
1760
|
reenter,
|
|
@@ -2400,34 +2350,34 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2400
2350
|
_internalQueue: []
|
|
2401
2351
|
});
|
|
2402
2352
|
for (const action of actions) {
|
|
2403
|
-
const
|
|
2353
|
+
const isInline = typeof action === 'function';
|
|
2354
|
+
const resolved = isInline ? action :
|
|
2355
|
+
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2356
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2357
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2358
|
+
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
2404
2359
|
if (!resolved) {
|
|
2405
2360
|
continue;
|
|
2406
2361
|
}
|
|
2407
|
-
const
|
|
2362
|
+
const actionArgs = {
|
|
2408
2363
|
context: intermediateState.context,
|
|
2409
2364
|
event,
|
|
2410
2365
|
self: actorCtx?.self,
|
|
2411
2366
|
system: actorCtx?.system,
|
|
2412
|
-
|
|
2413
|
-
// what those ones should receive?
|
|
2414
|
-
//
|
|
2415
|
-
// entry: ({ action }) => {}
|
|
2416
|
-
// exit: assign(({ action }) => {})
|
|
2417
|
-
action: typeof action === 'string' ? {
|
|
2367
|
+
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2418
2368
|
type: action
|
|
2419
2369
|
} : action
|
|
2420
2370
|
};
|
|
2421
2371
|
if (!('resolve' in resolved)) {
|
|
2422
2372
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
2423
|
-
resolved(
|
|
2373
|
+
resolved(actionArgs);
|
|
2424
2374
|
} else {
|
|
2425
|
-
actorCtx?.defer(() => resolved(
|
|
2375
|
+
actorCtx?.defer(() => resolved(actionArgs));
|
|
2426
2376
|
}
|
|
2427
2377
|
continue;
|
|
2428
2378
|
}
|
|
2429
2379
|
const builtinAction = resolved;
|
|
2430
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState,
|
|
2380
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
|
|
2431
2381
|
);
|
|
2432
2382
|
|
|
2433
2383
|
intermediateState = nextState;
|
|
@@ -2551,9 +2501,8 @@ class State {
|
|
|
2551
2501
|
*/
|
|
2552
2502
|
|
|
2553
2503
|
/**
|
|
2554
|
-
* The
|
|
2504
|
+
* The output data of the top-level finite state.
|
|
2555
2505
|
*/
|
|
2556
|
-
// TODO: add an explicit type for `output`
|
|
2557
2506
|
|
|
2558
2507
|
/**
|
|
2559
2508
|
* The enabled state nodes representative of the state value.
|
|
@@ -2976,8 +2925,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
2976
2925
|
branches
|
|
2977
2926
|
}) {
|
|
2978
2927
|
const matchedActions = branches.find(condition => {
|
|
2979
|
-
|
|
2980
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2928
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
2981
2929
|
})?.actions;
|
|
2982
2930
|
return [state, undefined, toArray(matchedActions)];
|
|
2983
2931
|
}
|
|
@@ -2994,7 +2942,7 @@ function resolve(_, state, args, {
|
|
|
2994
2942
|
get
|
|
2995
2943
|
}) {
|
|
2996
2944
|
return [state, undefined, toArray(get({
|
|
2997
|
-
context:
|
|
2945
|
+
context: args.context,
|
|
2998
2946
|
event: args.event
|
|
2999
2947
|
}))];
|
|
3000
2948
|
}
|
|
@@ -3142,7 +3090,6 @@ exports.stopSignal = stopSignal;
|
|
|
3142
3090
|
exports.stopSignalType = stopSignalType;
|
|
3143
3091
|
exports.toActorRef = toActorRef;
|
|
3144
3092
|
exports.toArray = toArray;
|
|
3145
|
-
exports.toGuardDefinition = toGuardDefinition;
|
|
3146
3093
|
exports.toInvokeConfig = toInvokeConfig;
|
|
3147
3094
|
exports.toObserver = toObserver;
|
|
3148
3095
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
@@ -1464,148 +1464,101 @@ function invoke({
|
|
|
1464
1464
|
return invoke;
|
|
1465
1465
|
}
|
|
1466
1466
|
|
|
1467
|
+
function checkStateIn(state, _, {
|
|
1468
|
+
stateValue
|
|
1469
|
+
}) {
|
|
1470
|
+
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1471
|
+
return state.configuration.some(sn => sn.id === stateValue.slice(1));
|
|
1472
|
+
}
|
|
1473
|
+
return state.matches(stateValue);
|
|
1474
|
+
}
|
|
1467
1475
|
function stateIn(stateValue) {
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1476
|
+
function stateIn(_) {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
stateIn.check = checkStateIn;
|
|
1480
|
+
stateIn.stateValue = stateValue;
|
|
1481
|
+
return stateIn;
|
|
1482
|
+
}
|
|
1483
|
+
function checkNot(state, {
|
|
1484
|
+
context,
|
|
1485
|
+
event
|
|
1486
|
+
}, {
|
|
1487
|
+
guards
|
|
1488
|
+
}) {
|
|
1489
|
+
return !evaluateGuard(guards[0], context, event, state);
|
|
1482
1490
|
}
|
|
1483
1491
|
function not(guard) {
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1492
|
+
function not(_) {
|
|
1493
|
+
return false;
|
|
1494
|
+
}
|
|
1495
|
+
not.check = checkNot;
|
|
1496
|
+
not.guards = [guard];
|
|
1497
|
+
return not;
|
|
1498
|
+
}
|
|
1499
|
+
function checkAnd(state, {
|
|
1500
|
+
context,
|
|
1501
|
+
event
|
|
1502
|
+
}, {
|
|
1503
|
+
guards
|
|
1504
|
+
}) {
|
|
1505
|
+
return guards.every(guard => evaluateGuard(guard, context, event, state));
|
|
1500
1506
|
}
|
|
1501
1507
|
function and(guards) {
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
return evaluate(childGuard, context, event, state);
|
|
1517
|
-
});
|
|
1518
|
-
}
|
|
1519
|
-
};
|
|
1508
|
+
function and(_) {
|
|
1509
|
+
return false;
|
|
1510
|
+
}
|
|
1511
|
+
and.check = checkAnd;
|
|
1512
|
+
and.guards = guards;
|
|
1513
|
+
return and;
|
|
1514
|
+
}
|
|
1515
|
+
function checkOr(state, {
|
|
1516
|
+
context,
|
|
1517
|
+
event
|
|
1518
|
+
}, {
|
|
1519
|
+
guards
|
|
1520
|
+
}) {
|
|
1521
|
+
return guards.some(guard => evaluateGuard(guard, context, event, state));
|
|
1520
1522
|
}
|
|
1521
1523
|
function or(guards) {
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
predicate: ({
|
|
1529
|
-
evaluate,
|
|
1530
|
-
guard,
|
|
1531
|
-
context,
|
|
1532
|
-
event,
|
|
1533
|
-
state
|
|
1534
|
-
}) => {
|
|
1535
|
-
return guard.children.some(childGuard => {
|
|
1536
|
-
return evaluate(childGuard, context, event, state);
|
|
1537
|
-
});
|
|
1538
|
-
}
|
|
1539
|
-
};
|
|
1524
|
+
function or(_) {
|
|
1525
|
+
return false;
|
|
1526
|
+
}
|
|
1527
|
+
or.check = checkOr;
|
|
1528
|
+
or.guards = guards;
|
|
1529
|
+
return or;
|
|
1540
1530
|
}
|
|
1531
|
+
|
|
1532
|
+
// TODO: throw on cycles (depth check should be enough)
|
|
1541
1533
|
function evaluateGuard(guard, context, event, state) {
|
|
1542
1534
|
const {
|
|
1543
1535
|
machine
|
|
1544
1536
|
} = state;
|
|
1545
|
-
const
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1537
|
+
const isInline = typeof guard === 'function';
|
|
1538
|
+
const resolved = isInline ? guard :
|
|
1539
|
+
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
1540
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
1541
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
1542
|
+
machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
|
|
1543
|
+
if (!isInline && !resolved) {
|
|
1544
|
+
throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
|
|
1545
|
+
}
|
|
1546
|
+
if (typeof resolved !== 'function') {
|
|
1547
|
+
return evaluateGuard(resolved, context, event, state);
|
|
1548
|
+
}
|
|
1549
|
+
const guardArgs = {
|
|
1550
1550
|
context,
|
|
1551
1551
|
event,
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
// TODO: check for cycles and consider a refactor to more lazily evaluated guards
|
|
1559
|
-
// TODO: resolve this more recursively: https://github.com/statelyai/xstate/pull/4064#discussion_r1229915724
|
|
1560
|
-
if (typeof guardConfig === 'string') {
|
|
1561
|
-
const predicateOrDef = getPredicate?.(guardConfig);
|
|
1562
|
-
if (typeof predicateOrDef === 'function') {
|
|
1563
|
-
return {
|
|
1564
|
-
type: guardConfig,
|
|
1565
|
-
predicate: predicateOrDef,
|
|
1566
|
-
params: {
|
|
1567
|
-
type: guardConfig
|
|
1568
|
-
}
|
|
1569
|
-
};
|
|
1570
|
-
} else if (predicateOrDef) {
|
|
1571
|
-
return predicateOrDef;
|
|
1572
|
-
} else {
|
|
1573
|
-
return {
|
|
1574
|
-
type: guardConfig,
|
|
1575
|
-
params: {
|
|
1576
|
-
type: guardConfig
|
|
1577
|
-
}
|
|
1578
|
-
};
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
if (typeof guardConfig === 'function') {
|
|
1582
|
-
return {
|
|
1583
|
-
type: guardConfig.name,
|
|
1584
|
-
predicate: guardConfig,
|
|
1585
|
-
params: {
|
|
1586
|
-
type: guardConfig.name,
|
|
1587
|
-
name: guardConfig.name
|
|
1588
|
-
}
|
|
1589
|
-
};
|
|
1590
|
-
}
|
|
1591
|
-
const predicateOrDef = getPredicate?.(guardConfig.type);
|
|
1592
|
-
if (typeof predicateOrDef === 'function') {
|
|
1593
|
-
return {
|
|
1594
|
-
type: guardConfig.type,
|
|
1595
|
-
params: guardConfig.params || guardConfig,
|
|
1596
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1597
|
-
predicate: getPredicate?.(guardConfig.type) || guardConfig.predicate
|
|
1598
|
-
};
|
|
1599
|
-
} else if (predicateOrDef) {
|
|
1600
|
-
return predicateOrDef;
|
|
1601
|
-
} else {
|
|
1602
|
-
return {
|
|
1603
|
-
type: guardConfig.type,
|
|
1604
|
-
params: guardConfig.params || guardConfig,
|
|
1605
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1606
|
-
predicate: guardConfig.predicate
|
|
1607
|
-
};
|
|
1552
|
+
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1553
|
+
type: guard
|
|
1554
|
+
} : guard
|
|
1555
|
+
};
|
|
1556
|
+
if (!('check' in resolved)) {
|
|
1557
|
+
return resolved(guardArgs);
|
|
1608
1558
|
}
|
|
1559
|
+
const builtinGuard = resolved;
|
|
1560
|
+
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
1561
|
+
);
|
|
1609
1562
|
}
|
|
1610
1563
|
|
|
1611
1564
|
function getOutput(configuration, context, event, self) {
|
|
@@ -1795,14 +1748,11 @@ function getDelayedTransitions(stateNode) {
|
|
|
1795
1748
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
1796
1749
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1797
1750
|
const reenter = transitionConfig.reenter ?? false;
|
|
1798
|
-
const {
|
|
1799
|
-
guards
|
|
1800
|
-
} = stateNode.machine.implementations;
|
|
1801
1751
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1802
1752
|
const transition = {
|
|
1803
1753
|
...transitionConfig,
|
|
1804
1754
|
actions: toArray(transitionConfig.actions),
|
|
1805
|
-
guard: transitionConfig.guard
|
|
1755
|
+
guard: transitionConfig.guard,
|
|
1806
1756
|
target,
|
|
1807
1757
|
source: stateNode,
|
|
1808
1758
|
reenter,
|
|
@@ -2398,34 +2348,34 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2398
2348
|
_internalQueue: []
|
|
2399
2349
|
});
|
|
2400
2350
|
for (const action of actions) {
|
|
2401
|
-
const
|
|
2351
|
+
const isInline = typeof action === 'function';
|
|
2352
|
+
const resolved = isInline ? action :
|
|
2353
|
+
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2354
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2355
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2356
|
+
machine.implementations.actions[typeof action === 'string' ? action : action.type];
|
|
2402
2357
|
if (!resolved) {
|
|
2403
2358
|
continue;
|
|
2404
2359
|
}
|
|
2405
|
-
const
|
|
2360
|
+
const actionArgs = {
|
|
2406
2361
|
context: intermediateState.context,
|
|
2407
2362
|
event,
|
|
2408
2363
|
self: actorCtx?.self,
|
|
2409
2364
|
system: actorCtx?.system,
|
|
2410
|
-
|
|
2411
|
-
// what those ones should receive?
|
|
2412
|
-
//
|
|
2413
|
-
// entry: ({ action }) => {}
|
|
2414
|
-
// exit: assign(({ action }) => {})
|
|
2415
|
-
action: typeof action === 'string' ? {
|
|
2365
|
+
action: isInline ? undefined : typeof action === 'string' ? {
|
|
2416
2366
|
type: action
|
|
2417
2367
|
} : action
|
|
2418
2368
|
};
|
|
2419
2369
|
if (!('resolve' in resolved)) {
|
|
2420
2370
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
2421
|
-
resolved(
|
|
2371
|
+
resolved(actionArgs);
|
|
2422
2372
|
} else {
|
|
2423
|
-
actorCtx?.defer(() => resolved(
|
|
2373
|
+
actorCtx?.defer(() => resolved(actionArgs));
|
|
2424
2374
|
}
|
|
2425
2375
|
continue;
|
|
2426
2376
|
}
|
|
2427
2377
|
const builtinAction = resolved;
|
|
2428
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState,
|
|
2378
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
|
|
2429
2379
|
);
|
|
2430
2380
|
|
|
2431
2381
|
intermediateState = nextState;
|
|
@@ -2549,9 +2499,8 @@ class State {
|
|
|
2549
2499
|
*/
|
|
2550
2500
|
|
|
2551
2501
|
/**
|
|
2552
|
-
* The
|
|
2502
|
+
* The output data of the top-level finite state.
|
|
2553
2503
|
*/
|
|
2554
|
-
// TODO: add an explicit type for `output`
|
|
2555
2504
|
|
|
2556
2505
|
/**
|
|
2557
2506
|
* The enabled state nodes representative of the state value.
|
|
@@ -2974,8 +2923,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
2974
2923
|
branches
|
|
2975
2924
|
}) {
|
|
2976
2925
|
const matchedActions = branches.find(condition => {
|
|
2977
|
-
|
|
2978
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2926
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
2979
2927
|
})?.actions;
|
|
2980
2928
|
return [state, undefined, toArray(matchedActions)];
|
|
2981
2929
|
}
|
|
@@ -2992,7 +2940,7 @@ function resolve(_, state, args, {
|
|
|
2992
2940
|
get
|
|
2993
2941
|
}) {
|
|
2994
2942
|
return [state, undefined, toArray(get({
|
|
2995
|
-
context:
|
|
2943
|
+
context: args.context,
|
|
2996
2944
|
event: args.event
|
|
2997
2945
|
}))];
|
|
2998
2946
|
}
|
|
@@ -3068,4 +3016,4 @@ function createInitEvent(input) {
|
|
|
3068
3016
|
};
|
|
3069
3017
|
}
|
|
3070
3018
|
|
|
3071
|
-
export { fromObservable as $, microstep as A, isAtomicStateNode as B, isStateId as C, getStateNodeByPath as D, getPersistedState as E, resolveReferencedActor as F, createActor as G, matchesState as H, sendTo as I, sendParent as J, forwardTo as K, interpret as L, Actor as M, NULL_EVENT as N, ActorStatus as O, InterpreterStatus as P, doneInvoke as Q, cancel as R, STATE_DELIMITER as S, choose as T, log as U, pure as V, raise as W, stop as X, pathToStateValue as Y, toObserver as Z, fromPromise as _, toTransitionConfigArray as a, fromCallback as a0, fromEventObservable as a1, fromTransition as a2, stateIn as a3, not as a4, and as a5, or as a6, ConstantPrefix as a7, SpecialTargets as a8, startSignalType as a9, stopSignalType as aa, startSignal as ab, stopSignal as ac, isSignal as ad, isActorRef as ae, toActorRef as af, createEmptyActor as ag,
|
|
3019
|
+
export { fromObservable as $, microstep as A, isAtomicStateNode as B, isStateId as C, getStateNodeByPath as D, getPersistedState as E, resolveReferencedActor as F, createActor as G, matchesState as H, sendTo as I, sendParent as J, forwardTo as K, interpret as L, Actor as M, NULL_EVENT as N, ActorStatus as O, InterpreterStatus as P, doneInvoke as Q, cancel as R, STATE_DELIMITER as S, choose as T, log as U, pure as V, raise as W, stop as X, pathToStateValue as Y, toObserver as Z, fromPromise as _, toTransitionConfigArray as a, fromCallback as a0, fromEventObservable as a1, fromTransition as a2, stateIn as a3, not as a4, and as a5, or as a6, ConstantPrefix as a7, SpecialTargets as a8, startSignalType as a9, stopSignalType as aa, startSignal as ab, stopSignal as ac, isSignal as ad, isActorRef as ae, toActorRef as af, createEmptyActor as ag, constantPrefixes as ah, after as ai, done as aj, error as ak, escalate as al, formatTransition as b, memo as c, flatten as d, evaluateGuard as e, formatTransitions as f, createInvokeId as g, getDelayedTransitions as h, formatInitialTransition as i, getCandidates as j, toInvokeConfig as k, getConfiguration as l, mapValues as m, getStateNodes as n, isInFinalState as o, State as p, isErrorEvent as q, resolveStateValue as r, cloneState as s, toArray as t, macrostep as u, transitionNode as v, getInitialConfiguration as w, resolveActionsAndContext as x, assign as y, createInitEvent as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MachineConfig, EventObject, MachineContext, InternalMachineImplementations, ParameterizedObject, ProvidedActor, AnyEventObject } from "./types.js";
|
|
1
|
+
import { MachineConfig, EventObject, MachineContext, InternalMachineImplementations, ParameterizedObject, ProvidedActor, AnyEventObject, NonReducibleUnknown } from "./types.js";
|
|
2
2
|
import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from "./typegenTypes.js";
|
|
3
3
|
import { StateMachine } from "./StateMachine.js";
|
|
4
|
-
export declare function createMachine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TActor extends ProvidedActor = ProvidedActor, TInput = any, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent,
|
|
4
|
+
export declare function createMachine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TInput = any, TOutput = NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TAction, TGuard, TActor, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, TEvent, TActor, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard>>): StateMachine<TContext, TEvent, TActor, TAction, TGuard, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard>>;
|