xstate 4.22.0 → 4.23.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 +58 -4
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +1 -6
- package/es/Machine.d.ts +3 -3
- package/es/Machine.js +1 -2
- package/es/State.js +1 -3
- package/es/StateNode.js +3 -2
- package/es/_virtual/_tslib.js +59 -73
- package/es/actionTypes.js +3 -2
- package/es/actions.d.ts +1 -1
- package/es/actions.js +51 -37
- package/es/behaviors.js +4 -2
- package/es/constants.js +2 -1
- package/es/devTools.js +1 -1
- package/es/environment.js +2 -1
- package/es/index.js +3 -1
- package/es/interpreter.d.ts +8 -2
- package/es/interpreter.js +8 -6
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -37
- package/es/model.types.d.ts +37 -0
- package/es/registry.js +2 -1
- package/es/scheduler.js +2 -1
- package/es/schema.js +1 -1
- package/es/serviceScope.js +1 -3
- package/es/stateUtils.js +1 -9
- package/es/types.d.ts +12 -2
- package/es/types.js +1 -1
- package/es/utils.js +1 -41
- package/lib/Actor.d.ts +25 -25
- package/lib/Actor.js +85 -66
- package/lib/Machine.d.ts +17 -17
- package/lib/Machine.js +14 -8
- package/lib/SimulatedClock.d.ts +16 -16
- package/lib/State.d.ts +108 -108
- package/lib/State.js +246 -236
- package/lib/StateNode.d.ts +279 -279
- package/lib/StateNode.js +1535 -1357
- package/lib/_virtual/_tslib.js +81 -0
- package/lib/actionTypes.d.ts +19 -19
- package/lib/actionTypes.js +43 -23
- package/lib/actions.d.ts +138 -138
- package/lib/actions.js +465 -387
- package/lib/behaviors.d.ts +36 -36
- package/lib/behaviors.js +65 -106
- package/lib/constants.d.ts +5 -5
- package/lib/constants.js +13 -7
- package/lib/devTools.d.ts +15 -15
- package/lib/devTools.js +37 -26
- package/lib/each.d.ts +3 -3
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +7 -4
- package/lib/index.d.ts +30 -30
- package/lib/index.js +67 -57
- package/lib/interpreter.d.ts +205 -199
- package/lib/interpreter.js +1306 -1060
- package/lib/invoke.d.ts +10 -10
- package/lib/invokeUtils.d.ts +6 -6
- package/lib/invokeUtils.js +40 -37
- package/lib/json.d.ts +30 -30
- package/lib/mapState.d.ts +3 -3
- package/lib/mapState.js +31 -32
- package/lib/match.d.ts +8 -8
- package/lib/match.js +33 -47
- package/lib/model.d.ts +4 -39
- package/lib/model.types.d.ts +37 -0
- package/lib/model.types.js +2 -0
- package/lib/patterns.d.ts +13 -13
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +21 -18
- package/lib/scheduler.d.ts +16 -16
- package/lib/scheduler.js +79 -70
- package/lib/schema.d.ts +1 -1
- package/lib/schema.js +6 -4
- package/lib/scxml.d.ts +5 -5
- package/lib/serviceScope.d.ts +3 -3
- package/lib/serviceScope.js +16 -12
- package/lib/stateUtils.d.ts +14 -14
- package/lib/stateUtils.js +231 -199
- package/lib/types.d.ts +928 -918
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -68
- package/lib/utils.js +528 -534
- package/package.json +5 -5
package/es/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StateNode } from './StateNode';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Interpreter, Clock } from './interpreter';
|
|
4
|
+
import { Model } from './model.types';
|
|
4
5
|
export declare type EventType = string;
|
|
5
6
|
export declare type ActionType = string;
|
|
6
7
|
export declare type MetaObject = Record<string, any>;
|
|
@@ -384,6 +385,13 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
|
|
|
384
385
|
* The tags for this state node, which are accumulated into the `state.tags` property.
|
|
385
386
|
*/
|
|
386
387
|
tags?: SingleOrArray<string>;
|
|
388
|
+
/**
|
|
389
|
+
* Whether actions should be called in order.
|
|
390
|
+
* When `false` (default), `assign(...)` actions are prioritized before other actions.
|
|
391
|
+
*
|
|
392
|
+
* @default false
|
|
393
|
+
*/
|
|
394
|
+
preserveActionOrder?: boolean;
|
|
387
395
|
}
|
|
388
396
|
export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
|
|
389
397
|
id: string;
|
|
@@ -875,8 +883,8 @@ export interface Subscription {
|
|
|
875
883
|
unsubscribe(): void;
|
|
876
884
|
}
|
|
877
885
|
export interface Subscribable<T> {
|
|
878
|
-
subscribe(observer: Observer<T>): Subscription;
|
|
879
886
|
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
887
|
+
subscribe(observer: Observer<T>): Subscription;
|
|
880
888
|
}
|
|
881
889
|
export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
|
|
882
890
|
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
|
|
@@ -901,7 +909,7 @@ export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise
|
|
|
901
909
|
* @deprecated Use `.getSnapshot()` instead.
|
|
902
910
|
*/
|
|
903
911
|
state: State<TContext, TEvent, any, TTypestate>;
|
|
904
|
-
} : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer
|
|
912
|
+
} : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
|
|
905
913
|
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
|
|
906
914
|
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
|
|
907
915
|
export interface ActorContext<TEvent extends EventObject, TEmitted> {
|
|
@@ -915,5 +923,7 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
|
|
|
915
923
|
initialState: TEmitted;
|
|
916
924
|
start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
|
|
917
925
|
}
|
|
926
|
+
export declare type EventFrom<T> = T extends StateMachine<any, any, infer TEvent, any> ? TEvent : T extends Model<any, infer TEvent, any> ? TEvent : T extends State<any, infer TEvent, any, any> ? TEvent : T extends Interpreter<any, any, infer TEvent, any> ? TEvent : never;
|
|
927
|
+
export declare type ContextFrom<T> = T extends StateMachine<infer TContext, any, any, any> ? TContext : T extends Model<infer TContext, any, any> ? TContext : T extends State<infer TContext, any, any, any> ? TContext : T extends Interpreter<infer TContext, any, any, any> ? TContext : never;
|
|
918
928
|
export {};
|
|
919
929
|
//# sourceMappingURL=types.d.ts.map
|
package/es/types.js
CHANGED
package/es/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ import { IS_PRODUCTION } from './environment.js';
|
|
|
5
5
|
function keys(value) {
|
|
6
6
|
return Object.keys(value);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
8
|
function matchesState(parentStateId, childStateId, delimiter) {
|
|
10
9
|
if (delimiter === void 0) {
|
|
11
10
|
delimiter = STATE_DELIMITER;
|
|
@@ -35,7 +34,6 @@ function matchesState(parentStateId, childStateId, delimiter) {
|
|
|
35
34
|
return matchesState(parentStateValue[key], childStateValue[key]);
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
function getEventType(event) {
|
|
40
38
|
try {
|
|
41
39
|
return isString(event) || typeof event === 'number' ? "" + event : event.type;
|
|
@@ -43,7 +41,6 @@ function getEventType(event) {
|
|
|
43
41
|
throw new Error('Events must be strings or objects with a string event.type property.');
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
|
-
|
|
47
44
|
function toStatePath(stateId, delimiter) {
|
|
48
45
|
try {
|
|
49
46
|
if (isArray(stateId)) {
|
|
@@ -55,11 +52,9 @@ function toStatePath(stateId, delimiter) {
|
|
|
55
52
|
throw new Error("'" + stateId + "' is not a valid state path.");
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
function isStateLike(state) {
|
|
60
56
|
return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state && '_event' in state;
|
|
61
57
|
}
|
|
62
|
-
|
|
63
58
|
function toStateValue(stateValue, delimiter) {
|
|
64
59
|
if (isStateLike(stateValue)) {
|
|
65
60
|
return stateValue.value;
|
|
@@ -76,7 +71,6 @@ function toStateValue(stateValue, delimiter) {
|
|
|
76
71
|
var statePath = toStatePath(stateValue, delimiter);
|
|
77
72
|
return pathToStateValue(statePath);
|
|
78
73
|
}
|
|
79
|
-
|
|
80
74
|
function pathToStateValue(statePath) {
|
|
81
75
|
if (statePath.length === 1) {
|
|
82
76
|
return statePath[0];
|
|
@@ -96,7 +90,6 @@ function pathToStateValue(statePath) {
|
|
|
96
90
|
|
|
97
91
|
return value;
|
|
98
92
|
}
|
|
99
|
-
|
|
100
93
|
function mapValues(collection, iteratee) {
|
|
101
94
|
var result = {};
|
|
102
95
|
var collectionKeys = keys(collection);
|
|
@@ -108,7 +101,6 @@ function mapValues(collection, iteratee) {
|
|
|
108
101
|
|
|
109
102
|
return result;
|
|
110
103
|
}
|
|
111
|
-
|
|
112
104
|
function mapFilterValues(collection, iteratee, predicate) {
|
|
113
105
|
var e_1, _a;
|
|
114
106
|
|
|
@@ -144,7 +136,6 @@ function mapFilterValues(collection, iteratee, predicate) {
|
|
|
144
136
|
* @param props The deep path to the prop of the desired value
|
|
145
137
|
*/
|
|
146
138
|
|
|
147
|
-
|
|
148
139
|
var path = function (props) {
|
|
149
140
|
return function (object) {
|
|
150
141
|
var e_2, _a;
|
|
@@ -176,7 +167,6 @@ var path = function (props) {
|
|
|
176
167
|
* @param props The deep path to the prop of the desired value
|
|
177
168
|
*/
|
|
178
169
|
|
|
179
|
-
|
|
180
170
|
function nestedPath(props, accessorProp) {
|
|
181
171
|
return function (object) {
|
|
182
172
|
var e_3, _a;
|
|
@@ -203,7 +193,6 @@ function nestedPath(props, accessorProp) {
|
|
|
203
193
|
return result;
|
|
204
194
|
};
|
|
205
195
|
}
|
|
206
|
-
|
|
207
196
|
function toStatePaths(stateValue) {
|
|
208
197
|
if (!stateValue) {
|
|
209
198
|
return [[]];
|
|
@@ -226,13 +215,11 @@ function toStatePaths(stateValue) {
|
|
|
226
215
|
}));
|
|
227
216
|
return result;
|
|
228
217
|
}
|
|
229
|
-
|
|
230
218
|
function flatten(array) {
|
|
231
219
|
var _a;
|
|
232
220
|
|
|
233
221
|
return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
|
|
234
222
|
}
|
|
235
|
-
|
|
236
223
|
function toArrayStrict(value) {
|
|
237
224
|
if (isArray(value)) {
|
|
238
225
|
return value;
|
|
@@ -240,7 +227,6 @@ function toArrayStrict(value) {
|
|
|
240
227
|
|
|
241
228
|
return [value];
|
|
242
229
|
}
|
|
243
|
-
|
|
244
230
|
function toArray(value) {
|
|
245
231
|
if (value === undefined) {
|
|
246
232
|
return [];
|
|
@@ -248,7 +234,6 @@ function toArray(value) {
|
|
|
248
234
|
|
|
249
235
|
return toArrayStrict(value);
|
|
250
236
|
}
|
|
251
|
-
|
|
252
237
|
function mapContext(mapper, context, _event) {
|
|
253
238
|
var e_5, _a;
|
|
254
239
|
|
|
@@ -283,11 +268,9 @@ function mapContext(mapper, context, _event) {
|
|
|
283
268
|
|
|
284
269
|
return result;
|
|
285
270
|
}
|
|
286
|
-
|
|
287
271
|
function isBuiltInEvent(eventType) {
|
|
288
272
|
return /^(done|error)\./.test(eventType);
|
|
289
273
|
}
|
|
290
|
-
|
|
291
274
|
function isPromiseLike(value) {
|
|
292
275
|
if (value instanceof Promise) {
|
|
293
276
|
return true;
|
|
@@ -300,11 +283,9 @@ function isPromiseLike(value) {
|
|
|
300
283
|
|
|
301
284
|
return false;
|
|
302
285
|
}
|
|
303
|
-
|
|
304
286
|
function isBehavior(value) {
|
|
305
287
|
return value !== null && typeof value === 'object' && 'transition' in value && typeof value.transition === 'function';
|
|
306
288
|
}
|
|
307
|
-
|
|
308
289
|
function partition(items, predicate) {
|
|
309
290
|
var e_6, _a;
|
|
310
291
|
|
|
@@ -336,7 +317,6 @@ function partition(items, predicate) {
|
|
|
336
317
|
|
|
337
318
|
return [truthy, falsy];
|
|
338
319
|
}
|
|
339
|
-
|
|
340
320
|
function updateHistoryStates(hist, stateValue) {
|
|
341
321
|
return mapValues(hist.states, function (subHist, key) {
|
|
342
322
|
if (!subHist) {
|
|
@@ -355,14 +335,12 @@ function updateHistoryStates(hist, stateValue) {
|
|
|
355
335
|
};
|
|
356
336
|
});
|
|
357
337
|
}
|
|
358
|
-
|
|
359
338
|
function updateHistoryValue(hist, stateValue) {
|
|
360
339
|
return {
|
|
361
340
|
current: stateValue,
|
|
362
341
|
states: updateHistoryStates(hist, stateValue)
|
|
363
342
|
};
|
|
364
343
|
}
|
|
365
|
-
|
|
366
344
|
function updateContext(context, _event, assignActions, state) {
|
|
367
345
|
if (!IS_PRODUCTION) {
|
|
368
346
|
warn(!!context, 'Attempting to update undefined context');
|
|
@@ -406,7 +384,6 @@ function updateContext(context, _event, assignActions, state) {
|
|
|
406
384
|
return updatedContext;
|
|
407
385
|
} // tslint:disable-next-line:no-empty
|
|
408
386
|
|
|
409
|
-
|
|
410
387
|
var warn = function () {};
|
|
411
388
|
|
|
412
389
|
if (!IS_PRODUCTION) {
|
|
@@ -429,16 +406,13 @@ if (!IS_PRODUCTION) {
|
|
|
429
406
|
}
|
|
430
407
|
};
|
|
431
408
|
}
|
|
432
|
-
|
|
433
409
|
function isArray(value) {
|
|
434
410
|
return Array.isArray(value);
|
|
435
411
|
} // tslint:disable-next-line:ban-types
|
|
436
412
|
|
|
437
|
-
|
|
438
413
|
function isFunction(value) {
|
|
439
414
|
return typeof value === 'function';
|
|
440
415
|
}
|
|
441
|
-
|
|
442
416
|
function isString(value) {
|
|
443
417
|
return typeof value === 'string';
|
|
444
418
|
} // export function memoizedGetter<T, TP extends { prototype: object }>(
|
|
@@ -453,7 +427,6 @@ function isString(value) {
|
|
|
453
427
|
// });
|
|
454
428
|
// }
|
|
455
429
|
|
|
456
|
-
|
|
457
430
|
function toGuard(condition, guardMap) {
|
|
458
431
|
if (!condition) {
|
|
459
432
|
return undefined;
|
|
@@ -477,7 +450,6 @@ function toGuard(condition, guardMap) {
|
|
|
477
450
|
|
|
478
451
|
return condition;
|
|
479
452
|
}
|
|
480
|
-
|
|
481
453
|
function isObservable(value) {
|
|
482
454
|
try {
|
|
483
455
|
return 'subscribe' in value && isFunction(value.subscribe);
|
|
@@ -485,11 +457,9 @@ function isObservable(value) {
|
|
|
485
457
|
return false;
|
|
486
458
|
}
|
|
487
459
|
}
|
|
488
|
-
|
|
489
460
|
var symbolObservable = /*#__PURE__*/function () {
|
|
490
461
|
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
491
462
|
}();
|
|
492
|
-
|
|
493
463
|
function isMachine(value) {
|
|
494
464
|
try {
|
|
495
465
|
return '__xstatenode' in value;
|
|
@@ -497,11 +467,9 @@ function isMachine(value) {
|
|
|
497
467
|
return false;
|
|
498
468
|
}
|
|
499
469
|
}
|
|
500
|
-
|
|
501
470
|
function isActor(value) {
|
|
502
471
|
return !!value && typeof value.send === 'function';
|
|
503
472
|
}
|
|
504
|
-
|
|
505
473
|
var uniqueId = /*#__PURE__*/function () {
|
|
506
474
|
var currentId = 0;
|
|
507
475
|
return function () {
|
|
@@ -509,7 +477,6 @@ var uniqueId = /*#__PURE__*/function () {
|
|
|
509
477
|
return currentId.toString(16);
|
|
510
478
|
};
|
|
511
479
|
}();
|
|
512
|
-
|
|
513
480
|
function toEventObject(event, payload // id?: TEvent['type']
|
|
514
481
|
) {
|
|
515
482
|
if (isString(event) || typeof event === 'number') {
|
|
@@ -520,7 +487,6 @@ function toEventObject(event, payload // id?: TEvent['type']
|
|
|
520
487
|
|
|
521
488
|
return event;
|
|
522
489
|
}
|
|
523
|
-
|
|
524
490
|
function toSCXMLEvent(event, scxmlEvent) {
|
|
525
491
|
if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
|
|
526
492
|
return event;
|
|
@@ -534,7 +500,6 @@ function toSCXMLEvent(event, scxmlEvent) {
|
|
|
534
500
|
type: 'external'
|
|
535
501
|
}, scxmlEvent);
|
|
536
502
|
}
|
|
537
|
-
|
|
538
503
|
function toTransitionConfigArray(event, configLike) {
|
|
539
504
|
var transitions = toArrayStrict(configLike).map(function (transitionLike) {
|
|
540
505
|
if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string' || isMachine(transitionLike)) {
|
|
@@ -550,7 +515,6 @@ function toTransitionConfigArray(event, configLike) {
|
|
|
550
515
|
});
|
|
551
516
|
return transitions;
|
|
552
517
|
}
|
|
553
|
-
|
|
554
518
|
function normalizeTarget(target) {
|
|
555
519
|
if (target === undefined || target === TARGETLESS_KEY) {
|
|
556
520
|
return undefined;
|
|
@@ -558,7 +522,6 @@ function normalizeTarget(target) {
|
|
|
558
522
|
|
|
559
523
|
return toArray(target);
|
|
560
524
|
}
|
|
561
|
-
|
|
562
525
|
function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
563
526
|
if (!IS_PRODUCTION) {
|
|
564
527
|
var originalStackTrace = originalError.stack ? " Stacktrace was '" + originalError.stack + "'" : '';
|
|
@@ -573,7 +536,6 @@ function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
|
573
536
|
}
|
|
574
537
|
}
|
|
575
538
|
}
|
|
576
|
-
|
|
577
539
|
function evaluateGuard(machine, guard, context, _event, state) {
|
|
578
540
|
var guards = machine.options.guards;
|
|
579
541
|
var guardMeta = {
|
|
@@ -594,7 +556,6 @@ function evaluateGuard(machine, guard, context, _event, state) {
|
|
|
594
556
|
|
|
595
557
|
return condFn(context, _event.data, guardMeta);
|
|
596
558
|
}
|
|
597
|
-
|
|
598
559
|
function toInvokeSource(src) {
|
|
599
560
|
if (typeof src === 'string') {
|
|
600
561
|
return {
|
|
@@ -604,7 +565,6 @@ function toInvokeSource(src) {
|
|
|
604
565
|
|
|
605
566
|
return src;
|
|
606
567
|
}
|
|
607
|
-
|
|
608
568
|
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
609
569
|
if (typeof nextHandler === 'object') {
|
|
610
570
|
return nextHandler;
|
|
@@ -621,4 +581,4 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
|
621
581
|
};
|
|
622
582
|
}
|
|
623
583
|
|
|
624
|
-
export { evaluateGuard, flatten, getEventType, isActor, isArray, isBehavior, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };
|
|
584
|
+
export { evaluateGuard, flatten, getEventType, isActor, isArray, isBehavior, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };
|
package/lib/Actor.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
|
|
2
|
-
import { ActorRef, BaseActorRef } from '.';
|
|
3
|
-
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {
|
|
4
|
-
id: string;
|
|
5
|
-
send: (event: TEvent) => any;
|
|
6
|
-
stop?: () => any | undefined;
|
|
7
|
-
toJSON: () => {
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
meta?: InvokeDefinition<TContext, TEvent>;
|
|
11
|
-
state?: any;
|
|
12
|
-
deferred?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare function createNullActor(id: string): ActorRef<any>;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a deferred actor that is able to be invoked given the provided
|
|
17
|
-
* invocation information in its `.meta` value.
|
|
18
|
-
*
|
|
19
|
-
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): ActorRef<any>;
|
|
22
|
-
export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): ActorRef<any, undefined>;
|
|
23
|
-
export declare function isActor(item: any): item is ActorRef<any>;
|
|
24
|
-
export declare function isSpawnedActor(item: any): item is ActorRef<any>;
|
|
25
|
-
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted>;
|
|
1
|
+
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
|
|
2
|
+
import { ActorRef, BaseActorRef } from '.';
|
|
3
|
+
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {
|
|
4
|
+
id: string;
|
|
5
|
+
send: (event: TEvent) => any;
|
|
6
|
+
stop?: () => any | undefined;
|
|
7
|
+
toJSON: () => {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
meta?: InvokeDefinition<TContext, TEvent>;
|
|
11
|
+
state?: any;
|
|
12
|
+
deferred?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createNullActor(id: string): ActorRef<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a deferred actor that is able to be invoked given the provided
|
|
17
|
+
* invocation information in its `.meta` value.
|
|
18
|
+
*
|
|
19
|
+
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): ActorRef<any>;
|
|
22
|
+
export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): ActorRef<any, undefined>;
|
|
23
|
+
export declare function isActor(item: any): item is ActorRef<any>;
|
|
24
|
+
export declare function isSpawnedActor(item: any): item is ActorRef<any>;
|
|
25
|
+
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted>;
|
|
26
26
|
//# sourceMappingURL=Actor.d.ts.map
|
package/lib/Actor.js
CHANGED
|
@@ -1,80 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.toActorRef = exports.isSpawnedActor = exports.isActor = exports.createDeferredActor = exports.createInvocableActor = exports.createNullActor = void 0;
|
|
15
|
-
var utils_1 = require("./utils");
|
|
16
|
-
var serviceScope = require("./serviceScope");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
var utils = require('./utils.js');
|
|
7
|
+
var serviceScope = require('./serviceScope.js');
|
|
8
|
+
|
|
17
9
|
function createNullActor(id) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
10
|
+
return {
|
|
11
|
+
id: id,
|
|
12
|
+
send: function () {
|
|
13
|
+
return void 0;
|
|
14
|
+
},
|
|
15
|
+
subscribe: function () {
|
|
16
|
+
return {
|
|
17
|
+
unsubscribe: function () {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
getSnapshot: function () {
|
|
23
|
+
return undefined;
|
|
24
|
+
},
|
|
25
|
+
toJSON: function () {
|
|
26
|
+
return {
|
|
27
|
+
id: id
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
32
|
+
/**
|
|
33
|
+
* Creates a deferred actor that is able to be invoked given the provided
|
|
34
|
+
* invocation information in its `.meta` value.
|
|
35
|
+
*
|
|
36
|
+
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
36
37
|
*/
|
|
38
|
+
|
|
37
39
|
function createInvocableActor(invokeDefinition, machine, context, _event) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
tempActor.meta = invokeDefinition;
|
|
49
|
-
return tempActor;
|
|
40
|
+
var _a;
|
|
41
|
+
|
|
42
|
+
var invokeSrc = utils.toInvokeSource(invokeDefinition.src);
|
|
43
|
+
var serviceCreator = (_a = machine === null || machine === void 0 ? void 0 : machine.options.services) === null || _a === void 0 ? void 0 : _a[invokeSrc.type];
|
|
44
|
+
var resolvedData = invokeDefinition.data ? utils.mapContext(invokeDefinition.data, context, _event) : undefined;
|
|
45
|
+
var tempActor = serviceCreator ? createDeferredActor(serviceCreator, invokeDefinition.id, resolvedData) : createNullActor(invokeDefinition.id); // @ts-ignore
|
|
46
|
+
|
|
47
|
+
tempActor.meta = invokeDefinition;
|
|
48
|
+
return tempActor;
|
|
50
49
|
}
|
|
51
|
-
exports.createInvocableActor = createInvocableActor;
|
|
52
50
|
function createDeferredActor(entity, id, data) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
var tempActor = createNullActor(id); // @ts-ignore
|
|
52
|
+
|
|
53
|
+
tempActor.deferred = true;
|
|
54
|
+
|
|
55
|
+
if (utils.isMachine(entity)) {
|
|
56
|
+
// "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
|
|
57
|
+
var initialState_1 = tempActor.state = serviceScope.provide(undefined, function () {
|
|
58
|
+
return (data ? entity.withContext(data) : entity).initialState;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
tempActor.getSnapshot = function () {
|
|
62
|
+
return initialState_1;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return tempActor;
|
|
62
67
|
}
|
|
63
|
-
exports.createDeferredActor = createDeferredActor;
|
|
64
68
|
function isActor(item) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
69
|
+
try {
|
|
70
|
+
return typeof item.send === 'function';
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
71
74
|
}
|
|
72
|
-
exports.isActor = isActor;
|
|
73
75
|
function isSpawnedActor(item) {
|
|
74
|
-
|
|
76
|
+
return isActor(item) && 'id' in item;
|
|
75
77
|
}
|
|
76
|
-
exports.isSpawnedActor = isSpawnedActor;
|
|
77
78
|
function toActorRef(actorRefLike) {
|
|
78
|
-
|
|
79
|
+
return _tslib.__assign({
|
|
80
|
+
subscribe: function () {
|
|
81
|
+
return {
|
|
82
|
+
unsubscribe: function () {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
id: 'anonymous',
|
|
88
|
+
getSnapshot: function () {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}, actorRefLike);
|
|
79
92
|
}
|
|
93
|
+
|
|
94
|
+
exports.createDeferredActor = createDeferredActor;
|
|
95
|
+
exports.createInvocableActor = createInvocableActor;
|
|
96
|
+
exports.createNullActor = createNullActor;
|
|
97
|
+
exports.isActor = isActor;
|
|
98
|
+
exports.isSpawnedActor = isSpawnedActor;
|
|
80
99
|
exports.toActorRef = toActorRef;
|
package/lib/Machine.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate } from './types';
|
|
2
|
-
import { Model, ModelContextFrom
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use `createMachine(...)` instead.
|
|
5
|
-
*/
|
|
6
|
-
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
|
|
7
|
-
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
|
|
8
|
-
export declare function createMachine<TModel extends Model<any, any, any>, TContext = ModelContextFrom<TModel>, TEvent extends EventObject =
|
|
9
|
-
value: any;
|
|
10
|
-
context: TContext;
|
|
11
|
-
}>(config: MachineConfig<TContext, any, TEvent> & {
|
|
12
|
-
context: TContext;
|
|
13
|
-
}, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
14
|
-
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
15
|
-
value: any;
|
|
16
|
-
context: TContext;
|
|
17
|
-
}>(config: TContext extends Model<any, any, any> ? never : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
1
|
+
import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate, EventFrom } from './types';
|
|
2
|
+
import { Model, ModelContextFrom } from './model.types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use `createMachine(...)` instead.
|
|
5
|
+
*/
|
|
6
|
+
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
|
|
7
|
+
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
|
|
8
|
+
export declare function createMachine<TModel extends Model<any, any, any>, TContext = ModelContextFrom<TModel>, TEvent extends EventObject = EventFrom<TModel>, TTypestate extends Typestate<TContext> = {
|
|
9
|
+
value: any;
|
|
10
|
+
context: TContext;
|
|
11
|
+
}>(config: MachineConfig<TContext, any, TEvent> & {
|
|
12
|
+
context: TContext;
|
|
13
|
+
}, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
14
|
+
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
15
|
+
value: any;
|
|
16
|
+
context: TContext;
|
|
17
|
+
}>(config: TContext extends Model<any, any, any> ? never : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
18
18
|
//# sourceMappingURL=Machine.d.ts.map
|
package/lib/Machine.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var StateNode = require('./StateNode.js');
|
|
6
|
+
|
|
5
7
|
function Machine(config, options, initialContext) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
if (initialContext === void 0) {
|
|
9
|
+
initialContext = config.context;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return new StateNode.StateNode(config, options, initialContext);
|
|
8
13
|
}
|
|
9
|
-
exports.Machine = Machine;
|
|
10
14
|
function createMachine(config, options) {
|
|
11
|
-
|
|
15
|
+
return new StateNode.StateNode(config, options);
|
|
12
16
|
}
|
|
17
|
+
|
|
18
|
+
exports.Machine = Machine;
|
|
13
19
|
exports.createMachine = createMachine;
|
package/lib/SimulatedClock.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Clock } from './interpreter';
|
|
2
|
-
export interface SimulatedClock extends Clock {
|
|
3
|
-
start(speed: number): void;
|
|
4
|
-
increment(ms: number): void;
|
|
5
|
-
set(ms: number): void;
|
|
6
|
-
}
|
|
7
|
-
export declare class SimulatedClock implements SimulatedClock {
|
|
8
|
-
private timeouts;
|
|
9
|
-
private _now;
|
|
10
|
-
private _id;
|
|
11
|
-
now(): number;
|
|
12
|
-
private getId;
|
|
13
|
-
setTimeout(fn: (...args: any[]) => void, timeout: number): number;
|
|
14
|
-
clearTimeout(id: number): void;
|
|
15
|
-
private flushTimeouts;
|
|
16
|
-
}
|
|
1
|
+
import { Clock } from './interpreter';
|
|
2
|
+
export interface SimulatedClock extends Clock {
|
|
3
|
+
start(speed: number): void;
|
|
4
|
+
increment(ms: number): void;
|
|
5
|
+
set(ms: number): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class SimulatedClock implements SimulatedClock {
|
|
8
|
+
private timeouts;
|
|
9
|
+
private _now;
|
|
10
|
+
private _id;
|
|
11
|
+
now(): number;
|
|
12
|
+
private getId;
|
|
13
|
+
setTimeout(fn: (...args: any[]) => void, timeout: number): number;
|
|
14
|
+
clearTimeout(id: number): void;
|
|
15
|
+
private flushTimeouts;
|
|
16
|
+
}
|
|
17
17
|
//# sourceMappingURL=SimulatedClock.d.ts.map
|