xstate 5.0.0-alpha.2 → 5.0.0-alpha.3
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.dev.js +1 -1
- package/actions/dist/xstate-actions.cjs.prod.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.dev.js +1 -1
- package/actors/dist/xstate-actors.cjs.prod.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-acb29ffe.cjs.prod.js → actions-3910d35f.cjs.prod.js} +94 -46
- package/dist/{actions-1e9778c2.cjs.dev.js → actions-3f0ba11b.cjs.dev.js} +94 -46
- package/dist/{actions-9778f6fb.esm.js → actions-4fe4ada8.esm.js} +94 -46
- package/dist/declarations/src/actions/pure.d.ts +4 -1
- package/dist/declarations/src/types.d.ts +38 -12
- package/dist/xstate.cjs.dev.js +5 -2
- package/dist/xstate.cjs.prod.js +5 -2
- package/dist/xstate.esm.js +6 -3
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.prod.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
|
@@ -346,14 +346,21 @@ function toArray(value) {
|
|
|
346
346
|
}
|
|
347
347
|
function mapContext(mapper, context, _event) {
|
|
348
348
|
if (isFunction(mapper)) {
|
|
349
|
-
return mapper(
|
|
349
|
+
return mapper({
|
|
350
|
+
context: context,
|
|
351
|
+
event: _event.data
|
|
352
|
+
});
|
|
350
353
|
}
|
|
351
354
|
var result = {};
|
|
355
|
+
var args = {
|
|
356
|
+
context: context,
|
|
357
|
+
event: _event.data
|
|
358
|
+
};
|
|
352
359
|
for (var _i4 = 0, _Object$keys2 = Object.keys(mapper); _i4 < _Object$keys2.length; _i4++) {
|
|
353
360
|
var _key3 = _Object$keys2[_i4];
|
|
354
361
|
var subMapper = mapper[_key3];
|
|
355
362
|
if (isFunction(subMapper)) {
|
|
356
|
-
result[_key3] = subMapper(
|
|
363
|
+
result[_key3] = subMapper(args);
|
|
357
364
|
} else {
|
|
358
365
|
result[_key3] = subMapper;
|
|
359
366
|
}
|
|
@@ -502,7 +509,9 @@ function send$1(eventOrExpr, options) {
|
|
|
502
509
|
// there is too big chance of the ID collision
|
|
503
510
|
id: options && options.id !== undefined ? options.id : isFunction(eventOrExpr) ? eventOrExpr.name : eventOrExpr.type
|
|
504
511
|
};
|
|
505
|
-
var
|
|
512
|
+
var args = {
|
|
513
|
+
context: state.context,
|
|
514
|
+
event: _event.data,
|
|
506
515
|
_event: _event,
|
|
507
516
|
state: state,
|
|
508
517
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : null,
|
|
@@ -511,15 +520,15 @@ function send$1(eventOrExpr, options) {
|
|
|
511
520
|
var delaysMap = state.machine.options.delays;
|
|
512
521
|
|
|
513
522
|
// TODO: helper function for resolving Expr
|
|
514
|
-
var resolvedEvent = toSCXMLEvent(isFunction(eventOrExpr) ? eventOrExpr(
|
|
523
|
+
var resolvedEvent = toSCXMLEvent(isFunction(eventOrExpr) ? eventOrExpr(args) : eventOrExpr);
|
|
515
524
|
var resolvedDelay;
|
|
516
525
|
if (isString(params.delay)) {
|
|
517
526
|
var configDelay = delaysMap && delaysMap[params.delay];
|
|
518
|
-
resolvedDelay = isFunction(configDelay) ? configDelay(
|
|
527
|
+
resolvedDelay = isFunction(configDelay) ? configDelay(args) : configDelay;
|
|
519
528
|
} else {
|
|
520
|
-
resolvedDelay = isFunction(params.delay) ? params.delay(
|
|
529
|
+
resolvedDelay = isFunction(params.delay) ? params.delay(args) : params.delay;
|
|
521
530
|
}
|
|
522
|
-
var resolvedTarget = isFunction(params.to) ? params.to(
|
|
531
|
+
var resolvedTarget = isFunction(params.to) ? params.to(args) : params.to;
|
|
523
532
|
var targetActorRef;
|
|
524
533
|
if (typeof resolvedTarget === 'string') {
|
|
525
534
|
if (resolvedTarget === exports.SpecialTargets.Parent) {
|
|
@@ -591,7 +600,7 @@ function sendParent(event, options) {
|
|
|
591
600
|
*/
|
|
592
601
|
function respond(event, options) {
|
|
593
602
|
return send$1(event, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
594
|
-
to: function to(
|
|
603
|
+
to: function to(_ref2) {
|
|
595
604
|
var _event = _ref2._event;
|
|
596
605
|
return _event.origin; // TODO: handle when _event.origin is undefined
|
|
597
606
|
}
|
|
@@ -615,7 +624,8 @@ function forwardTo(target, options) {
|
|
|
615
624
|
return resolvedTarget;
|
|
616
625
|
};
|
|
617
626
|
}
|
|
618
|
-
return send$1(function (
|
|
627
|
+
return send$1(function (_ref3) {
|
|
628
|
+
var event = _ref3.event;
|
|
619
629
|
return event;
|
|
620
630
|
}, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
621
631
|
to: target
|
|
@@ -630,10 +640,10 @@ function forwardTo(target, options) {
|
|
|
630
640
|
* @param options Options to pass into the send action creator.
|
|
631
641
|
*/
|
|
632
642
|
function escalate(errorData, options) {
|
|
633
|
-
return sendParent(function (
|
|
643
|
+
return sendParent(function (arg) {
|
|
634
644
|
return {
|
|
635
645
|
type: error,
|
|
636
|
-
data: isFunction(errorData) ? errorData(
|
|
646
|
+
data: isFunction(errorData) ? errorData(arg) : errorData
|
|
637
647
|
};
|
|
638
648
|
}, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
639
649
|
to: exports.SpecialTargets.Parent
|
|
@@ -1721,7 +1731,10 @@ function stop$1(actorRef) {
|
|
|
1721
1731
|
}
|
|
1722
1732
|
}, function (_event, _ref) {
|
|
1723
1733
|
var state = _ref.state;
|
|
1724
|
-
var actorRefOrString = isFunction(actor) ? actor(
|
|
1734
|
+
var actorRefOrString = isFunction(actor) ? actor({
|
|
1735
|
+
context: state.context,
|
|
1736
|
+
event: _event.data
|
|
1737
|
+
}) : actor;
|
|
1725
1738
|
var actorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
|
|
1726
1739
|
return [state, {
|
|
1727
1740
|
type: 'xstate.stop',
|
|
@@ -1744,7 +1757,9 @@ function stop$1(actorRef) {
|
|
|
1744
1757
|
});
|
|
1745
1758
|
}
|
|
1746
1759
|
|
|
1747
|
-
var defaultLogExpr = function defaultLogExpr(
|
|
1760
|
+
var defaultLogExpr = function defaultLogExpr(_ref) {
|
|
1761
|
+
var context = _ref.context,
|
|
1762
|
+
event = _ref.event;
|
|
1748
1763
|
return {
|
|
1749
1764
|
context: context,
|
|
1750
1765
|
event: event
|
|
@@ -1769,11 +1784,13 @@ function log$1() {
|
|
|
1769
1784
|
label: label,
|
|
1770
1785
|
expr: expr
|
|
1771
1786
|
}
|
|
1772
|
-
}, function (_event,
|
|
1787
|
+
}, function (_event, _ref2) {
|
|
1773
1788
|
var _actorContext$self;
|
|
1774
|
-
var state =
|
|
1775
|
-
actorContext =
|
|
1776
|
-
var resolvedValue = typeof expr === 'function' ? expr(
|
|
1789
|
+
var state = _ref2.state,
|
|
1790
|
+
actorContext = _ref2.actorContext;
|
|
1791
|
+
var resolvedValue = typeof expr === 'function' ? expr({
|
|
1792
|
+
context: state.context,
|
|
1793
|
+
event: _event.data,
|
|
1777
1794
|
_event: _event,
|
|
1778
1795
|
state: state,
|
|
1779
1796
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
@@ -1816,7 +1833,9 @@ function cancel$1(sendId) {
|
|
|
1816
1833
|
var _actorContext$self;
|
|
1817
1834
|
var state = _ref.state,
|
|
1818
1835
|
actorContext = _ref.actorContext;
|
|
1819
|
-
var resolvedSendId = isFunction(sendId) ? sendId(
|
|
1836
|
+
var resolvedSendId = isFunction(sendId) ? sendId({
|
|
1837
|
+
context: state.context,
|
|
1838
|
+
event: _event.data,
|
|
1820
1839
|
_event: _event,
|
|
1821
1840
|
state: state,
|
|
1822
1841
|
// TODO: fix types,
|
|
@@ -1883,7 +1902,7 @@ function stateIn(stateValue) {
|
|
|
1883
1902
|
params: {
|
|
1884
1903
|
stateValue: stateValue
|
|
1885
1904
|
},
|
|
1886
|
-
predicate: function predicate(
|
|
1905
|
+
predicate: function predicate(_ref) {
|
|
1887
1906
|
var state = _ref.state;
|
|
1888
1907
|
if (isString(stateValue) && isStateId(stateValue)) {
|
|
1889
1908
|
return state.configuration.some(function (sn) {
|
|
@@ -1901,8 +1920,13 @@ function not(guard) {
|
|
|
1901
1920
|
op: 'not'
|
|
1902
1921
|
},
|
|
1903
1922
|
children: [toGuardDefinition(guard)],
|
|
1904
|
-
predicate: function predicate(
|
|
1905
|
-
|
|
1923
|
+
predicate: function predicate(_ref2) {
|
|
1924
|
+
var evaluate = _ref2.evaluate,
|
|
1925
|
+
guard = _ref2.guard,
|
|
1926
|
+
context = _ref2.context,
|
|
1927
|
+
_event = _ref2._event,
|
|
1928
|
+
state = _ref2.state;
|
|
1929
|
+
return !evaluate(guard.children[0], context, _event, state);
|
|
1906
1930
|
}
|
|
1907
1931
|
};
|
|
1908
1932
|
}
|
|
@@ -1915,9 +1939,14 @@ function and(guards) {
|
|
|
1915
1939
|
children: guards.map(function (guard) {
|
|
1916
1940
|
return toGuardDefinition(guard);
|
|
1917
1941
|
}),
|
|
1918
|
-
predicate: function predicate(
|
|
1919
|
-
|
|
1920
|
-
|
|
1942
|
+
predicate: function predicate(_ref3) {
|
|
1943
|
+
var evaluate = _ref3.evaluate,
|
|
1944
|
+
guard = _ref3.guard,
|
|
1945
|
+
context = _ref3.context,
|
|
1946
|
+
_event = _ref3._event,
|
|
1947
|
+
state = _ref3.state;
|
|
1948
|
+
return guard.children.every(function (childGuard) {
|
|
1949
|
+
return evaluate(childGuard, context, _event, state);
|
|
1921
1950
|
});
|
|
1922
1951
|
}
|
|
1923
1952
|
};
|
|
@@ -1931,9 +1960,14 @@ function or(guards) {
|
|
|
1931
1960
|
children: guards.map(function (guard) {
|
|
1932
1961
|
return toGuardDefinition(guard);
|
|
1933
1962
|
}),
|
|
1934
|
-
predicate: function predicate(
|
|
1935
|
-
|
|
1936
|
-
|
|
1963
|
+
predicate: function predicate(_ref4) {
|
|
1964
|
+
var evaluate = _ref4.evaluate,
|
|
1965
|
+
guard = _ref4.guard,
|
|
1966
|
+
context = _ref4.context,
|
|
1967
|
+
_event = _ref4._event,
|
|
1968
|
+
state = _ref4.state;
|
|
1969
|
+
return guard.children.some(function (childGuard) {
|
|
1970
|
+
return evaluate(childGuard, context, _event, state);
|
|
1937
1971
|
});
|
|
1938
1972
|
}
|
|
1939
1973
|
};
|
|
@@ -1941,17 +1975,18 @@ function or(guards) {
|
|
|
1941
1975
|
function evaluateGuard(guard, context, _event, state) {
|
|
1942
1976
|
var _machine$options$guar, _machine$options, _machine$options$guar2;
|
|
1943
1977
|
var machine = state.machine;
|
|
1944
|
-
var guardMeta = {
|
|
1945
|
-
state: state,
|
|
1946
|
-
guard: guard,
|
|
1947
|
-
_event: _event,
|
|
1948
|
-
evaluate: evaluateGuard
|
|
1949
|
-
};
|
|
1950
1978
|
var predicate = (_machine$options$guar = machine === null || machine === void 0 ? void 0 : (_machine$options = machine.options) === null || _machine$options === void 0 ? void 0 : (_machine$options$guar2 = _machine$options.guards) === null || _machine$options$guar2 === void 0 ? void 0 : _machine$options$guar2[guard.type]) !== null && _machine$options$guar !== void 0 ? _machine$options$guar : guard.predicate;
|
|
1951
1979
|
if (!predicate) {
|
|
1952
1980
|
throw new Error("Guard '".concat(guard.type, "' is not implemented.'."));
|
|
1953
1981
|
}
|
|
1954
|
-
return predicate(
|
|
1982
|
+
return predicate({
|
|
1983
|
+
context: context,
|
|
1984
|
+
event: _event.data,
|
|
1985
|
+
state: state,
|
|
1986
|
+
guard: guard,
|
|
1987
|
+
_event: _event,
|
|
1988
|
+
evaluate: evaluateGuard
|
|
1989
|
+
});
|
|
1955
1990
|
}
|
|
1956
1991
|
function toGuardDefinition(guardConfig, getPredicate) {
|
|
1957
1992
|
var _guardConfig$children;
|
|
@@ -3794,8 +3829,10 @@ function invoke$1(invokeDef) {
|
|
|
3794
3829
|
src: src,
|
|
3795
3830
|
parent: actorContext === null || actorContext === void 0 ? void 0 : actorContext.self,
|
|
3796
3831
|
systemId: invokeDef.systemId,
|
|
3797
|
-
input: typeof input === 'function' ? input(
|
|
3798
|
-
|
|
3832
|
+
input: typeof input === 'function' ? input({
|
|
3833
|
+
context: state.context,
|
|
3834
|
+
event: _event.data,
|
|
3835
|
+
self: actorContext === null || actorContext === void 0 ? void 0 : actorContext.self
|
|
3799
3836
|
}) : input
|
|
3800
3837
|
});
|
|
3801
3838
|
resolvedInvokeAction = {
|
|
@@ -3849,7 +3886,9 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
|
|
|
3849
3886
|
var actorRef = interpret(referenced.src, {
|
|
3850
3887
|
id: resolvedName,
|
|
3851
3888
|
parent: self,
|
|
3852
|
-
input: typeof input === 'function' ? input(
|
|
3889
|
+
input: typeof input === 'function' ? input({
|
|
3890
|
+
context: context,
|
|
3891
|
+
event: _event.data,
|
|
3853
3892
|
self: self
|
|
3854
3893
|
}) : input
|
|
3855
3894
|
});
|
|
@@ -3907,7 +3946,9 @@ function assign$1(assignment) {
|
|
|
3907
3946
|
if (!state.context) {
|
|
3908
3947
|
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
3909
3948
|
}
|
|
3910
|
-
var
|
|
3949
|
+
var args = {
|
|
3950
|
+
context: state.context,
|
|
3951
|
+
event: _event.data,
|
|
3911
3952
|
state: state,
|
|
3912
3953
|
action: action,
|
|
3913
3954
|
_event: _event,
|
|
@@ -3917,12 +3958,12 @@ function assign$1(assignment) {
|
|
|
3917
3958
|
};
|
|
3918
3959
|
var partialUpdate = {};
|
|
3919
3960
|
if (isFunction(assignment)) {
|
|
3920
|
-
partialUpdate = assignment(
|
|
3961
|
+
partialUpdate = assignment(args);
|
|
3921
3962
|
} else {
|
|
3922
3963
|
for (var _i = 0, _Object$keys = Object.keys(assignment); _i < _Object$keys.length; _i++) {
|
|
3923
3964
|
var key = _Object$keys[_i];
|
|
3924
3965
|
var propAssignment = assignment[key];
|
|
3925
|
-
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(
|
|
3966
|
+
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(args) : propAssignment;
|
|
3926
3967
|
}
|
|
3927
3968
|
}
|
|
3928
3969
|
var updatedContext = Object.assign({}, state.context, partialUpdate);
|
|
@@ -3962,22 +4003,25 @@ function raise$1(eventOrExpr, options) {
|
|
|
3962
4003
|
event: eventOrExpr,
|
|
3963
4004
|
id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
|
|
3964
4005
|
};
|
|
3965
|
-
var
|
|
4006
|
+
var args = {
|
|
4007
|
+
context: state.context,
|
|
4008
|
+
event: _event.data,
|
|
3966
4009
|
_event: _event,
|
|
3967
4010
|
state: state,
|
|
4011
|
+
// TODO: fix
|
|
3968
4012
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
3969
4013
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
3970
4014
|
};
|
|
3971
4015
|
var delaysMap = state.machine.options.delays;
|
|
3972
4016
|
|
|
3973
4017
|
// TODO: helper function for resolving Expr
|
|
3974
|
-
var resolvedEvent = toSCXMLEvent(typeof eventOrExpr === 'function' ? eventOrExpr(
|
|
4018
|
+
var resolvedEvent = toSCXMLEvent(typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr);
|
|
3975
4019
|
var resolvedDelay;
|
|
3976
4020
|
if (typeof params.delay === 'string') {
|
|
3977
4021
|
var configDelay = delaysMap && delaysMap[params.delay];
|
|
3978
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(
|
|
4022
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
|
|
3979
4023
|
} else {
|
|
3980
|
-
resolvedDelay = typeof params.delay === 'function' ? params.delay(
|
|
4024
|
+
resolvedDelay = typeof params.delay === 'function' ? params.delay(args) : params.delay;
|
|
3981
4025
|
}
|
|
3982
4026
|
var resolvedAction = {
|
|
3983
4027
|
type: raise,
|
|
@@ -4040,7 +4084,9 @@ function resolveActionObject(actionObject, actionFunctionMap) {
|
|
|
4040
4084
|
type: actionObject.type,
|
|
4041
4085
|
params: actionObject.params,
|
|
4042
4086
|
execute: function execute(actorCtx) {
|
|
4043
|
-
return dereferencedAction(
|
|
4087
|
+
return dereferencedAction({
|
|
4088
|
+
context: state.context,
|
|
4089
|
+
event: state.event,
|
|
4044
4090
|
action: a,
|
|
4045
4091
|
_event: state._event,
|
|
4046
4092
|
state: state,
|
|
@@ -4080,7 +4126,9 @@ function toActionObject(action) {
|
|
|
4080
4126
|
"function": action
|
|
4081
4127
|
},
|
|
4082
4128
|
execute: function execute(actorCtx) {
|
|
4083
|
-
return action(
|
|
4129
|
+
return action({
|
|
4130
|
+
context: state.context,
|
|
4131
|
+
event: _event.data,
|
|
4084
4132
|
action: actionObject,
|
|
4085
4133
|
_event: _event,
|
|
4086
4134
|
state: state,
|
|
@@ -346,14 +346,21 @@ function toArray(value) {
|
|
|
346
346
|
}
|
|
347
347
|
function mapContext(mapper, context, _event) {
|
|
348
348
|
if (isFunction(mapper)) {
|
|
349
|
-
return mapper(
|
|
349
|
+
return mapper({
|
|
350
|
+
context: context,
|
|
351
|
+
event: _event.data
|
|
352
|
+
});
|
|
350
353
|
}
|
|
351
354
|
var result = {};
|
|
355
|
+
var args = {
|
|
356
|
+
context: context,
|
|
357
|
+
event: _event.data
|
|
358
|
+
};
|
|
352
359
|
for (var _i4 = 0, _Object$keys2 = Object.keys(mapper); _i4 < _Object$keys2.length; _i4++) {
|
|
353
360
|
var _key3 = _Object$keys2[_i4];
|
|
354
361
|
var subMapper = mapper[_key3];
|
|
355
362
|
if (isFunction(subMapper)) {
|
|
356
|
-
result[_key3] = subMapper(
|
|
363
|
+
result[_key3] = subMapper(args);
|
|
357
364
|
} else {
|
|
358
365
|
result[_key3] = subMapper;
|
|
359
366
|
}
|
|
@@ -518,7 +525,9 @@ function send$1(eventOrExpr, options) {
|
|
|
518
525
|
// there is too big chance of the ID collision
|
|
519
526
|
id: options && options.id !== undefined ? options.id : isFunction(eventOrExpr) ? eventOrExpr.name : eventOrExpr.type
|
|
520
527
|
};
|
|
521
|
-
var
|
|
528
|
+
var args = {
|
|
529
|
+
context: state.context,
|
|
530
|
+
event: _event.data,
|
|
522
531
|
_event: _event,
|
|
523
532
|
state: state,
|
|
524
533
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : null,
|
|
@@ -527,15 +536,15 @@ function send$1(eventOrExpr, options) {
|
|
|
527
536
|
var delaysMap = state.machine.options.delays;
|
|
528
537
|
|
|
529
538
|
// TODO: helper function for resolving Expr
|
|
530
|
-
var resolvedEvent = toSCXMLEvent(isFunction(eventOrExpr) ? eventOrExpr(
|
|
539
|
+
var resolvedEvent = toSCXMLEvent(isFunction(eventOrExpr) ? eventOrExpr(args) : eventOrExpr);
|
|
531
540
|
var resolvedDelay;
|
|
532
541
|
if (isString(params.delay)) {
|
|
533
542
|
var configDelay = delaysMap && delaysMap[params.delay];
|
|
534
|
-
resolvedDelay = isFunction(configDelay) ? configDelay(
|
|
543
|
+
resolvedDelay = isFunction(configDelay) ? configDelay(args) : configDelay;
|
|
535
544
|
} else {
|
|
536
|
-
resolvedDelay = isFunction(params.delay) ? params.delay(
|
|
545
|
+
resolvedDelay = isFunction(params.delay) ? params.delay(args) : params.delay;
|
|
537
546
|
}
|
|
538
|
-
var resolvedTarget = isFunction(params.to) ? params.to(
|
|
547
|
+
var resolvedTarget = isFunction(params.to) ? params.to(args) : params.to;
|
|
539
548
|
var targetActorRef;
|
|
540
549
|
if (typeof resolvedTarget === 'string') {
|
|
541
550
|
if (resolvedTarget === exports.SpecialTargets.Parent) {
|
|
@@ -607,7 +616,7 @@ function sendParent(event, options) {
|
|
|
607
616
|
*/
|
|
608
617
|
function respond(event, options) {
|
|
609
618
|
return send$1(event, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
610
|
-
to: function to(
|
|
619
|
+
to: function to(_ref2) {
|
|
611
620
|
var _event = _ref2._event;
|
|
612
621
|
return _event.origin; // TODO: handle when _event.origin is undefined
|
|
613
622
|
}
|
|
@@ -631,7 +640,8 @@ function forwardTo(target, options) {
|
|
|
631
640
|
return resolvedTarget;
|
|
632
641
|
};
|
|
633
642
|
}
|
|
634
|
-
return send$1(function (
|
|
643
|
+
return send$1(function (_ref3) {
|
|
644
|
+
var event = _ref3.event;
|
|
635
645
|
return event;
|
|
636
646
|
}, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
637
647
|
to: target
|
|
@@ -646,10 +656,10 @@ function forwardTo(target, options) {
|
|
|
646
656
|
* @param options Options to pass into the send action creator.
|
|
647
657
|
*/
|
|
648
658
|
function escalate(errorData, options) {
|
|
649
|
-
return sendParent(function (
|
|
659
|
+
return sendParent(function (arg) {
|
|
650
660
|
return {
|
|
651
661
|
type: error,
|
|
652
|
-
data: isFunction(errorData) ? errorData(
|
|
662
|
+
data: isFunction(errorData) ? errorData(arg) : errorData
|
|
653
663
|
};
|
|
654
664
|
}, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
655
665
|
to: exports.SpecialTargets.Parent
|
|
@@ -1742,7 +1752,10 @@ function stop$1(actorRef) {
|
|
|
1742
1752
|
}
|
|
1743
1753
|
}, function (_event, _ref) {
|
|
1744
1754
|
var state = _ref.state;
|
|
1745
|
-
var actorRefOrString = isFunction(actor) ? actor(
|
|
1755
|
+
var actorRefOrString = isFunction(actor) ? actor({
|
|
1756
|
+
context: state.context,
|
|
1757
|
+
event: _event.data
|
|
1758
|
+
}) : actor;
|
|
1746
1759
|
var actorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
|
|
1747
1760
|
return [state, {
|
|
1748
1761
|
type: 'xstate.stop',
|
|
@@ -1765,7 +1778,9 @@ function stop$1(actorRef) {
|
|
|
1765
1778
|
});
|
|
1766
1779
|
}
|
|
1767
1780
|
|
|
1768
|
-
var defaultLogExpr = function defaultLogExpr(
|
|
1781
|
+
var defaultLogExpr = function defaultLogExpr(_ref) {
|
|
1782
|
+
var context = _ref.context,
|
|
1783
|
+
event = _ref.event;
|
|
1769
1784
|
return {
|
|
1770
1785
|
context: context,
|
|
1771
1786
|
event: event
|
|
@@ -1790,11 +1805,13 @@ function log$1() {
|
|
|
1790
1805
|
label: label,
|
|
1791
1806
|
expr: expr
|
|
1792
1807
|
}
|
|
1793
|
-
}, function (_event,
|
|
1808
|
+
}, function (_event, _ref2) {
|
|
1794
1809
|
var _actorContext$self;
|
|
1795
|
-
var state =
|
|
1796
|
-
actorContext =
|
|
1797
|
-
var resolvedValue = typeof expr === 'function' ? expr(
|
|
1810
|
+
var state = _ref2.state,
|
|
1811
|
+
actorContext = _ref2.actorContext;
|
|
1812
|
+
var resolvedValue = typeof expr === 'function' ? expr({
|
|
1813
|
+
context: state.context,
|
|
1814
|
+
event: _event.data,
|
|
1798
1815
|
_event: _event,
|
|
1799
1816
|
state: state,
|
|
1800
1817
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
@@ -1837,7 +1854,9 @@ function cancel$1(sendId) {
|
|
|
1837
1854
|
var _actorContext$self;
|
|
1838
1855
|
var state = _ref.state,
|
|
1839
1856
|
actorContext = _ref.actorContext;
|
|
1840
|
-
var resolvedSendId = isFunction(sendId) ? sendId(
|
|
1857
|
+
var resolvedSendId = isFunction(sendId) ? sendId({
|
|
1858
|
+
context: state.context,
|
|
1859
|
+
event: _event.data,
|
|
1841
1860
|
_event: _event,
|
|
1842
1861
|
state: state,
|
|
1843
1862
|
// TODO: fix types,
|
|
@@ -1904,7 +1923,7 @@ function stateIn(stateValue) {
|
|
|
1904
1923
|
params: {
|
|
1905
1924
|
stateValue: stateValue
|
|
1906
1925
|
},
|
|
1907
|
-
predicate: function predicate(
|
|
1926
|
+
predicate: function predicate(_ref) {
|
|
1908
1927
|
var state = _ref.state;
|
|
1909
1928
|
if (isString(stateValue) && isStateId(stateValue)) {
|
|
1910
1929
|
return state.configuration.some(function (sn) {
|
|
@@ -1922,8 +1941,13 @@ function not(guard) {
|
|
|
1922
1941
|
op: 'not'
|
|
1923
1942
|
},
|
|
1924
1943
|
children: [toGuardDefinition(guard)],
|
|
1925
|
-
predicate: function predicate(
|
|
1926
|
-
|
|
1944
|
+
predicate: function predicate(_ref2) {
|
|
1945
|
+
var evaluate = _ref2.evaluate,
|
|
1946
|
+
guard = _ref2.guard,
|
|
1947
|
+
context = _ref2.context,
|
|
1948
|
+
_event = _ref2._event,
|
|
1949
|
+
state = _ref2.state;
|
|
1950
|
+
return !evaluate(guard.children[0], context, _event, state);
|
|
1927
1951
|
}
|
|
1928
1952
|
};
|
|
1929
1953
|
}
|
|
@@ -1936,9 +1960,14 @@ function and(guards) {
|
|
|
1936
1960
|
children: guards.map(function (guard) {
|
|
1937
1961
|
return toGuardDefinition(guard);
|
|
1938
1962
|
}),
|
|
1939
|
-
predicate: function predicate(
|
|
1940
|
-
|
|
1941
|
-
|
|
1963
|
+
predicate: function predicate(_ref3) {
|
|
1964
|
+
var evaluate = _ref3.evaluate,
|
|
1965
|
+
guard = _ref3.guard,
|
|
1966
|
+
context = _ref3.context,
|
|
1967
|
+
_event = _ref3._event,
|
|
1968
|
+
state = _ref3.state;
|
|
1969
|
+
return guard.children.every(function (childGuard) {
|
|
1970
|
+
return evaluate(childGuard, context, _event, state);
|
|
1942
1971
|
});
|
|
1943
1972
|
}
|
|
1944
1973
|
};
|
|
@@ -1952,9 +1981,14 @@ function or(guards) {
|
|
|
1952
1981
|
children: guards.map(function (guard) {
|
|
1953
1982
|
return toGuardDefinition(guard);
|
|
1954
1983
|
}),
|
|
1955
|
-
predicate: function predicate(
|
|
1956
|
-
|
|
1957
|
-
|
|
1984
|
+
predicate: function predicate(_ref4) {
|
|
1985
|
+
var evaluate = _ref4.evaluate,
|
|
1986
|
+
guard = _ref4.guard,
|
|
1987
|
+
context = _ref4.context,
|
|
1988
|
+
_event = _ref4._event,
|
|
1989
|
+
state = _ref4.state;
|
|
1990
|
+
return guard.children.some(function (childGuard) {
|
|
1991
|
+
return evaluate(childGuard, context, _event, state);
|
|
1958
1992
|
});
|
|
1959
1993
|
}
|
|
1960
1994
|
};
|
|
@@ -1962,17 +1996,18 @@ function or(guards) {
|
|
|
1962
1996
|
function evaluateGuard(guard, context, _event, state) {
|
|
1963
1997
|
var _machine$options$guar, _machine$options, _machine$options$guar2;
|
|
1964
1998
|
var machine = state.machine;
|
|
1965
|
-
var guardMeta = {
|
|
1966
|
-
state: state,
|
|
1967
|
-
guard: guard,
|
|
1968
|
-
_event: _event,
|
|
1969
|
-
evaluate: evaluateGuard
|
|
1970
|
-
};
|
|
1971
1999
|
var predicate = (_machine$options$guar = machine === null || machine === void 0 ? void 0 : (_machine$options = machine.options) === null || _machine$options === void 0 ? void 0 : (_machine$options$guar2 = _machine$options.guards) === null || _machine$options$guar2 === void 0 ? void 0 : _machine$options$guar2[guard.type]) !== null && _machine$options$guar !== void 0 ? _machine$options$guar : guard.predicate;
|
|
1972
2000
|
if (!predicate) {
|
|
1973
2001
|
throw new Error("Guard '".concat(guard.type, "' is not implemented.'."));
|
|
1974
2002
|
}
|
|
1975
|
-
return predicate(
|
|
2003
|
+
return predicate({
|
|
2004
|
+
context: context,
|
|
2005
|
+
event: _event.data,
|
|
2006
|
+
state: state,
|
|
2007
|
+
guard: guard,
|
|
2008
|
+
_event: _event,
|
|
2009
|
+
evaluate: evaluateGuard
|
|
2010
|
+
});
|
|
1976
2011
|
}
|
|
1977
2012
|
function toGuardDefinition(guardConfig, getPredicate) {
|
|
1978
2013
|
var _guardConfig$children;
|
|
@@ -3829,8 +3864,10 @@ function invoke$1(invokeDef) {
|
|
|
3829
3864
|
src: src,
|
|
3830
3865
|
parent: actorContext === null || actorContext === void 0 ? void 0 : actorContext.self,
|
|
3831
3866
|
systemId: invokeDef.systemId,
|
|
3832
|
-
input: typeof input === 'function' ? input(
|
|
3833
|
-
|
|
3867
|
+
input: typeof input === 'function' ? input({
|
|
3868
|
+
context: state.context,
|
|
3869
|
+
event: _event.data,
|
|
3870
|
+
self: actorContext === null || actorContext === void 0 ? void 0 : actorContext.self
|
|
3834
3871
|
}) : input
|
|
3835
3872
|
});
|
|
3836
3873
|
resolvedInvokeAction = {
|
|
@@ -3887,7 +3924,9 @@ function createSpawner(self, machine, context, _event, mutCapturedActions) {
|
|
|
3887
3924
|
var actorRef = interpret(referenced.src, {
|
|
3888
3925
|
id: resolvedName,
|
|
3889
3926
|
parent: self,
|
|
3890
|
-
input: typeof input === 'function' ? input(
|
|
3927
|
+
input: typeof input === 'function' ? input({
|
|
3928
|
+
context: context,
|
|
3929
|
+
event: _event.data,
|
|
3891
3930
|
self: self
|
|
3892
3931
|
}) : input
|
|
3893
3932
|
});
|
|
@@ -3945,7 +3984,9 @@ function assign$1(assignment) {
|
|
|
3945
3984
|
if (!state.context) {
|
|
3946
3985
|
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
3947
3986
|
}
|
|
3948
|
-
var
|
|
3987
|
+
var args = {
|
|
3988
|
+
context: state.context,
|
|
3989
|
+
event: _event.data,
|
|
3949
3990
|
state: state,
|
|
3950
3991
|
action: action,
|
|
3951
3992
|
_event: _event,
|
|
@@ -3955,12 +3996,12 @@ function assign$1(assignment) {
|
|
|
3955
3996
|
};
|
|
3956
3997
|
var partialUpdate = {};
|
|
3957
3998
|
if (isFunction(assignment)) {
|
|
3958
|
-
partialUpdate = assignment(
|
|
3999
|
+
partialUpdate = assignment(args);
|
|
3959
4000
|
} else {
|
|
3960
4001
|
for (var _i = 0, _Object$keys = Object.keys(assignment); _i < _Object$keys.length; _i++) {
|
|
3961
4002
|
var key = _Object$keys[_i];
|
|
3962
4003
|
var propAssignment = assignment[key];
|
|
3963
|
-
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(
|
|
4004
|
+
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(args) : propAssignment;
|
|
3964
4005
|
}
|
|
3965
4006
|
}
|
|
3966
4007
|
var updatedContext = Object.assign({}, state.context, partialUpdate);
|
|
@@ -4000,22 +4041,25 @@ function raise$1(eventOrExpr, options) {
|
|
|
4000
4041
|
event: eventOrExpr,
|
|
4001
4042
|
id: options && options.id !== undefined ? options.id : typeof eventOrExpr === 'function' ? eventOrExpr.name : eventOrExpr.type
|
|
4002
4043
|
};
|
|
4003
|
-
var
|
|
4044
|
+
var args = {
|
|
4045
|
+
context: state.context,
|
|
4046
|
+
event: _event.data,
|
|
4004
4047
|
_event: _event,
|
|
4005
4048
|
state: state,
|
|
4049
|
+
// TODO: fix
|
|
4006
4050
|
self: (_actorContext$self = actorContext === null || actorContext === void 0 ? void 0 : actorContext.self) !== null && _actorContext$self !== void 0 ? _actorContext$self : {},
|
|
4007
4051
|
system: actorContext === null || actorContext === void 0 ? void 0 : actorContext.system
|
|
4008
4052
|
};
|
|
4009
4053
|
var delaysMap = state.machine.options.delays;
|
|
4010
4054
|
|
|
4011
4055
|
// TODO: helper function for resolving Expr
|
|
4012
|
-
var resolvedEvent = toSCXMLEvent(typeof eventOrExpr === 'function' ? eventOrExpr(
|
|
4056
|
+
var resolvedEvent = toSCXMLEvent(typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr);
|
|
4013
4057
|
var resolvedDelay;
|
|
4014
4058
|
if (typeof params.delay === 'string') {
|
|
4015
4059
|
var configDelay = delaysMap && delaysMap[params.delay];
|
|
4016
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(
|
|
4060
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
|
|
4017
4061
|
} else {
|
|
4018
|
-
resolvedDelay = typeof params.delay === 'function' ? params.delay(
|
|
4062
|
+
resolvedDelay = typeof params.delay === 'function' ? params.delay(args) : params.delay;
|
|
4019
4063
|
}
|
|
4020
4064
|
var resolvedAction = {
|
|
4021
4065
|
type: raise,
|
|
@@ -4078,7 +4122,9 @@ function resolveActionObject(actionObject, actionFunctionMap) {
|
|
|
4078
4122
|
type: actionObject.type,
|
|
4079
4123
|
params: actionObject.params,
|
|
4080
4124
|
execute: function execute(actorCtx) {
|
|
4081
|
-
return dereferencedAction(
|
|
4125
|
+
return dereferencedAction({
|
|
4126
|
+
context: state.context,
|
|
4127
|
+
event: state.event,
|
|
4082
4128
|
action: a,
|
|
4083
4129
|
_event: state._event,
|
|
4084
4130
|
state: state,
|
|
@@ -4118,7 +4164,9 @@ function toActionObject(action) {
|
|
|
4118
4164
|
"function": action
|
|
4119
4165
|
},
|
|
4120
4166
|
execute: function execute(actorCtx) {
|
|
4121
|
-
return action(
|
|
4167
|
+
return action({
|
|
4168
|
+
context: state.context,
|
|
4169
|
+
event: _event.data,
|
|
4122
4170
|
action: actionObject,
|
|
4123
4171
|
_event: _event,
|
|
4124
4172
|
state: state,
|