xstate 5.0.0-beta.23 → 5.0.0-beta.25
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-0fcd4d15.development.cjs.js → actions-0971b43d.development.cjs.js} +88 -133
- package/dist/{actions-e83129c5.cjs.js → actions-319cefe7.cjs.js} +84 -137
- package/dist/{actions-bf7f6679.esm.js → actions-5943a9db.esm.js} +85 -137
- package/dist/{actions-f6b5002d.development.esm.js → actions-cf69419d.development.esm.js} +89 -133
- package/dist/declarations/src/Machine.d.ts +2 -2
- package/dist/declarations/src/State.d.ts +7 -3
- package/dist/declarations/src/StateMachine.d.ts +23 -17
- package/dist/declarations/src/StateNode.d.ts +23 -7
- package/dist/declarations/src/actions/choose.d.ts +4 -2
- package/dist/declarations/src/actions/pure.d.ts +6 -3
- package/dist/declarations/src/actions/raise.d.ts +2 -1
- package/dist/declarations/src/actions/send.d.ts +11 -55
- package/dist/declarations/src/guards.d.ts +20 -8
- package/dist/declarations/src/stateUtils.d.ts +10 -9
- package/dist/declarations/src/typegenTypes.d.ts +14 -2
- package/dist/declarations/src/types.d.ts +117 -142
- package/dist/declarations/src/utils.d.ts +3 -3
- package/dist/xstate.cjs.js +7 -3
- package/dist/xstate.development.cjs.js +7 -3
- package/dist/xstate.development.esm.js +8 -4
- package/dist/xstate.esm.js +8 -4
- 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
|
@@ -1496,148 +1496,108 @@ function invoke({
|
|
|
1496
1496
|
return invoke;
|
|
1497
1497
|
}
|
|
1498
1498
|
|
|
1499
|
+
function checkStateIn(state, _, {
|
|
1500
|
+
stateValue
|
|
1501
|
+
}) {
|
|
1502
|
+
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1503
|
+
return state.configuration.some(sn => sn.id === stateValue.slice(1));
|
|
1504
|
+
}
|
|
1505
|
+
return state.matches(stateValue);
|
|
1506
|
+
}
|
|
1499
1507
|
function stateIn(stateValue) {
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
stateValue
|
|
1504
|
-
},
|
|
1505
|
-
predicate: ({
|
|
1506
|
-
state
|
|
1507
|
-
}) => {
|
|
1508
|
-
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1509
|
-
return state.configuration.some(sn => sn.id === stateValue.slice(1));
|
|
1510
|
-
}
|
|
1511
|
-
return state.matches(stateValue);
|
|
1508
|
+
function stateIn(_) {
|
|
1509
|
+
{
|
|
1510
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1512
1511
|
}
|
|
1513
|
-
}
|
|
1512
|
+
}
|
|
1513
|
+
stateIn.check = checkStateIn;
|
|
1514
|
+
stateIn.stateValue = stateValue;
|
|
1515
|
+
return stateIn;
|
|
1516
|
+
}
|
|
1517
|
+
function checkNot(state, {
|
|
1518
|
+
context,
|
|
1519
|
+
event
|
|
1520
|
+
}, {
|
|
1521
|
+
guards
|
|
1522
|
+
}) {
|
|
1523
|
+
return !evaluateGuard(guards[0], context, event, state);
|
|
1514
1524
|
}
|
|
1515
1525
|
function not(guard) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
op: 'not'
|
|
1520
|
-
},
|
|
1521
|
-
children: [toGuardDefinition(guard)],
|
|
1522
|
-
predicate: ({
|
|
1523
|
-
evaluate,
|
|
1524
|
-
guard,
|
|
1525
|
-
context,
|
|
1526
|
-
event,
|
|
1527
|
-
state
|
|
1528
|
-
}) => {
|
|
1529
|
-
return !evaluate(guard.children[0], context, event, state);
|
|
1526
|
+
function not(_) {
|
|
1527
|
+
{
|
|
1528
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1530
1529
|
}
|
|
1531
|
-
}
|
|
1530
|
+
}
|
|
1531
|
+
not.check = checkNot;
|
|
1532
|
+
not.guards = [guard];
|
|
1533
|
+
return not;
|
|
1534
|
+
}
|
|
1535
|
+
function checkAnd(state, {
|
|
1536
|
+
context,
|
|
1537
|
+
event
|
|
1538
|
+
}, {
|
|
1539
|
+
guards
|
|
1540
|
+
}) {
|
|
1541
|
+
return guards.every(guard => evaluateGuard(guard, context, event, state));
|
|
1532
1542
|
}
|
|
1533
1543
|
function and(guards) {
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
op: 'and'
|
|
1538
|
-
},
|
|
1539
|
-
children: guards.map(guard => toGuardDefinition(guard)),
|
|
1540
|
-
predicate: ({
|
|
1541
|
-
evaluate,
|
|
1542
|
-
guard,
|
|
1543
|
-
context,
|
|
1544
|
-
event,
|
|
1545
|
-
state
|
|
1546
|
-
}) => {
|
|
1547
|
-
return guard.children.every(childGuard => {
|
|
1548
|
-
return evaluate(childGuard, context, event, state);
|
|
1549
|
-
});
|
|
1544
|
+
function and(_) {
|
|
1545
|
+
{
|
|
1546
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1550
1547
|
}
|
|
1551
|
-
}
|
|
1548
|
+
}
|
|
1549
|
+
and.check = checkAnd;
|
|
1550
|
+
and.guards = guards;
|
|
1551
|
+
return and;
|
|
1552
|
+
}
|
|
1553
|
+
function checkOr(state, {
|
|
1554
|
+
context,
|
|
1555
|
+
event
|
|
1556
|
+
}, {
|
|
1557
|
+
guards
|
|
1558
|
+
}) {
|
|
1559
|
+
return guards.some(guard => evaluateGuard(guard, context, event, state));
|
|
1552
1560
|
}
|
|
1553
1561
|
function or(guards) {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
op: 'or'
|
|
1558
|
-
},
|
|
1559
|
-
children: guards.map(guard => toGuardDefinition(guard)),
|
|
1560
|
-
predicate: ({
|
|
1561
|
-
evaluate,
|
|
1562
|
-
guard,
|
|
1563
|
-
context,
|
|
1564
|
-
event,
|
|
1565
|
-
state
|
|
1566
|
-
}) => {
|
|
1567
|
-
return guard.children.some(childGuard => {
|
|
1568
|
-
return evaluate(childGuard, context, event, state);
|
|
1569
|
-
});
|
|
1562
|
+
function or(_) {
|
|
1563
|
+
{
|
|
1564
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1570
1565
|
}
|
|
1571
|
-
}
|
|
1566
|
+
}
|
|
1567
|
+
or.check = checkOr;
|
|
1568
|
+
or.guards = guards;
|
|
1569
|
+
return or;
|
|
1572
1570
|
}
|
|
1571
|
+
|
|
1572
|
+
// TODO: throw on cycles (depth check should be enough)
|
|
1573
1573
|
function evaluateGuard(guard, context, event, state) {
|
|
1574
1574
|
const {
|
|
1575
1575
|
machine
|
|
1576
1576
|
} = state;
|
|
1577
|
-
const
|
|
1578
|
-
|
|
1579
|
-
|
|
1577
|
+
const isInline = typeof guard === 'function';
|
|
1578
|
+
const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
|
|
1579
|
+
if (!isInline && !resolved) {
|
|
1580
|
+
throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
|
|
1581
|
+
}
|
|
1582
|
+
if (typeof resolved !== 'function') {
|
|
1583
|
+
return evaluateGuard(resolved, context, event, state);
|
|
1580
1584
|
}
|
|
1581
|
-
|
|
1585
|
+
const guardArgs = {
|
|
1582
1586
|
context,
|
|
1583
1587
|
event,
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
const predicateOrDef = getPredicate?.(guardConfig);
|
|
1594
|
-
if (typeof predicateOrDef === 'function') {
|
|
1595
|
-
return {
|
|
1596
|
-
type: guardConfig,
|
|
1597
|
-
predicate: predicateOrDef,
|
|
1598
|
-
params: {
|
|
1599
|
-
type: guardConfig
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1602
|
-
} else if (predicateOrDef) {
|
|
1603
|
-
return predicateOrDef;
|
|
1604
|
-
} else {
|
|
1605
|
-
return {
|
|
1606
|
-
type: guardConfig,
|
|
1607
|
-
params: {
|
|
1608
|
-
type: guardConfig
|
|
1609
|
-
}
|
|
1610
|
-
};
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
if (typeof guardConfig === 'function') {
|
|
1614
|
-
return {
|
|
1615
|
-
type: guardConfig.name,
|
|
1616
|
-
predicate: guardConfig,
|
|
1617
|
-
params: {
|
|
1618
|
-
type: guardConfig.name,
|
|
1619
|
-
name: guardConfig.name
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
}
|
|
1623
|
-
const predicateOrDef = getPredicate?.(guardConfig.type);
|
|
1624
|
-
if (typeof predicateOrDef === 'function') {
|
|
1625
|
-
return {
|
|
1626
|
-
type: guardConfig.type,
|
|
1627
|
-
params: guardConfig.params || guardConfig,
|
|
1628
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1629
|
-
predicate: getPredicate?.(guardConfig.type) || guardConfig.predicate
|
|
1630
|
-
};
|
|
1631
|
-
} else if (predicateOrDef) {
|
|
1632
|
-
return predicateOrDef;
|
|
1633
|
-
} else {
|
|
1634
|
-
return {
|
|
1635
|
-
type: guardConfig.type,
|
|
1636
|
-
params: guardConfig.params || guardConfig,
|
|
1637
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1638
|
-
predicate: guardConfig.predicate
|
|
1639
|
-
};
|
|
1588
|
+
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1589
|
+
type: guard
|
|
1590
|
+
} : guard
|
|
1591
|
+
};
|
|
1592
|
+
if (!('check' in resolved)) {
|
|
1593
|
+
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
1594
|
+
// inline guards expect `TExpressionGuard` to be set to `undefined`
|
|
1595
|
+
// it's fine to cast this here, our logic makes sure that we call those 2 "variants" correctly
|
|
1596
|
+
return resolved(guardArgs);
|
|
1640
1597
|
}
|
|
1598
|
+
const builtinGuard = resolved;
|
|
1599
|
+
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
1600
|
+
);
|
|
1641
1601
|
}
|
|
1642
1602
|
|
|
1643
1603
|
function getOutput(configuration, context, event, self) {
|
|
@@ -1833,9 +1793,6 @@ function getDelayedTransitions(stateNode) {
|
|
|
1833
1793
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
1834
1794
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1835
1795
|
const reenter = transitionConfig.reenter ?? false;
|
|
1836
|
-
const {
|
|
1837
|
-
guards
|
|
1838
|
-
} = stateNode.machine.implementations;
|
|
1839
1796
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1840
1797
|
|
|
1841
1798
|
// TODO: should this be part of a lint rule instead?
|
|
@@ -1845,7 +1802,7 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1845
1802
|
const transition = {
|
|
1846
1803
|
...transitionConfig,
|
|
1847
1804
|
actions: toArray(transitionConfig.actions),
|
|
1848
|
-
guard: transitionConfig.guard
|
|
1805
|
+
guard: transitionConfig.guard,
|
|
1849
1806
|
target,
|
|
1850
1807
|
source: stateNode,
|
|
1851
1808
|
reenter,
|
|
@@ -2450,7 +2407,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2450
2407
|
if (!resolved) {
|
|
2451
2408
|
continue;
|
|
2452
2409
|
}
|
|
2453
|
-
const
|
|
2410
|
+
const actionArgs = {
|
|
2454
2411
|
context: intermediateState.context,
|
|
2455
2412
|
event,
|
|
2456
2413
|
self: actorCtx?.self,
|
|
@@ -2461,14 +2418,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2461
2418
|
};
|
|
2462
2419
|
if (!('resolve' in resolved)) {
|
|
2463
2420
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
2464
|
-
resolved(
|
|
2421
|
+
resolved(actionArgs);
|
|
2465
2422
|
} else {
|
|
2466
|
-
actorCtx?.defer(() => resolved(
|
|
2423
|
+
actorCtx?.defer(() => resolved(actionArgs));
|
|
2467
2424
|
}
|
|
2468
2425
|
continue;
|
|
2469
2426
|
}
|
|
2470
2427
|
const builtinAction = resolved;
|
|
2471
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState,
|
|
2428
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
|
|
2472
2429
|
);
|
|
2473
2430
|
|
|
2474
2431
|
intermediateState = nextState;
|
|
@@ -3034,8 +2991,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
3034
2991
|
branches
|
|
3035
2992
|
}) {
|
|
3036
2993
|
const matchedActions = branches.find(condition => {
|
|
3037
|
-
|
|
3038
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2994
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
3039
2995
|
})?.actions;
|
|
3040
2996
|
return [state, undefined, toArray(matchedActions)];
|
|
3041
2997
|
}
|
|
@@ -3206,7 +3162,6 @@ exports.stopSignal = stopSignal;
|
|
|
3206
3162
|
exports.stopSignalType = stopSignalType;
|
|
3207
3163
|
exports.toActorRef = toActorRef;
|
|
3208
3164
|
exports.toArray = toArray;
|
|
3209
|
-
exports.toGuardDefinition = toGuardDefinition;
|
|
3210
3165
|
exports.toInvokeConfig = toInvokeConfig;
|
|
3211
3166
|
exports.toObserver = toObserver;
|
|
3212
3167
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
@@ -1466,148 +1466,100 @@ 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
|
-
|
|
1539
|
+
const isInline = typeof guard === 'function';
|
|
1540
|
+
const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
|
|
1541
|
+
if (!isInline && !resolved) {
|
|
1542
|
+
throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
|
|
1543
|
+
}
|
|
1544
|
+
if (typeof resolved !== 'function') {
|
|
1545
|
+
return evaluateGuard(resolved, context, event, state);
|
|
1550
1546
|
}
|
|
1551
|
-
|
|
1547
|
+
const guardArgs = {
|
|
1552
1548
|
context,
|
|
1553
1549
|
event,
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
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
|
-
};
|
|
1550
|
+
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1551
|
+
type: guard
|
|
1552
|
+
} : guard
|
|
1553
|
+
};
|
|
1554
|
+
if (!('check' in resolved)) {
|
|
1555
|
+
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
1556
|
+
// inline guards expect `TExpressionGuard` to be set to `undefined`
|
|
1557
|
+
// it's fine to cast this here, our logic makes sure that we call those 2 "variants" correctly
|
|
1558
|
+
return resolved(guardArgs);
|
|
1610
1559
|
}
|
|
1560
|
+
const builtinGuard = resolved;
|
|
1561
|
+
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
1562
|
+
);
|
|
1611
1563
|
}
|
|
1612
1564
|
|
|
1613
1565
|
function getOutput(configuration, context, event, self) {
|
|
@@ -1797,14 +1749,11 @@ function getDelayedTransitions(stateNode) {
|
|
|
1797
1749
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
1798
1750
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1799
1751
|
const reenter = transitionConfig.reenter ?? false;
|
|
1800
|
-
const {
|
|
1801
|
-
guards
|
|
1802
|
-
} = stateNode.machine.implementations;
|
|
1803
1752
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1804
1753
|
const transition = {
|
|
1805
1754
|
...transitionConfig,
|
|
1806
1755
|
actions: toArray(transitionConfig.actions),
|
|
1807
|
-
guard: transitionConfig.guard
|
|
1756
|
+
guard: transitionConfig.guard,
|
|
1808
1757
|
target,
|
|
1809
1758
|
source: stateNode,
|
|
1810
1759
|
reenter,
|
|
@@ -2409,7 +2358,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2409
2358
|
if (!resolved) {
|
|
2410
2359
|
continue;
|
|
2411
2360
|
}
|
|
2412
|
-
const
|
|
2361
|
+
const actionArgs = {
|
|
2413
2362
|
context: intermediateState.context,
|
|
2414
2363
|
event,
|
|
2415
2364
|
self: actorCtx?.self,
|
|
@@ -2420,14 +2369,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2420
2369
|
};
|
|
2421
2370
|
if (!('resolve' in resolved)) {
|
|
2422
2371
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
2423
|
-
resolved(
|
|
2372
|
+
resolved(actionArgs);
|
|
2424
2373
|
} else {
|
|
2425
|
-
actorCtx?.defer(() => resolved(
|
|
2374
|
+
actorCtx?.defer(() => resolved(actionArgs));
|
|
2426
2375
|
}
|
|
2427
2376
|
continue;
|
|
2428
2377
|
}
|
|
2429
2378
|
const builtinAction = resolved;
|
|
2430
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState,
|
|
2379
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
|
|
2431
2380
|
);
|
|
2432
2381
|
|
|
2433
2382
|
intermediateState = nextState;
|
|
@@ -2975,8 +2924,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
2975
2924
|
branches
|
|
2976
2925
|
}) {
|
|
2977
2926
|
const matchedActions = branches.find(condition => {
|
|
2978
|
-
|
|
2979
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2927
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
2980
2928
|
})?.actions;
|
|
2981
2929
|
return [state, undefined, toArray(matchedActions)];
|
|
2982
2930
|
}
|
|
@@ -3141,7 +3089,6 @@ exports.stopSignal = stopSignal;
|
|
|
3141
3089
|
exports.stopSignalType = stopSignalType;
|
|
3142
3090
|
exports.toActorRef = toActorRef;
|
|
3143
3091
|
exports.toArray = toArray;
|
|
3144
|
-
exports.toGuardDefinition = toGuardDefinition;
|
|
3145
3092
|
exports.toInvokeConfig = toInvokeConfig;
|
|
3146
3093
|
exports.toObserver = toObserver;
|
|
3147
3094
|
exports.toTransitionConfigArray = toTransitionConfigArray;
|