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
|
@@ -1464,148 +1464,100 @@ 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
|
-
|
|
1537
|
+
const isInline = typeof guard === 'function';
|
|
1538
|
+
const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
|
|
1539
|
+
if (!isInline && !resolved) {
|
|
1540
|
+
throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
|
|
1541
|
+
}
|
|
1542
|
+
if (typeof resolved !== 'function') {
|
|
1543
|
+
return evaluateGuard(resolved, context, event, state);
|
|
1548
1544
|
}
|
|
1549
|
-
|
|
1545
|
+
const guardArgs = {
|
|
1550
1546
|
context,
|
|
1551
1547
|
event,
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
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
|
-
};
|
|
1548
|
+
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1549
|
+
type: guard
|
|
1550
|
+
} : guard
|
|
1551
|
+
};
|
|
1552
|
+
if (!('check' in resolved)) {
|
|
1553
|
+
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
1554
|
+
// inline guards expect `TExpressionGuard` to be set to `undefined`
|
|
1555
|
+
// it's fine to cast this here, our logic makes sure that we call those 2 "variants" correctly
|
|
1556
|
+
return resolved(guardArgs);
|
|
1608
1557
|
}
|
|
1558
|
+
const builtinGuard = resolved;
|
|
1559
|
+
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
1560
|
+
);
|
|
1609
1561
|
}
|
|
1610
1562
|
|
|
1611
1563
|
function getOutput(configuration, context, event, self) {
|
|
@@ -1795,14 +1747,11 @@ function getDelayedTransitions(stateNode) {
|
|
|
1795
1747
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
1796
1748
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1797
1749
|
const reenter = transitionConfig.reenter ?? false;
|
|
1798
|
-
const {
|
|
1799
|
-
guards
|
|
1800
|
-
} = stateNode.machine.implementations;
|
|
1801
1750
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1802
1751
|
const transition = {
|
|
1803
1752
|
...transitionConfig,
|
|
1804
1753
|
actions: toArray(transitionConfig.actions),
|
|
1805
|
-
guard: transitionConfig.guard
|
|
1754
|
+
guard: transitionConfig.guard,
|
|
1806
1755
|
target,
|
|
1807
1756
|
source: stateNode,
|
|
1808
1757
|
reenter,
|
|
@@ -2407,7 +2356,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2407
2356
|
if (!resolved) {
|
|
2408
2357
|
continue;
|
|
2409
2358
|
}
|
|
2410
|
-
const
|
|
2359
|
+
const actionArgs = {
|
|
2411
2360
|
context: intermediateState.context,
|
|
2412
2361
|
event,
|
|
2413
2362
|
self: actorCtx?.self,
|
|
@@ -2418,14 +2367,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2418
2367
|
};
|
|
2419
2368
|
if (!('resolve' in resolved)) {
|
|
2420
2369
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
2421
|
-
resolved(
|
|
2370
|
+
resolved(actionArgs);
|
|
2422
2371
|
} else {
|
|
2423
|
-
actorCtx?.defer(() => resolved(
|
|
2372
|
+
actorCtx?.defer(() => resolved(actionArgs));
|
|
2424
2373
|
}
|
|
2425
2374
|
continue;
|
|
2426
2375
|
}
|
|
2427
2376
|
const builtinAction = resolved;
|
|
2428
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState,
|
|
2377
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
|
|
2429
2378
|
);
|
|
2430
2379
|
|
|
2431
2380
|
intermediateState = nextState;
|
|
@@ -2973,8 +2922,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
2973
2922
|
branches
|
|
2974
2923
|
}) {
|
|
2975
2924
|
const matchedActions = branches.find(condition => {
|
|
2976
|
-
|
|
2977
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2925
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
2978
2926
|
})?.actions;
|
|
2979
2927
|
return [state, undefined, toArray(matchedActions)];
|
|
2980
2928
|
}
|
|
@@ -3067,4 +3015,4 @@ function createInitEvent(input) {
|
|
|
3067
3015
|
};
|
|
3068
3016
|
}
|
|
3069
3017
|
|
|
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,
|
|
3018
|
+
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 };
|
|
@@ -1494,148 +1494,108 @@ function invoke({
|
|
|
1494
1494
|
return invoke;
|
|
1495
1495
|
}
|
|
1496
1496
|
|
|
1497
|
+
function checkStateIn(state, _, {
|
|
1498
|
+
stateValue
|
|
1499
|
+
}) {
|
|
1500
|
+
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1501
|
+
return state.configuration.some(sn => sn.id === stateValue.slice(1));
|
|
1502
|
+
}
|
|
1503
|
+
return state.matches(stateValue);
|
|
1504
|
+
}
|
|
1497
1505
|
function stateIn(stateValue) {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
stateValue
|
|
1502
|
-
},
|
|
1503
|
-
predicate: ({
|
|
1504
|
-
state
|
|
1505
|
-
}) => {
|
|
1506
|
-
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1507
|
-
return state.configuration.some(sn => sn.id === stateValue.slice(1));
|
|
1508
|
-
}
|
|
1509
|
-
return state.matches(stateValue);
|
|
1506
|
+
function stateIn(_) {
|
|
1507
|
+
{
|
|
1508
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1510
1509
|
}
|
|
1511
|
-
}
|
|
1510
|
+
}
|
|
1511
|
+
stateIn.check = checkStateIn;
|
|
1512
|
+
stateIn.stateValue = stateValue;
|
|
1513
|
+
return stateIn;
|
|
1514
|
+
}
|
|
1515
|
+
function checkNot(state, {
|
|
1516
|
+
context,
|
|
1517
|
+
event
|
|
1518
|
+
}, {
|
|
1519
|
+
guards
|
|
1520
|
+
}) {
|
|
1521
|
+
return !evaluateGuard(guards[0], context, event, state);
|
|
1512
1522
|
}
|
|
1513
1523
|
function not(guard) {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
op: 'not'
|
|
1518
|
-
},
|
|
1519
|
-
children: [toGuardDefinition(guard)],
|
|
1520
|
-
predicate: ({
|
|
1521
|
-
evaluate,
|
|
1522
|
-
guard,
|
|
1523
|
-
context,
|
|
1524
|
-
event,
|
|
1525
|
-
state
|
|
1526
|
-
}) => {
|
|
1527
|
-
return !evaluate(guard.children[0], context, event, state);
|
|
1524
|
+
function not(_) {
|
|
1525
|
+
{
|
|
1526
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1528
1527
|
}
|
|
1529
|
-
}
|
|
1528
|
+
}
|
|
1529
|
+
not.check = checkNot;
|
|
1530
|
+
not.guards = [guard];
|
|
1531
|
+
return not;
|
|
1532
|
+
}
|
|
1533
|
+
function checkAnd(state, {
|
|
1534
|
+
context,
|
|
1535
|
+
event
|
|
1536
|
+
}, {
|
|
1537
|
+
guards
|
|
1538
|
+
}) {
|
|
1539
|
+
return guards.every(guard => evaluateGuard(guard, context, event, state));
|
|
1530
1540
|
}
|
|
1531
1541
|
function and(guards) {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
op: 'and'
|
|
1536
|
-
},
|
|
1537
|
-
children: guards.map(guard => toGuardDefinition(guard)),
|
|
1538
|
-
predicate: ({
|
|
1539
|
-
evaluate,
|
|
1540
|
-
guard,
|
|
1541
|
-
context,
|
|
1542
|
-
event,
|
|
1543
|
-
state
|
|
1544
|
-
}) => {
|
|
1545
|
-
return guard.children.every(childGuard => {
|
|
1546
|
-
return evaluate(childGuard, context, event, state);
|
|
1547
|
-
});
|
|
1542
|
+
function and(_) {
|
|
1543
|
+
{
|
|
1544
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1548
1545
|
}
|
|
1549
|
-
}
|
|
1546
|
+
}
|
|
1547
|
+
and.check = checkAnd;
|
|
1548
|
+
and.guards = guards;
|
|
1549
|
+
return and;
|
|
1550
|
+
}
|
|
1551
|
+
function checkOr(state, {
|
|
1552
|
+
context,
|
|
1553
|
+
event
|
|
1554
|
+
}, {
|
|
1555
|
+
guards
|
|
1556
|
+
}) {
|
|
1557
|
+
return guards.some(guard => evaluateGuard(guard, context, event, state));
|
|
1550
1558
|
}
|
|
1551
1559
|
function or(guards) {
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
op: 'or'
|
|
1556
|
-
},
|
|
1557
|
-
children: guards.map(guard => toGuardDefinition(guard)),
|
|
1558
|
-
predicate: ({
|
|
1559
|
-
evaluate,
|
|
1560
|
-
guard,
|
|
1561
|
-
context,
|
|
1562
|
-
event,
|
|
1563
|
-
state
|
|
1564
|
-
}) => {
|
|
1565
|
-
return guard.children.some(childGuard => {
|
|
1566
|
-
return evaluate(childGuard, context, event, state);
|
|
1567
|
-
});
|
|
1560
|
+
function or(_) {
|
|
1561
|
+
{
|
|
1562
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1568
1563
|
}
|
|
1569
|
-
}
|
|
1564
|
+
}
|
|
1565
|
+
or.check = checkOr;
|
|
1566
|
+
or.guards = guards;
|
|
1567
|
+
return or;
|
|
1570
1568
|
}
|
|
1569
|
+
|
|
1570
|
+
// TODO: throw on cycles (depth check should be enough)
|
|
1571
1571
|
function evaluateGuard(guard, context, event, state) {
|
|
1572
1572
|
const {
|
|
1573
1573
|
machine
|
|
1574
1574
|
} = state;
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1575
|
+
const isInline = typeof guard === 'function';
|
|
1576
|
+
const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
|
|
1577
|
+
if (!isInline && !resolved) {
|
|
1578
|
+
throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
|
|
1579
|
+
}
|
|
1580
|
+
if (typeof resolved !== 'function') {
|
|
1581
|
+
return evaluateGuard(resolved, context, event, state);
|
|
1578
1582
|
}
|
|
1579
|
-
|
|
1583
|
+
const guardArgs = {
|
|
1580
1584
|
context,
|
|
1581
1585
|
event,
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
const predicateOrDef = getPredicate?.(guardConfig);
|
|
1592
|
-
if (typeof predicateOrDef === 'function') {
|
|
1593
|
-
return {
|
|
1594
|
-
type: guardConfig,
|
|
1595
|
-
predicate: predicateOrDef,
|
|
1596
|
-
params: {
|
|
1597
|
-
type: guardConfig
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
} else if (predicateOrDef) {
|
|
1601
|
-
return predicateOrDef;
|
|
1602
|
-
} else {
|
|
1603
|
-
return {
|
|
1604
|
-
type: guardConfig,
|
|
1605
|
-
params: {
|
|
1606
|
-
type: guardConfig
|
|
1607
|
-
}
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
if (typeof guardConfig === 'function') {
|
|
1612
|
-
return {
|
|
1613
|
-
type: guardConfig.name,
|
|
1614
|
-
predicate: guardConfig,
|
|
1615
|
-
params: {
|
|
1616
|
-
type: guardConfig.name,
|
|
1617
|
-
name: guardConfig.name
|
|
1618
|
-
}
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
const predicateOrDef = getPredicate?.(guardConfig.type);
|
|
1622
|
-
if (typeof predicateOrDef === 'function') {
|
|
1623
|
-
return {
|
|
1624
|
-
type: guardConfig.type,
|
|
1625
|
-
params: guardConfig.params || guardConfig,
|
|
1626
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1627
|
-
predicate: getPredicate?.(guardConfig.type) || guardConfig.predicate
|
|
1628
|
-
};
|
|
1629
|
-
} else if (predicateOrDef) {
|
|
1630
|
-
return predicateOrDef;
|
|
1631
|
-
} else {
|
|
1632
|
-
return {
|
|
1633
|
-
type: guardConfig.type,
|
|
1634
|
-
params: guardConfig.params || guardConfig,
|
|
1635
|
-
children: guardConfig.children?.map(childGuard => toGuardDefinition(childGuard, getPredicate)),
|
|
1636
|
-
predicate: guardConfig.predicate
|
|
1637
|
-
};
|
|
1586
|
+
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
1587
|
+
type: guard
|
|
1588
|
+
} : guard
|
|
1589
|
+
};
|
|
1590
|
+
if (!('check' in resolved)) {
|
|
1591
|
+
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
1592
|
+
// inline guards expect `TExpressionGuard` to be set to `undefined`
|
|
1593
|
+
// it's fine to cast this here, our logic makes sure that we call those 2 "variants" correctly
|
|
1594
|
+
return resolved(guardArgs);
|
|
1638
1595
|
}
|
|
1596
|
+
const builtinGuard = resolved;
|
|
1597
|
+
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
1598
|
+
);
|
|
1639
1599
|
}
|
|
1640
1600
|
|
|
1641
1601
|
function getOutput(configuration, context, event, self) {
|
|
@@ -1831,9 +1791,6 @@ function getDelayedTransitions(stateNode) {
|
|
|
1831
1791
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
1832
1792
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1833
1793
|
const reenter = transitionConfig.reenter ?? false;
|
|
1834
|
-
const {
|
|
1835
|
-
guards
|
|
1836
|
-
} = stateNode.machine.implementations;
|
|
1837
1794
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1838
1795
|
|
|
1839
1796
|
// TODO: should this be part of a lint rule instead?
|
|
@@ -1843,7 +1800,7 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1843
1800
|
const transition = {
|
|
1844
1801
|
...transitionConfig,
|
|
1845
1802
|
actions: toArray(transitionConfig.actions),
|
|
1846
|
-
guard: transitionConfig.guard
|
|
1803
|
+
guard: transitionConfig.guard,
|
|
1847
1804
|
target,
|
|
1848
1805
|
source: stateNode,
|
|
1849
1806
|
reenter,
|
|
@@ -2448,7 +2405,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2448
2405
|
if (!resolved) {
|
|
2449
2406
|
continue;
|
|
2450
2407
|
}
|
|
2451
|
-
const
|
|
2408
|
+
const actionArgs = {
|
|
2452
2409
|
context: intermediateState.context,
|
|
2453
2410
|
event,
|
|
2454
2411
|
self: actorCtx?.self,
|
|
@@ -2459,14 +2416,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
2459
2416
|
};
|
|
2460
2417
|
if (!('resolve' in resolved)) {
|
|
2461
2418
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
2462
|
-
resolved(
|
|
2419
|
+
resolved(actionArgs);
|
|
2463
2420
|
} else {
|
|
2464
|
-
actorCtx?.defer(() => resolved(
|
|
2421
|
+
actorCtx?.defer(() => resolved(actionArgs));
|
|
2465
2422
|
}
|
|
2466
2423
|
continue;
|
|
2467
2424
|
}
|
|
2468
2425
|
const builtinAction = resolved;
|
|
2469
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState,
|
|
2426
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
|
|
2470
2427
|
);
|
|
2471
2428
|
|
|
2472
2429
|
intermediateState = nextState;
|
|
@@ -3032,8 +2989,7 @@ function resolve$1(_, state, actionArgs, {
|
|
|
3032
2989
|
branches
|
|
3033
2990
|
}) {
|
|
3034
2991
|
const matchedActions = branches.find(condition => {
|
|
3035
|
-
|
|
3036
|
-
return !guard || evaluateGuard(guard, state.context, actionArgs.event, state);
|
|
2992
|
+
return !condition.guard || evaluateGuard(condition.guard, state.context, actionArgs.event, state);
|
|
3037
2993
|
})?.actions;
|
|
3038
2994
|
return [state, undefined, toArray(matchedActions)];
|
|
3039
2995
|
}
|
|
@@ -3132,4 +3088,4 @@ function createInitEvent(input) {
|
|
|
3132
3088
|
};
|
|
3133
3089
|
}
|
|
3134
3090
|
|
|
3135
|
-
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,
|
|
3091
|
+
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, NonReducibleUnknown } from "./types.js";
|
|
1
|
+
import { MachineConfig, EventObject, MachineContext, InternalMachineImplementations, ParameterizedObject, ProvidedActor, AnyEventObject, NonReducibleUnknown, Prop } 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, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, TEvent, TActor, TAction, TDelay, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, TActor, TAction, TGuard, TDelay, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
@@ -12,7 +12,7 @@ export declare function isStateConfig<TContext extends MachineContext, TEvent ex
|
|
|
12
12
|
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
|
|
13
13
|
*/
|
|
14
14
|
export declare const isState: typeof isStateConfig;
|
|
15
|
-
export declare class State<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TOutput, TResolvedTypesMeta = TypegenDisabled> {
|
|
15
|
+
export declare class State<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> {
|
|
16
16
|
machine: AnyStateMachine;
|
|
17
17
|
tags: Set<string>;
|
|
18
18
|
value: StateValue;
|
|
@@ -41,7 +41,11 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
|
|
|
41
41
|
* @param stateValue
|
|
42
42
|
* @param context
|
|
43
43
|
*/
|
|
44
|
-
static from<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: State<TContext, TEvent, TODO, any,
|
|
44
|
+
static from<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: State<TContext, TEvent, TODO, any, // tags
|
|
45
|
+
any, // output
|
|
46
|
+
any> | StateValue, context: TContext | undefined, machine: AnyStateMachine): State<TContext, TEvent, TODO, any, // tags
|
|
47
|
+
any, // output
|
|
48
|
+
any>;
|
|
45
49
|
/**
|
|
46
50
|
* Creates a new `State` instance that represents the current state of a running machine.
|
|
47
51
|
*
|
|
@@ -67,7 +71,7 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
|
|
|
67
71
|
* Whether the current state configuration has a state node with the specified `tag`.
|
|
68
72
|
* @param tag
|
|
69
73
|
*/
|
|
70
|
-
hasTag(tag:
|
|
74
|
+
hasTag(tag: TTag): boolean;
|
|
71
75
|
/**
|
|
72
76
|
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
73
77
|
* to be selected, even if the transitions have no actions nor
|