xstate 5.0.0-beta.23 → 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-f6b5002d.development.esm.js → actions-194e6dcc.development.esm.js} +91 -134
- package/dist/{actions-0fcd4d15.development.cjs.js → actions-43f7d40e.development.cjs.js} +90 -134
- package/dist/{actions-e83129c5.cjs.js → actions-6a8cda73.cjs.js} +86 -138
- package/dist/{actions-bf7f6679.esm.js → actions-7b182232.esm.js} +87 -138
- package/dist/declarations/src/Machine.d.ts +1 -1
- package/dist/declarations/src/StateMachine.d.ts +8 -6
- package/dist/declarations/src/StateNode.d.ts +6 -6
- package/dist/declarations/src/actions/choose.d.ts +2 -2
- package/dist/declarations/src/actions/pure.d.ts +3 -2
- package/dist/declarations/src/actions/send.d.ts +1 -1
- package/dist/declarations/src/guards.d.ts +17 -8
- package/dist/declarations/src/stateUtils.d.ts +4 -4
- package/dist/declarations/src/typegenTypes.d.ts +6 -2
- package/dist/declarations/src/types.d.ts +77 -113
- package/dist/declarations/src/utils.d.ts +3 -3
- package/dist/xstate.cjs.js +5 -3
- package/dist/xstate.development.cjs.js +5 -3
- package/dist/xstate.development.esm.js +6 -4
- package/dist/xstate.esm.js +6 -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
|
@@ -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,
|
|
@@ -2409,7 +2359,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2409
2359
|
if (!resolved) {
|
|
2410
2360
|
continue;
|
|
2411
2361
|
}
|
|
2412
|
-
const
|
|
2362
|
+
const actionArgs = {
|
|
2413
2363
|
context: intermediateState.context,
|
|
2414
2364
|
event,
|
|
2415
2365
|
self: actorCtx?.self,
|
|
@@ -2420,14 +2370,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
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;
|
|
@@ -2975,8 +2925,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
2975
2925
|
branches
|
|
2976
2926
|
}) {
|
|
2977
2927
|
const matchedActions = branches.find(condition => {
|
|
2978
|
-
|
|
2979
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2928
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
2980
2929
|
})?.actions;
|
|
2981
2930
|
return [state, undefined, toArray(matchedActions)];
|
|
2982
2931
|
}
|
|
@@ -3141,7 +3090,6 @@ exports.stopSignal = stopSignal;
|
|
|
3141
3090
|
exports.stopSignalType = stopSignalType;
|
|
3142
3091
|
exports.toActorRef = toActorRef;
|
|
3143
3092
|
exports.toArray = toArray;
|
|
3144
|
-
exports.toGuardDefinition = toGuardDefinition;
|
|
3145
3093
|
exports.toInvokeConfig = toInvokeConfig;
|
|
3146
3094
|
exports.toObserver = toObserver;
|
|
3147
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,
|
|
@@ -2407,7 +2357,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2407
2357
|
if (!resolved) {
|
|
2408
2358
|
continue;
|
|
2409
2359
|
}
|
|
2410
|
-
const
|
|
2360
|
+
const actionArgs = {
|
|
2411
2361
|
context: intermediateState.context,
|
|
2412
2362
|
event,
|
|
2413
2363
|
self: actorCtx?.self,
|
|
@@ -2418,14 +2368,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
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;
|
|
@@ -2973,8 +2923,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
2973
2923
|
branches
|
|
2974
2924
|
}) {
|
|
2975
2925
|
const matchedActions = branches.find(condition => {
|
|
2976
|
-
|
|
2977
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2926
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
2978
2927
|
})?.actions;
|
|
2979
2928
|
return [state, undefined, toArray(matchedActions)];
|
|
2980
2929
|
}
|
|
@@ -3067,4 +3016,4 @@ function createInitEvent(input) {
|
|
|
3067
3016
|
};
|
|
3068
3017
|
}
|
|
3069
3018
|
|
|
3070
|
-
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
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,
|
|
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>>;
|
|
@@ -4,17 +4,17 @@ import type { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAs
|
|
|
4
4
|
import type { ActorContext, ActorLogic, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineTypes, NoInfer, StateConfig, StateMachineDefinition, StateValue, TransitionDefinition, PersistedMachineState, ParameterizedObject, AnyActorContext, ProvidedActor, Equals, TODO } from "./types.js";
|
|
5
5
|
export declare const STATE_IDENTIFIER = "#";
|
|
6
6
|
export declare const WILDCARD = "*";
|
|
7
|
-
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject,
|
|
7
|
+
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TInput, TOutput, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TActor, TAction, TGuard>> implements ActorLogic<TEvent, State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>, TODO, TInput, TOutput> {
|
|
8
8
|
/**
|
|
9
9
|
* The raw config used to create the machine.
|
|
10
10
|
*/
|
|
11
|
-
config: MachineConfig<TContext, TEvent, any, any, any, TOutput, any>;
|
|
11
|
+
config: MachineConfig<TContext, TEvent, any, any, any, any, TOutput, any>;
|
|
12
12
|
/**
|
|
13
13
|
* The machine's own version.
|
|
14
14
|
*/
|
|
15
15
|
version?: string;
|
|
16
16
|
implementations: MachineImplementationsSimplified<TContext, TEvent>;
|
|
17
|
-
types: MachineTypes<TContext, TEvent, TAction, TActor, TInput, TOutput>;
|
|
17
|
+
types: MachineTypes<TContext, TEvent, TAction, TGuard, TActor, TInput, TOutput, TResolvedTypesMeta>;
|
|
18
18
|
__xstatenode: true;
|
|
19
19
|
idMap: Map<string, StateNode<TContext, TEvent>>;
|
|
20
20
|
root: StateNode<TContext, TEvent>;
|
|
@@ -25,7 +25,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
25
25
|
/**
|
|
26
26
|
* The raw config used to create the machine.
|
|
27
27
|
*/
|
|
28
|
-
config: MachineConfig<TContext, TEvent, any, any, any, TOutput, any>, implementations?: MachineImplementationsSimplified<TContext, TEvent>);
|
|
28
|
+
config: MachineConfig<TContext, TEvent, any, any, any, any, TOutput, any>, implementations?: MachineImplementationsSimplified<TContext, TEvent>);
|
|
29
29
|
/**
|
|
30
30
|
* Clones this state machine with the provided implementations
|
|
31
31
|
* and merges the `context` (if provided).
|
|
@@ -35,7 +35,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
35
35
|
*
|
|
36
36
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
37
37
|
*/
|
|
38
|
-
provide(implementations: InternalMachineImplementations<TContext, TEvent,
|
|
38
|
+
provide(implementations: InternalMachineImplementations<TContext, TEvent, TActor, TAction, TResolvedTypesMeta, true>): StateMachine<TContext, TEvent, TActor, TAction, TGuard, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
|
|
39
39
|
/**
|
|
40
40
|
* Resolves the given `state` to a new `State` instance relative to this machine.
|
|
41
41
|
*
|
|
@@ -93,9 +93,11 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
93
93
|
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
94
94
|
__TEvent: TEvent;
|
|
95
95
|
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
96
|
+
__TActor: TActor;
|
|
97
|
+
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
96
98
|
__TAction: TAction;
|
|
97
99
|
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
98
|
-
|
|
100
|
+
__TGuard: TGuard;
|
|
99
101
|
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
100
102
|
__TInput: TInput;
|
|
101
103
|
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|