xstate 4.27.0 → 4.28.0
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/CHANGELOG.md +46 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +5 -5
- package/es/StateNode.js +12 -11
- package/es/actions.js +15 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/interpreter.d.ts +0 -5
- package/es/interpreter.js +14 -9
- package/es/types.d.ts +5 -2
- package/es/utils.d.ts +7 -1
- package/es/utils.js +8 -1
- package/lib/Actor.js +4 -4
- package/lib/StateNode.js +11 -10
- package/lib/actions.js +15 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/interpreter.d.ts +0 -5
- package/lib/interpreter.js +13 -8
- package/lib/types.d.ts +5 -2
- package/lib/utils.d.ts +7 -1
- package/lib/utils.js +9 -0
- package/package.json +1 -1
package/lib/actions.js
CHANGED
|
@@ -156,6 +156,20 @@ function sendParent(event, options) {
|
|
|
156
156
|
to: types.SpecialTargets.Parent
|
|
157
157
|
}));
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Sends an event to an actor.
|
|
161
|
+
*
|
|
162
|
+
* @param actor The `ActorRef` to send the event to.
|
|
163
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
164
|
+
* @param options Send action options
|
|
165
|
+
* @returns An XState send action object
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
function sendTo(actor, event, options) {
|
|
169
|
+
return send(event, _tslib.__assign(_tslib.__assign({}, options), {
|
|
170
|
+
to: actor
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
159
173
|
/**
|
|
160
174
|
* Sends an update event to this machine's parent.
|
|
161
175
|
*/
|
|
@@ -524,6 +538,7 @@ exports.resolveStop = resolveStop;
|
|
|
524
538
|
exports.respond = respond;
|
|
525
539
|
exports.send = send;
|
|
526
540
|
exports.sendParent = sendParent;
|
|
541
|
+
exports.sendTo = sendTo;
|
|
527
542
|
exports.sendUpdate = sendUpdate;
|
|
528
543
|
exports.start = start;
|
|
529
544
|
exports.stop = stop;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { StateNode } from './StateNode';
|
|
|
4
4
|
import { State } from './State';
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
6
|
import { Actor } from './Actor';
|
|
7
|
-
import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
|
|
7
|
+
import { raise, send, sendParent, sendTo, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
|
|
8
8
|
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
|
|
9
9
|
import { matchState } from './match';
|
|
10
10
|
import { createSchema } from './schema';
|
|
@@ -12,6 +12,7 @@ declare const actions: {
|
|
|
12
12
|
raise: typeof raise;
|
|
13
13
|
send: typeof send;
|
|
14
14
|
sendParent: typeof sendParent;
|
|
15
|
+
sendTo: typeof sendTo;
|
|
15
16
|
sendUpdate: typeof sendUpdate;
|
|
16
17
|
log: typeof log;
|
|
17
18
|
cancel: (sendId: string | number) => import("./types").CancelAction;
|
package/lib/index.js
CHANGED
package/lib/interpreter.d.ts
CHANGED
|
@@ -21,11 +21,6 @@ export declare enum InterpreterStatus {
|
|
|
21
21
|
Running = 1,
|
|
22
22
|
Stopped = 2
|
|
23
23
|
}
|
|
24
|
-
declare global {
|
|
25
|
-
interface SymbolConstructor {
|
|
26
|
-
readonly observable: symbol;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
24
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
30
25
|
value: any;
|
|
31
26
|
context: TContext;
|
package/lib/interpreter.js
CHANGED
|
@@ -1039,7 +1039,8 @@ function () {
|
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
1041
|
});
|
|
1042
|
-
|
|
1042
|
+
|
|
1043
|
+
var actor = _tslib.__assign({
|
|
1043
1044
|
id: id,
|
|
1044
1045
|
send: function () {
|
|
1045
1046
|
return void 0;
|
|
@@ -1083,7 +1084,8 @@ function () {
|
|
|
1083
1084
|
getSnapshot: function () {
|
|
1084
1085
|
return resolvedData;
|
|
1085
1086
|
}
|
|
1086
|
-
};
|
|
1087
|
+
}, utils.interopSymbols);
|
|
1088
|
+
|
|
1087
1089
|
this.children.set(id, actor);
|
|
1088
1090
|
return actor;
|
|
1089
1091
|
};
|
|
@@ -1127,7 +1129,7 @@ function () {
|
|
|
1127
1129
|
return this.spawnPromise(callbackStop, id);
|
|
1128
1130
|
}
|
|
1129
1131
|
|
|
1130
|
-
var actor = {
|
|
1132
|
+
var actor = _tslib.__assign({
|
|
1131
1133
|
id: id,
|
|
1132
1134
|
send: function (event) {
|
|
1133
1135
|
return receivers.forEach(function (receiver) {
|
|
@@ -1157,7 +1159,8 @@ function () {
|
|
|
1157
1159
|
getSnapshot: function () {
|
|
1158
1160
|
return emitted;
|
|
1159
1161
|
}
|
|
1160
|
-
};
|
|
1162
|
+
}, utils.interopSymbols);
|
|
1163
|
+
|
|
1161
1164
|
this.children.set(id, actor);
|
|
1162
1165
|
return actor;
|
|
1163
1166
|
};
|
|
@@ -1185,7 +1188,8 @@ function () {
|
|
|
1185
1188
|
origin: id
|
|
1186
1189
|
}));
|
|
1187
1190
|
});
|
|
1188
|
-
|
|
1191
|
+
|
|
1192
|
+
var actor = _tslib.__assign({
|
|
1189
1193
|
id: id,
|
|
1190
1194
|
send: function () {
|
|
1191
1195
|
return void 0;
|
|
@@ -1204,7 +1208,8 @@ function () {
|
|
|
1204
1208
|
id: id
|
|
1205
1209
|
};
|
|
1206
1210
|
}
|
|
1207
|
-
};
|
|
1211
|
+
}, utils.interopSymbols);
|
|
1212
|
+
|
|
1208
1213
|
this.children.set(id, actor);
|
|
1209
1214
|
return actor;
|
|
1210
1215
|
};
|
|
@@ -1232,7 +1237,7 @@ function () {
|
|
|
1232
1237
|
};
|
|
1233
1238
|
|
|
1234
1239
|
Interpreter.prototype.spawnEffect = function (id, dispose) {
|
|
1235
|
-
this.children.set(id, {
|
|
1240
|
+
this.children.set(id, _tslib.__assign({
|
|
1236
1241
|
id: id,
|
|
1237
1242
|
send: function () {
|
|
1238
1243
|
return void 0;
|
|
@@ -1253,7 +1258,7 @@ function () {
|
|
|
1253
1258
|
id: id
|
|
1254
1259
|
};
|
|
1255
1260
|
}
|
|
1256
|
-
});
|
|
1261
|
+
}, utils.interopSymbols));
|
|
1257
1262
|
};
|
|
1258
1263
|
|
|
1259
1264
|
Interpreter.prototype.attachDev = function () {
|
package/lib/types.d.ts
CHANGED
|
@@ -916,18 +916,21 @@ export interface Observer<T> {
|
|
|
916
916
|
export interface Subscription {
|
|
917
917
|
unsubscribe(): void;
|
|
918
918
|
}
|
|
919
|
+
export interface InteropObservable<T> {
|
|
920
|
+
[Symbol.observable]: () => Subscribable<T>;
|
|
921
|
+
}
|
|
919
922
|
export interface Subscribable<T> {
|
|
920
923
|
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
921
924
|
subscribe(observer: Observer<T>): Subscription;
|
|
922
925
|
}
|
|
923
|
-
export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
|
|
926
|
+
export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | InteropObservable<any> | Subscribable<any> | Behavior<any>;
|
|
924
927
|
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
|
|
925
928
|
type: TEventType;
|
|
926
929
|
} ? TEvent : never;
|
|
927
930
|
export interface BaseActorRef<TEvent extends EventObject> {
|
|
928
931
|
send: (event: TEvent) => void;
|
|
929
932
|
}
|
|
930
|
-
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
|
|
933
|
+
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted>, InteropObservable<TEmitted> {
|
|
931
934
|
send: Sender<TEvent>;
|
|
932
935
|
id: string;
|
|
933
936
|
getSnapshot: () => TEmitted | undefined;
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior } from './types';
|
|
2
3
|
import { StateNode } from './StateNode';
|
|
3
4
|
import { State } from './State';
|
|
@@ -52,7 +53,11 @@ export declare function isFunction(value: any): value is Function;
|
|
|
52
53
|
export declare function isString(value: any): value is string;
|
|
53
54
|
export declare function toGuard<TContext, TEvent extends EventObject>(condition?: Condition<TContext, TEvent>, guardMap?: Record<string, ConditionPredicate<TContext, TEvent>>): Guard<TContext, TEvent> | undefined;
|
|
54
55
|
export declare function isObservable<T>(value: any): value is Subscribable<T>;
|
|
55
|
-
export declare const symbolObservable:
|
|
56
|
+
export declare const symbolObservable: string | typeof Symbol.observable;
|
|
57
|
+
export declare const interopSymbols: {
|
|
58
|
+
[x: string]: () => any;
|
|
59
|
+
[Symbol.observable]: () => any;
|
|
60
|
+
};
|
|
56
61
|
export declare function isMachine(value: any): value is StateMachine<any, any, any>;
|
|
57
62
|
export declare function isActor(value: any): value is Actor;
|
|
58
63
|
export declare const uniqueId: () => string;
|
|
@@ -66,4 +71,5 @@ export declare function reportUnhandledExceptionOnInvocation(originalError: any,
|
|
|
66
71
|
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
|
|
67
72
|
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
|
|
68
73
|
export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
74
|
+
export declare function createInvokeId(stateNodeId: string, index: number): string;
|
|
69
75
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ var _tslib = require('./_virtual/_tslib.js');
|
|
|
6
6
|
var constants = require('./constants.js');
|
|
7
7
|
var environment = require('./environment.js');
|
|
8
8
|
|
|
9
|
+
var _a;
|
|
9
10
|
function keys(value) {
|
|
10
11
|
return Object.keys(value);
|
|
11
12
|
}
|
|
@@ -464,6 +465,9 @@ function isObservable(value) {
|
|
|
464
465
|
var symbolObservable = /*#__PURE__*/function () {
|
|
465
466
|
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
466
467
|
}();
|
|
468
|
+
var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
|
|
469
|
+
return this;
|
|
470
|
+
}, _a);
|
|
467
471
|
function isMachine(value) {
|
|
468
472
|
try {
|
|
469
473
|
return '__xstatenode' in value;
|
|
@@ -584,10 +588,15 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
|
584
588
|
complete: completionHandler || noop
|
|
585
589
|
};
|
|
586
590
|
}
|
|
591
|
+
function createInvokeId(stateNodeId, index) {
|
|
592
|
+
return "".concat(stateNodeId, ":invocation[").concat(index, "]");
|
|
593
|
+
}
|
|
587
594
|
|
|
595
|
+
exports.createInvokeId = createInvokeId;
|
|
588
596
|
exports.evaluateGuard = evaluateGuard;
|
|
589
597
|
exports.flatten = flatten;
|
|
590
598
|
exports.getEventType = getEventType;
|
|
599
|
+
exports.interopSymbols = interopSymbols;
|
|
591
600
|
exports.isActor = isActor;
|
|
592
601
|
exports.isArray = isArray;
|
|
593
602
|
exports.isBehavior = isBehavior;
|