xstate 4.30.1 → 4.30.2
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 +12 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +1 -1
- package/es/Actor.js +15 -6
- package/es/State.d.ts +3 -2
- package/es/State.js +0 -5
- package/es/index.d.ts +2 -2
- package/es/index.js +1 -0
- package/es/interpreter.d.ts +4 -3
- package/es/interpreter.js +29 -19
- package/es/types.d.ts +7 -4
- package/es/utils.d.ts +1 -2
- package/es/utils.js +4 -1
- package/lib/Actor.d.ts +1 -1
- package/lib/Actor.js +14 -5
- package/lib/State.d.ts +3 -2
- package/lib/State.js +0 -5
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -0
- package/lib/interpreter.d.ts +4 -3
- package/lib/interpreter.js +28 -18
- package/lib/types.d.ts +7 -4
- package/lib/utils.d.ts +1 -2
- package/lib/utils.js +4 -1
- package/package.json +1 -1
package/lib/State.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
71
71
|
* @param stateValue
|
|
72
72
|
* @param context
|
|
73
73
|
*/
|
|
74
|
-
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
|
|
74
|
+
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context: TC): State<TC, TE>;
|
|
75
75
|
/**
|
|
76
76
|
* Creates a new State instance.
|
|
77
77
|
* @param value The state value
|
|
@@ -98,7 +98,8 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
98
98
|
* Whether the current state value is a subset of the given parent state value.
|
|
99
99
|
* @param parentStateValue
|
|
100
100
|
*/
|
|
101
|
-
matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'matchesStates'> :
|
|
101
|
+
matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<TResolvedTypesMeta, 'matchesStates'> : never>(parentStateValue: TSV): boolean;
|
|
102
|
+
matches<TSV extends TResolvedTypesMeta extends TypegenDisabled ? TTypestate['value'] : never>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
|
|
102
103
|
value: TSV;
|
|
103
104
|
context: any;
|
|
104
105
|
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
|
package/lib/State.js
CHANGED
|
@@ -230,11 +230,6 @@ function () {
|
|
|
230
230
|
tags: Array.from(tags)
|
|
231
231
|
});
|
|
232
232
|
};
|
|
233
|
-
/**
|
|
234
|
-
* Whether the current state value is a subset of the given parent state value.
|
|
235
|
-
* @param parentStateValue
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
233
|
|
|
239
234
|
State.prototype.matches = function (parentStateValue) {
|
|
240
235
|
return utils.matchesState(parentStateValue, this.value);
|
package/lib/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { mapState } from './mapState';
|
|
|
3
3
|
import { StateNode } from './StateNode';
|
|
4
4
|
import { State } from './State';
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
|
-
import { Actor } from './Actor';
|
|
6
|
+
import { Actor, toActorRef } from './Actor';
|
|
7
7
|
import * as actions from './actions';
|
|
8
8
|
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
|
|
9
9
|
import { matchState } from './match';
|
|
10
10
|
import { createSchema, t } from './schema';
|
|
11
11
|
declare const assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>, send: typeof actions.send, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke;
|
|
12
|
-
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
|
|
12
|
+
export { Actor, toActorRef, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
|
|
13
13
|
export * from './types';
|
|
14
14
|
export * from './typegenTypes';
|
|
15
15
|
declare global {
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var mapState = require('./mapState.js');
|
|
|
7
7
|
var types = require('./types.js');
|
|
8
8
|
var actions = require('./actions.js');
|
|
9
9
|
var State = require('./State.js');
|
|
10
|
+
var Actor = require('./Actor.js');
|
|
10
11
|
var StateNode = require('./StateNode.js');
|
|
11
12
|
var Machine = require('./Machine.js');
|
|
12
13
|
var interpreter = require('./interpreter.js');
|
|
@@ -36,6 +37,7 @@ Object.defineProperty(exports, 'SpecialTargets', {
|
|
|
36
37
|
});
|
|
37
38
|
exports.actions = actions;
|
|
38
39
|
exports.State = State.State;
|
|
40
|
+
exports.toActorRef = Actor.toActorRef;
|
|
39
41
|
exports.StateNode = StateNode.StateNode;
|
|
40
42
|
exports.Machine = Machine.Machine;
|
|
41
43
|
exports.createMachine = Machine.createMachine;
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray,
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription, StateConfig, InteropSubscribable } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
|
+
import { symbolObservable } from './utils';
|
|
3
4
|
import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
|
|
4
5
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
5
6
|
value: any;
|
|
@@ -92,8 +93,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
92
93
|
execute(state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
93
94
|
private update;
|
|
94
95
|
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
|
|
95
|
-
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
96
96
|
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>): Subscription;
|
|
97
|
+
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
97
98
|
/**
|
|
98
99
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
99
100
|
* @param listener The event listener
|
|
@@ -188,7 +189,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
188
189
|
toJSON(): {
|
|
189
190
|
id: string;
|
|
190
191
|
};
|
|
191
|
-
[
|
|
192
|
+
[symbolObservable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
192
193
|
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
193
194
|
}
|
|
194
195
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
package/lib/interpreter.js
CHANGED
|
@@ -1000,6 +1000,8 @@ function () {
|
|
|
1000
1000
|
};
|
|
1001
1001
|
|
|
1002
1002
|
Interpreter.prototype.spawnPromise = function (promise, id) {
|
|
1003
|
+
var _a;
|
|
1004
|
+
|
|
1003
1005
|
var _this = this;
|
|
1004
1006
|
|
|
1005
1007
|
var canceled = false;
|
|
@@ -1042,8 +1044,7 @@ function () {
|
|
|
1042
1044
|
}
|
|
1043
1045
|
}
|
|
1044
1046
|
});
|
|
1045
|
-
|
|
1046
|
-
var actor = _tslib.__assign({
|
|
1047
|
+
var actor = (_a = {
|
|
1047
1048
|
id: id,
|
|
1048
1049
|
send: function () {
|
|
1049
1050
|
return void 0;
|
|
@@ -1087,13 +1088,16 @@ function () {
|
|
|
1087
1088
|
getSnapshot: function () {
|
|
1088
1089
|
return resolvedData;
|
|
1089
1090
|
}
|
|
1090
|
-
}, utils.
|
|
1091
|
-
|
|
1091
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1092
|
+
return this;
|
|
1093
|
+
}, _a);
|
|
1092
1094
|
this.children.set(id, actor);
|
|
1093
1095
|
return actor;
|
|
1094
1096
|
};
|
|
1095
1097
|
|
|
1096
1098
|
Interpreter.prototype.spawnCallback = function (callback, id) {
|
|
1099
|
+
var _a;
|
|
1100
|
+
|
|
1097
1101
|
var _this = this;
|
|
1098
1102
|
|
|
1099
1103
|
var canceled = false;
|
|
@@ -1132,7 +1136,7 @@ function () {
|
|
|
1132
1136
|
return this.spawnPromise(callbackStop, id);
|
|
1133
1137
|
}
|
|
1134
1138
|
|
|
1135
|
-
var actor =
|
|
1139
|
+
var actor = (_a = {
|
|
1136
1140
|
id: id,
|
|
1137
1141
|
send: function (event) {
|
|
1138
1142
|
return receivers.forEach(function (receiver) {
|
|
@@ -1140,10 +1144,11 @@ function () {
|
|
|
1140
1144
|
});
|
|
1141
1145
|
},
|
|
1142
1146
|
subscribe: function (next) {
|
|
1143
|
-
|
|
1147
|
+
var observer = utils.toObserver(next);
|
|
1148
|
+
listeners.add(observer.next);
|
|
1144
1149
|
return {
|
|
1145
1150
|
unsubscribe: function () {
|
|
1146
|
-
listeners.delete(next);
|
|
1151
|
+
listeners.delete(observer.next);
|
|
1147
1152
|
}
|
|
1148
1153
|
};
|
|
1149
1154
|
},
|
|
@@ -1162,13 +1167,16 @@ function () {
|
|
|
1162
1167
|
getSnapshot: function () {
|
|
1163
1168
|
return emitted;
|
|
1164
1169
|
}
|
|
1165
|
-
}, utils.
|
|
1166
|
-
|
|
1170
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1171
|
+
return this;
|
|
1172
|
+
}, _a);
|
|
1167
1173
|
this.children.set(id, actor);
|
|
1168
1174
|
return actor;
|
|
1169
1175
|
};
|
|
1170
1176
|
|
|
1171
1177
|
Interpreter.prototype.spawnObservable = function (source, id) {
|
|
1178
|
+
var _a;
|
|
1179
|
+
|
|
1172
1180
|
var _this = this;
|
|
1173
1181
|
|
|
1174
1182
|
var emitted;
|
|
@@ -1191,8 +1199,7 @@ function () {
|
|
|
1191
1199
|
origin: id
|
|
1192
1200
|
}));
|
|
1193
1201
|
});
|
|
1194
|
-
|
|
1195
|
-
var actor = _tslib.__assign({
|
|
1202
|
+
var actor = (_a = {
|
|
1196
1203
|
id: id,
|
|
1197
1204
|
send: function () {
|
|
1198
1205
|
return void 0;
|
|
@@ -1211,8 +1218,9 @@ function () {
|
|
|
1211
1218
|
id: id
|
|
1212
1219
|
};
|
|
1213
1220
|
}
|
|
1214
|
-
}, utils.
|
|
1215
|
-
|
|
1221
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1222
|
+
return this;
|
|
1223
|
+
}, _a);
|
|
1216
1224
|
this.children.set(id, actor);
|
|
1217
1225
|
return actor;
|
|
1218
1226
|
};
|
|
@@ -1240,7 +1248,9 @@ function () {
|
|
|
1240
1248
|
};
|
|
1241
1249
|
|
|
1242
1250
|
Interpreter.prototype.spawnEffect = function (id, dispose) {
|
|
1243
|
-
|
|
1251
|
+
var _a;
|
|
1252
|
+
|
|
1253
|
+
this.children.set(id, (_a = {
|
|
1244
1254
|
id: id,
|
|
1245
1255
|
send: function () {
|
|
1246
1256
|
return void 0;
|
|
@@ -1261,7 +1271,9 @@ function () {
|
|
|
1261
1271
|
id: id
|
|
1262
1272
|
};
|
|
1263
1273
|
}
|
|
1264
|
-
}, utils.
|
|
1274
|
+
}, _a[utils.symbolObservable] = function () {
|
|
1275
|
+
return this;
|
|
1276
|
+
}, _a));
|
|
1265
1277
|
};
|
|
1266
1278
|
|
|
1267
1279
|
Interpreter.prototype.attachDev = function () {
|
|
@@ -1302,9 +1314,7 @@ function () {
|
|
|
1302
1314
|
|
|
1303
1315
|
Interpreter.prototype[utils.symbolObservable] = function () {
|
|
1304
1316
|
return this;
|
|
1305
|
-
};
|
|
1306
|
-
// it has to be here to be included in the generated .d.ts
|
|
1307
|
-
|
|
1317
|
+
};
|
|
1308
1318
|
|
|
1309
1319
|
Interpreter.prototype.getSnapshot = function () {
|
|
1310
1320
|
if (this.status === exports.InterpreterStatus.NotStarted) {
|
package/lib/types.d.ts
CHANGED
|
@@ -570,7 +570,7 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
|
|
|
570
570
|
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
|
|
571
571
|
value: any;
|
|
572
572
|
context: TContext;
|
|
573
|
-
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = TypegenDisabled
|
|
573
|
+
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, TEvent, TAction, TServiceMap>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta> {
|
|
574
574
|
id: string;
|
|
575
575
|
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
|
|
576
576
|
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
|
|
@@ -976,11 +976,14 @@ export interface Subscription {
|
|
|
976
976
|
unsubscribe(): void;
|
|
977
977
|
}
|
|
978
978
|
export interface InteropObservable<T> {
|
|
979
|
-
[Symbol.observable]: () =>
|
|
979
|
+
[Symbol.observable]: () => InteropSubscribable<T>;
|
|
980
980
|
}
|
|
981
|
-
export interface
|
|
982
|
-
subscribe(
|
|
981
|
+
export interface InteropSubscribable<T> {
|
|
982
|
+
subscribe(observer: Observer<T>): Subscription;
|
|
983
|
+
}
|
|
984
|
+
export interface Subscribable<T> extends InteropSubscribable<T> {
|
|
983
985
|
subscribe(observer: Observer<T>): Subscription;
|
|
986
|
+
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
984
987
|
}
|
|
985
988
|
export declare type Spawnable = AnyStateMachine | PromiseLike<any> | InvokeCallback | InteropObservable<any> | Subscribable<any> | Behavior<any>;
|
|
986
989
|
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
|
package/lib/utils.d.ts
CHANGED
|
@@ -53,9 +53,8 @@ export declare function isFunction(value: any): value is Function;
|
|
|
53
53
|
export declare function isString(value: any): value is string;
|
|
54
54
|
export declare function toGuard<TContext, TEvent extends EventObject>(condition?: Condition<TContext, TEvent>, guardMap?: Record<string, ConditionPredicate<TContext, TEvent>>): Guard<TContext, TEvent> | undefined;
|
|
55
55
|
export declare function isObservable<T>(value: any): value is Subscribable<T>;
|
|
56
|
-
export declare const symbolObservable:
|
|
56
|
+
export declare const symbolObservable: typeof Symbol.observable;
|
|
57
57
|
export declare const interopSymbols: {
|
|
58
|
-
[x: string]: () => any;
|
|
59
58
|
[Symbol.observable]: () => any;
|
|
60
59
|
};
|
|
61
60
|
export declare function isMachine(value: any): value is AnyStateMachine;
|
package/lib/utils.js
CHANGED
|
@@ -464,9 +464,12 @@ function isObservable(value) {
|
|
|
464
464
|
}
|
|
465
465
|
var symbolObservable = /*#__PURE__*/function () {
|
|
466
466
|
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
467
|
-
}();
|
|
467
|
+
}(); // TODO: to be removed in v5, left it out just to minimize the scope of the change and maintain compatibility with older versions of integration paackages
|
|
468
|
+
|
|
468
469
|
var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
|
|
469
470
|
return this;
|
|
471
|
+
}, _a[Symbol.observable] = function () {
|
|
472
|
+
return this;
|
|
470
473
|
}, _a);
|
|
471
474
|
function isMachine(value) {
|
|
472
475
|
try {
|