xstate 4.13.0 → 4.14.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 +21 -0
- package/LICENSE +22 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/StateNode.js +3 -1
- package/es/actions.d.ts +7 -3
- package/es/actions.js +23 -6
- package/es/index.d.ts +2 -2
- package/es/index.js +1 -1
- package/es/interpreter.d.ts +7 -2
- package/es/interpreter.js +75 -54
- package/es/match.d.ts +4 -1
- package/es/types.d.ts +33 -1
- package/lib/StateNode.js +2 -1
- package/lib/actions.d.ts +7 -3
- package/lib/actions.js +24 -5
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -2
- package/lib/interpreter.d.ts +7 -2
- package/lib/interpreter.js +56 -41
- package/lib/match.d.ts +4 -1
- package/lib/types.d.ts +33 -1
- package/package.json +4 -4
package/es/interpreter.js
CHANGED
|
@@ -55,7 +55,7 @@ function () {
|
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
57
|
this.initialized = false;
|
|
58
|
-
this.
|
|
58
|
+
this.status = InterpreterStatus.NotStarted;
|
|
59
59
|
this.children = new Map();
|
|
60
60
|
this.forwardTo = new Set();
|
|
61
61
|
/**
|
|
@@ -82,7 +82,7 @@ function () {
|
|
|
82
82
|
|
|
83
83
|
var _event = toSCXMLEvent(toEventObject(event, payload));
|
|
84
84
|
|
|
85
|
-
if (_this.
|
|
85
|
+
if (_this.status === InterpreterStatus.Stopped) {
|
|
86
86
|
// do nothing
|
|
87
87
|
if (!IS_PRODUCTION) {
|
|
88
88
|
warn(false, "Event \"" + _event.name + "\" was sent to stopped service \"" + _this.machine.id + "\". This service has already reached its final state, and will not transition.\nEvent: " + JSON.stringify(_event.data));
|
|
@@ -91,12 +91,7 @@ function () {
|
|
|
91
91
|
return _this.state;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
if (_this.
|
|
95
|
-
// tslint:disable-next-line:no-console
|
|
96
|
-
if (!IS_PRODUCTION) {
|
|
97
|
-
warn(false, "Event \"" + _event.name + "\" was sent to uninitialized service \"" + _this.machine.id + "\" and is deferred. Make sure .start() is called for this service.\nEvent: " + JSON.stringify(_event.data));
|
|
98
|
-
}
|
|
99
|
-
} else if (_this._status !== InterpreterStatus.Running) {
|
|
94
|
+
if (_this.status !== InterpreterStatus.Running && !_this.options.deferEvents) {
|
|
100
95
|
throw new Error("Event \"" + _event.name + "\" was sent to uninitialized service \"" + _this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: " + JSON.stringify(_event.data));
|
|
101
96
|
}
|
|
102
97
|
|
|
@@ -179,7 +174,7 @@ function () {
|
|
|
179
174
|
Object.defineProperty(Interpreter.prototype, "state", {
|
|
180
175
|
get: function () {
|
|
181
176
|
if (!IS_PRODUCTION) {
|
|
182
|
-
warn(this.
|
|
177
|
+
warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '" + this.id + "'. Make sure the service is started first.");
|
|
183
178
|
}
|
|
184
179
|
|
|
185
180
|
return this._state;
|
|
@@ -227,8 +222,12 @@ function () {
|
|
|
227
222
|
|
|
228
223
|
if (this.options.execute) {
|
|
229
224
|
this.execute(this.state);
|
|
230
|
-
} //
|
|
225
|
+
} // Update children
|
|
226
|
+
|
|
231
227
|
|
|
228
|
+
this.children.forEach(function (child) {
|
|
229
|
+
_this.state.children[child.id] = child;
|
|
230
|
+
}); // Dev tools
|
|
232
231
|
|
|
233
232
|
if (this.devTools) {
|
|
234
233
|
this.devTools.send(_event.data, state);
|
|
@@ -291,7 +290,29 @@ function () {
|
|
|
291
290
|
var isDone = isInFinalState(state.configuration || [], this.machine);
|
|
292
291
|
|
|
293
292
|
if (this.state.configuration && isDone) {
|
|
294
|
-
//
|
|
293
|
+
// exit interpreter procedure: https://www.w3.org/TR/scxml/#exitInterpreter
|
|
294
|
+
this.state.configuration.forEach(function (stateNode) {
|
|
295
|
+
var e_6, _a;
|
|
296
|
+
|
|
297
|
+
try {
|
|
298
|
+
for (var _b = __values(stateNode.definition.exit), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
299
|
+
var action = _c.value;
|
|
300
|
+
|
|
301
|
+
_this.exec(action, state);
|
|
302
|
+
}
|
|
303
|
+
} catch (e_6_1) {
|
|
304
|
+
e_6 = {
|
|
305
|
+
error: e_6_1
|
|
306
|
+
};
|
|
307
|
+
} finally {
|
|
308
|
+
try {
|
|
309
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
310
|
+
} finally {
|
|
311
|
+
if (e_6) throw e_6.error;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}); // get final child state node
|
|
315
|
+
|
|
295
316
|
var finalChildStateNode = state.configuration.find(function (sn) {
|
|
296
317
|
return sn.type === 'final' && sn.parent === _this.machine;
|
|
297
318
|
});
|
|
@@ -328,7 +349,7 @@ function () {
|
|
|
328
349
|
Interpreter.prototype.onTransition = function (listener) {
|
|
329
350
|
this.listeners.add(listener); // Send current state to listener
|
|
330
351
|
|
|
331
|
-
if (this.
|
|
352
|
+
if (this.status === InterpreterStatus.Running) {
|
|
332
353
|
listener(this.state, this.state.event);
|
|
333
354
|
}
|
|
334
355
|
|
|
@@ -359,7 +380,7 @@ function () {
|
|
|
359
380
|
|
|
360
381
|
this.listeners.add(listener); // Send current state to listener
|
|
361
382
|
|
|
362
|
-
if (this.
|
|
383
|
+
if (this.status === InterpreterStatus.Running) {
|
|
363
384
|
listener(this.state);
|
|
364
385
|
}
|
|
365
386
|
|
|
@@ -448,14 +469,14 @@ function () {
|
|
|
448
469
|
Interpreter.prototype.start = function (initialState) {
|
|
449
470
|
var _this = this;
|
|
450
471
|
|
|
451
|
-
if (this.
|
|
472
|
+
if (this.status === InterpreterStatus.Running) {
|
|
452
473
|
// Do not restart the service if it is already started
|
|
453
474
|
return this;
|
|
454
475
|
}
|
|
455
476
|
|
|
456
477
|
registry.register(this.sessionId, this);
|
|
457
478
|
this.initialized = true;
|
|
458
|
-
this.
|
|
479
|
+
this.status = InterpreterStatus.Running;
|
|
459
480
|
var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
|
|
460
481
|
return isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
|
|
461
482
|
});
|
|
@@ -477,22 +498,22 @@ function () {
|
|
|
477
498
|
|
|
478
499
|
|
|
479
500
|
Interpreter.prototype.stop = function () {
|
|
480
|
-
var
|
|
501
|
+
var e_7, _a, e_8, _b, e_9, _c, e_10, _d, e_11, _e;
|
|
481
502
|
|
|
482
503
|
try {
|
|
483
504
|
for (var _f = __values(this.listeners), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
484
505
|
var listener = _g.value;
|
|
485
506
|
this.listeners.delete(listener);
|
|
486
507
|
}
|
|
487
|
-
} catch (
|
|
488
|
-
|
|
489
|
-
error:
|
|
508
|
+
} catch (e_7_1) {
|
|
509
|
+
e_7 = {
|
|
510
|
+
error: e_7_1
|
|
490
511
|
};
|
|
491
512
|
} finally {
|
|
492
513
|
try {
|
|
493
514
|
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
494
515
|
} finally {
|
|
495
|
-
if (
|
|
516
|
+
if (e_7) throw e_7.error;
|
|
496
517
|
}
|
|
497
518
|
}
|
|
498
519
|
|
|
@@ -503,15 +524,15 @@ function () {
|
|
|
503
524
|
listener();
|
|
504
525
|
this.stopListeners.delete(listener);
|
|
505
526
|
}
|
|
506
|
-
} catch (
|
|
507
|
-
|
|
508
|
-
error:
|
|
527
|
+
} catch (e_8_1) {
|
|
528
|
+
e_8 = {
|
|
529
|
+
error: e_8_1
|
|
509
530
|
};
|
|
510
531
|
} finally {
|
|
511
532
|
try {
|
|
512
533
|
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
513
534
|
} finally {
|
|
514
|
-
if (
|
|
535
|
+
if (e_8) throw e_8.error;
|
|
515
536
|
}
|
|
516
537
|
}
|
|
517
538
|
|
|
@@ -520,15 +541,15 @@ function () {
|
|
|
520
541
|
var listener = _l.value;
|
|
521
542
|
this.contextListeners.delete(listener);
|
|
522
543
|
}
|
|
523
|
-
} catch (
|
|
524
|
-
|
|
525
|
-
error:
|
|
544
|
+
} catch (e_9_1) {
|
|
545
|
+
e_9 = {
|
|
546
|
+
error: e_9_1
|
|
526
547
|
};
|
|
527
548
|
} finally {
|
|
528
549
|
try {
|
|
529
550
|
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
530
551
|
} finally {
|
|
531
|
-
if (
|
|
552
|
+
if (e_9) throw e_9.error;
|
|
532
553
|
}
|
|
533
554
|
}
|
|
534
555
|
|
|
@@ -537,15 +558,15 @@ function () {
|
|
|
537
558
|
var listener = _o.value;
|
|
538
559
|
this.doneListeners.delete(listener);
|
|
539
560
|
}
|
|
540
|
-
} catch (
|
|
541
|
-
|
|
542
|
-
error:
|
|
561
|
+
} catch (e_10_1) {
|
|
562
|
+
e_10 = {
|
|
563
|
+
error: e_10_1
|
|
543
564
|
};
|
|
544
565
|
} finally {
|
|
545
566
|
try {
|
|
546
567
|
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
547
568
|
} finally {
|
|
548
|
-
if (
|
|
569
|
+
if (e_10) throw e_10.error;
|
|
549
570
|
}
|
|
550
571
|
} // Stop all children
|
|
551
572
|
|
|
@@ -562,21 +583,21 @@ function () {
|
|
|
562
583
|
var key = _q.value;
|
|
563
584
|
this.clock.clearTimeout(this.delayedEventsMap[key]);
|
|
564
585
|
}
|
|
565
|
-
} catch (
|
|
566
|
-
|
|
567
|
-
error:
|
|
586
|
+
} catch (e_11_1) {
|
|
587
|
+
e_11 = {
|
|
588
|
+
error: e_11_1
|
|
568
589
|
};
|
|
569
590
|
} finally {
|
|
570
591
|
try {
|
|
571
592
|
if (_q && !_q.done && (_e = _p.return)) _e.call(_p);
|
|
572
593
|
} finally {
|
|
573
|
-
if (
|
|
594
|
+
if (e_11) throw e_11.error;
|
|
574
595
|
}
|
|
575
596
|
}
|
|
576
597
|
|
|
577
598
|
this.scheduler.clear();
|
|
578
599
|
this.initialized = false;
|
|
579
|
-
this.
|
|
600
|
+
this.status = InterpreterStatus.Stopped;
|
|
580
601
|
registry.free(this.sessionId);
|
|
581
602
|
return this;
|
|
582
603
|
};
|
|
@@ -584,18 +605,18 @@ function () {
|
|
|
584
605
|
Interpreter.prototype.batch = function (events) {
|
|
585
606
|
var _this = this;
|
|
586
607
|
|
|
587
|
-
if (this.
|
|
608
|
+
if (this.status === InterpreterStatus.NotStarted && this.options.deferEvents) {
|
|
588
609
|
// tslint:disable-next-line:no-console
|
|
589
610
|
if (!IS_PRODUCTION) {
|
|
590
611
|
warn(false, events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\" and are deferred. Make sure .start() is called for this service.\nEvent: " + JSON.stringify(event));
|
|
591
612
|
}
|
|
592
|
-
} else if (this.
|
|
613
|
+
} else if (this.status !== InterpreterStatus.Running) {
|
|
593
614
|
throw new Error( // tslint:disable-next-line:max-line-length
|
|
594
615
|
events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.");
|
|
595
616
|
}
|
|
596
617
|
|
|
597
618
|
this.scheduler.schedule(function () {
|
|
598
|
-
var
|
|
619
|
+
var e_12, _a;
|
|
599
620
|
|
|
600
621
|
var nextState = _this.state;
|
|
601
622
|
var batchChanged = false;
|
|
@@ -621,15 +642,15 @@ function () {
|
|
|
621
642
|
|
|
622
643
|
_loop_1(event_1);
|
|
623
644
|
}
|
|
624
|
-
} catch (
|
|
625
|
-
|
|
626
|
-
error:
|
|
645
|
+
} catch (e_12_1) {
|
|
646
|
+
e_12 = {
|
|
647
|
+
error: e_12_1
|
|
627
648
|
};
|
|
628
649
|
} finally {
|
|
629
650
|
try {
|
|
630
651
|
if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
|
|
631
652
|
} finally {
|
|
632
|
-
if (
|
|
653
|
+
if (e_12) throw e_12.error;
|
|
633
654
|
}
|
|
634
655
|
}
|
|
635
656
|
|
|
@@ -676,7 +697,7 @@ function () {
|
|
|
676
697
|
};
|
|
677
698
|
|
|
678
699
|
Interpreter.prototype.forward = function (event) {
|
|
679
|
-
var
|
|
700
|
+
var e_13, _a;
|
|
680
701
|
|
|
681
702
|
try {
|
|
682
703
|
for (var _b = __values(this.forwardTo), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -689,15 +710,15 @@ function () {
|
|
|
689
710
|
|
|
690
711
|
child.send(event);
|
|
691
712
|
}
|
|
692
|
-
} catch (
|
|
693
|
-
|
|
694
|
-
error:
|
|
713
|
+
} catch (e_13_1) {
|
|
714
|
+
e_13 = {
|
|
715
|
+
error: e_13_1
|
|
695
716
|
};
|
|
696
717
|
} finally {
|
|
697
718
|
try {
|
|
698
719
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
699
720
|
} finally {
|
|
700
|
-
if (
|
|
721
|
+
if (e_13) throw e_13.error;
|
|
701
722
|
}
|
|
702
723
|
}
|
|
703
724
|
};
|
|
@@ -809,14 +830,14 @@ function () {
|
|
|
809
830
|
}) : serviceCreator;
|
|
810
831
|
|
|
811
832
|
if (isPromiseLike(source)) {
|
|
812
|
-
this.
|
|
833
|
+
this.spawnPromise(Promise.resolve(source), id);
|
|
813
834
|
} else if (isFunction(source)) {
|
|
814
|
-
this.
|
|
835
|
+
this.spawnCallback(source, id);
|
|
815
836
|
} else if (isObservable(source)) {
|
|
816
|
-
this.
|
|
837
|
+
this.spawnObservable(source, id);
|
|
817
838
|
} else if (isMachine(source)) {
|
|
818
839
|
// TODO: try/catch here
|
|
819
|
-
this.
|
|
840
|
+
this.spawnMachine(resolvedData ? source.withContext(resolvedData) : source, {
|
|
820
841
|
id: id,
|
|
821
842
|
autoForward: autoForward
|
|
822
843
|
});
|
|
@@ -1278,4 +1299,4 @@ function interpret(machine, options) {
|
|
|
1278
1299
|
return interpreter;
|
|
1279
1300
|
}
|
|
1280
1301
|
|
|
1281
|
-
export { Interpreter, interpret, spawn };
|
|
1302
|
+
export { Interpreter, InterpreterStatus, interpret, spawn };
|
package/es/match.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { State } from './State';
|
|
2
2
|
import { StateValue, EventObject } from './types';
|
|
3
3
|
export declare type ValueFromStateGetter<T, TContext, TEvent extends EventObject> = (state: State<TContext, TEvent>) => T;
|
|
4
|
-
export declare type StatePatternTuple<T, TContext, TEvent extends EventObject> = [
|
|
4
|
+
export declare type StatePatternTuple<T, TContext, TEvent extends EventObject> = [
|
|
5
|
+
StateValue,
|
|
6
|
+
ValueFromStateGetter<T, TContext, TEvent>
|
|
7
|
+
];
|
|
5
8
|
export declare function matchState<T, TContext, TEvent extends EventObject>(state: State<TContext, TEvent> | StateValue, patterns: Array<StatePatternTuple<T, TContext, TEvent>>, defaultValue: ValueFromStateGetter<T, TContext, TEvent>): T;
|
|
6
9
|
//# sourceMappingURL=match.d.ts.map
|
package/es/types.d.ts
CHANGED
|
@@ -116,6 +116,24 @@ export interface ActivityDefinition<TContext, TEvent extends EventObject> extend
|
|
|
116
116
|
type: string;
|
|
117
117
|
}
|
|
118
118
|
export declare type Sender<TEvent extends EventObject> = (event: Event<TEvent>) => void;
|
|
119
|
+
declare type ExcludeType<A> = {
|
|
120
|
+
[K in Exclude<keyof A, 'type'>]: A[K];
|
|
121
|
+
};
|
|
122
|
+
declare type ExtractExtraParameters<A, T> = A extends {
|
|
123
|
+
type: T;
|
|
124
|
+
} ? ExcludeType<A> : never;
|
|
125
|
+
declare type ExtractSimple<A> = A extends any ? {} extends ExcludeType<A> ? A : never : never;
|
|
126
|
+
declare type NeverIfEmpty<T> = {} extends T ? never : T;
|
|
127
|
+
export interface PayloadSender<TEvent extends EventObject> {
|
|
128
|
+
/**
|
|
129
|
+
* Send an event object or just the event type, if the event has no other payload
|
|
130
|
+
*/
|
|
131
|
+
(event: TEvent | ExtractSimple<TEvent>['type']): void;
|
|
132
|
+
/**
|
|
133
|
+
* Send an event type and its payload
|
|
134
|
+
*/
|
|
135
|
+
<K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
|
|
136
|
+
}
|
|
119
137
|
export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
|
|
120
138
|
export declare type InvokeCallback = (callback: Sender<any>, onReceive: Receiver<EventObject>) => any;
|
|
121
139
|
export interface InvokeMeta {
|
|
@@ -541,7 +559,7 @@ export interface NullEvent {
|
|
|
541
559
|
}
|
|
542
560
|
export interface ActivityActionObject<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
|
|
543
561
|
type: ActionTypes.Start | ActionTypes.Stop;
|
|
544
|
-
activity: ActivityDefinition<TContext, TEvent
|
|
562
|
+
activity: ActivityDefinition<TContext, TEvent> | undefined;
|
|
545
563
|
exec: ActionFunction<TContext, TEvent> | undefined;
|
|
546
564
|
}
|
|
547
565
|
export interface InvokeActionObject<TContext, TEvent extends EventObject> extends ActivityActionObject<TContext, TEvent> {
|
|
@@ -569,6 +587,20 @@ export interface SendActionObject<TContext, TEvent extends EventObject, TSentEve
|
|
|
569
587
|
delay?: number;
|
|
570
588
|
id: string | number;
|
|
571
589
|
}
|
|
590
|
+
export interface StopAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
|
|
591
|
+
type: ActionTypes.Stop;
|
|
592
|
+
activity: string | {
|
|
593
|
+
id: string;
|
|
594
|
+
} | Expr<TContext, TEvent, string | {
|
|
595
|
+
id: string;
|
|
596
|
+
}>;
|
|
597
|
+
}
|
|
598
|
+
export interface StopActionObject {
|
|
599
|
+
type: ActionTypes.Stop;
|
|
600
|
+
activity: {
|
|
601
|
+
id: string;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
572
604
|
export declare type Expr<TContext, TEvent extends EventObject, T> = (context: TContext, event: TEvent) => T;
|
|
573
605
|
export declare type ExprWithMeta<TContext, TEvent extends EventObject, T> = (context: TContext, event: TEvent, meta: SCXMLEventMeta<TEvent>) => T;
|
|
574
606
|
export declare type SendExpr<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> = ExprWithMeta<TContext, TEvent, TSentEvent>;
|
package/lib/StateNode.js
CHANGED
|
@@ -792,8 +792,9 @@ var StateNode = /** @class */ (function () {
|
|
|
792
792
|
types_1.SpecialTargets.Internal);
|
|
793
793
|
}), 2), raisedEvents = _c[0], nonRaisedActions = _c[1];
|
|
794
794
|
var invokeActions = resolvedActions.filter(function (action) {
|
|
795
|
+
var _a;
|
|
795
796
|
return (action.type === actionTypes.start &&
|
|
796
|
-
action.activity.type ===
|
|
797
|
+
((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
797
798
|
actionTypes.invoke);
|
|
798
799
|
});
|
|
799
800
|
var children = invokeActions.reduce(function (acc, action) {
|
package/lib/actions.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseConditon, ChooseAction, AnyEventObject } from './types';
|
|
1
|
+
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseConditon, ChooseAction, AnyEventObject, Expr } from './types';
|
|
2
2
|
import * as actionTypes from './actionTypes';
|
|
3
3
|
import { State } from './State';
|
|
4
4
|
import { StateNode } from './StateNode';
|
|
5
|
+
import { StopAction, StopActionObject } from '.';
|
|
5
6
|
export { actionTypes };
|
|
6
7
|
export declare const initEvent: SCXML.Event<{
|
|
7
8
|
type: ActionTypes;
|
|
@@ -77,9 +78,12 @@ export declare function start<TContext, TEvent extends EventObject>(activity: st
|
|
|
77
78
|
/**
|
|
78
79
|
* Stops an activity.
|
|
79
80
|
*
|
|
80
|
-
* @param
|
|
81
|
+
* @param actorRef The activity to stop.
|
|
81
82
|
*/
|
|
82
|
-
export declare function stop<TContext, TEvent extends EventObject>(
|
|
83
|
+
export declare function stop<TContext, TEvent extends EventObject>(actorRef: string | ActivityDefinition<TContext, TEvent> | Expr<TContext, TEvent, string | {
|
|
84
|
+
id: string;
|
|
85
|
+
}>): StopAction<TContext, TEvent>;
|
|
86
|
+
export declare function resolveStop<TContext, TEvent extends EventObject>(action: StopAction<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>): StopActionObject;
|
|
83
87
|
/**
|
|
84
88
|
* Updates the current context of the machine.
|
|
85
89
|
*
|
package/lib/actions.js
CHANGED
|
@@ -27,7 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.resolveActions = exports.choose = exports.escalate = exports.forwardTo = exports.pure = exports.error = exports.doneInvoke = exports.done = exports.after = exports.isActionObject = exports.assign = exports.stop = exports.start = exports.cancel = exports.resolveLog = exports.log = exports.respond = exports.sendUpdate = exports.sendParent = exports.resolveSend = exports.send = exports.resolveRaise = exports.raise = exports.toActivityDefinition = exports.toActionObjects = exports.toActionObject = exports.getActionFunction = exports.initEvent = exports.actionTypes = void 0;
|
|
30
|
+
exports.resolveActions = exports.choose = exports.escalate = exports.forwardTo = exports.pure = exports.error = exports.doneInvoke = exports.done = exports.after = exports.isActionObject = exports.assign = exports.resolveStop = exports.stop = exports.start = exports.cancel = exports.resolveLog = exports.log = exports.respond = exports.sendUpdate = exports.sendParent = exports.resolveSend = exports.send = exports.resolveRaise = exports.raise = exports.toActivityDefinition = exports.toActionObjects = exports.toActionObject = exports.getActionFunction = exports.initEvent = exports.actionTypes = void 0;
|
|
31
31
|
var types_1 = require("./types");
|
|
32
32
|
var actionTypes = require("./actionTypes");
|
|
33
33
|
exports.actionTypes = actionTypes;
|
|
@@ -258,17 +258,33 @@ exports.start = start;
|
|
|
258
258
|
/**
|
|
259
259
|
* Stops an activity.
|
|
260
260
|
*
|
|
261
|
-
* @param
|
|
261
|
+
* @param actorRef The activity to stop.
|
|
262
262
|
*/
|
|
263
|
-
function stop(
|
|
264
|
-
var
|
|
263
|
+
function stop(actorRef) {
|
|
264
|
+
var activity = utils_1.isFunction(actorRef)
|
|
265
|
+
? actorRef
|
|
266
|
+
: toActivityDefinition(actorRef);
|
|
265
267
|
return {
|
|
266
268
|
type: types_1.ActionTypes.Stop,
|
|
267
|
-
activity:
|
|
269
|
+
activity: activity,
|
|
268
270
|
exec: undefined
|
|
269
271
|
};
|
|
270
272
|
}
|
|
271
273
|
exports.stop = stop;
|
|
274
|
+
function resolveStop(action, context, _event) {
|
|
275
|
+
var actorRefOrString = utils_1.isFunction(action.activity)
|
|
276
|
+
? action.activity(context, _event.data)
|
|
277
|
+
: action.activity;
|
|
278
|
+
var resolvedActorRef = typeof actorRefOrString === 'string'
|
|
279
|
+
? { id: actorRefOrString }
|
|
280
|
+
: actorRefOrString;
|
|
281
|
+
var actionObject = {
|
|
282
|
+
type: types_1.ActionTypes.Stop,
|
|
283
|
+
activity: resolvedActorRef
|
|
284
|
+
};
|
|
285
|
+
return actionObject;
|
|
286
|
+
}
|
|
287
|
+
exports.resolveStop = resolveStop;
|
|
272
288
|
/**
|
|
273
289
|
* Updates the current context of the machine.
|
|
274
290
|
*
|
|
@@ -428,6 +444,9 @@ function resolveActions(machine, currentState, currentContext, _event, actions)
|
|
|
428
444
|
updatedContext = resolved[1];
|
|
429
445
|
return resolved[0];
|
|
430
446
|
}
|
|
447
|
+
case actionTypes.stop: {
|
|
448
|
+
return resolveStop(actionObject, updatedContext, _event);
|
|
449
|
+
}
|
|
431
450
|
default:
|
|
432
451
|
return toActionObject(actionObject, machine.options.actions);
|
|
433
452
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { State } from './State';
|
|
|
5
5
|
import { Machine, createMachine } from './Machine';
|
|
6
6
|
import { Actor } from './Actor';
|
|
7
7
|
import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
|
|
8
|
-
import { interpret, Interpreter, spawn } from './interpreter';
|
|
8
|
+
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
|
|
9
9
|
import { matchState } from './match';
|
|
10
10
|
declare const actions: {
|
|
11
11
|
raise: typeof raise;
|
|
@@ -25,6 +25,6 @@ declare const actions: {
|
|
|
25
25
|
choose: typeof choose;
|
|
26
26
|
pure: typeof pure;
|
|
27
27
|
};
|
|
28
|
-
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, matchState, spawn, doneInvoke, createMachine };
|
|
28
|
+
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine };
|
|
29
29
|
export * from './types';
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -7,10 +7,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.createMachine = exports.doneInvoke = exports.spawn = exports.matchState = exports.Interpreter = exports.interpret = exports.forwardTo = exports.sendUpdate = exports.sendParent = exports.send = exports.assign = exports.actions = exports.mapState = exports.matchesState = exports.State = exports.StateNode = exports.Machine = void 0;
|
|
13
|
+
exports.createMachine = exports.doneInvoke = exports.spawn = exports.matchState = exports.InterpreterStatus = exports.Interpreter = exports.interpret = exports.forwardTo = exports.sendUpdate = exports.sendParent = exports.send = exports.assign = exports.actions = exports.mapState = exports.matchesState = exports.State = exports.StateNode = exports.Machine = void 0;
|
|
14
14
|
var utils_1 = require("./utils");
|
|
15
15
|
Object.defineProperty(exports, "matchesState", { enumerable: true, get: function () { return utils_1.matchesState; } });
|
|
16
16
|
var mapState_1 = require("./mapState");
|
|
@@ -33,6 +33,7 @@ var interpreter_1 = require("./interpreter");
|
|
|
33
33
|
Object.defineProperty(exports, "interpret", { enumerable: true, get: function () { return interpreter_1.interpret; } });
|
|
34
34
|
Object.defineProperty(exports, "Interpreter", { enumerable: true, get: function () { return interpreter_1.Interpreter; } });
|
|
35
35
|
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return interpreter_1.spawn; } });
|
|
36
|
+
Object.defineProperty(exports, "InterpreterStatus", { enumerable: true, get: function () { return interpreter_1.InterpreterStatus; } });
|
|
36
37
|
var match_1 = require("./match");
|
|
37
38
|
Object.defineProperty(exports, "matchState", { enumerable: true, get: function () { return match_1.matchState; } });
|
|
38
39
|
var actions = {
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ interface SpawnOptions {
|
|
|
17
17
|
autoForward?: boolean;
|
|
18
18
|
sync?: boolean;
|
|
19
19
|
}
|
|
20
|
+
export declare enum InterpreterStatus {
|
|
21
|
+
NotStarted = 0,
|
|
22
|
+
Running = 1,
|
|
23
|
+
Stopped = 2
|
|
24
|
+
}
|
|
20
25
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
21
26
|
value: any;
|
|
22
27
|
context: TContext;
|
|
@@ -52,7 +57,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
52
57
|
* Whether the service is started.
|
|
53
58
|
*/
|
|
54
59
|
initialized: boolean;
|
|
55
|
-
|
|
60
|
+
status: InterpreterStatus;
|
|
56
61
|
parent?: Interpreter<any>;
|
|
57
62
|
id: string;
|
|
58
63
|
/**
|
|
@@ -177,7 +182,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
177
182
|
id: string;
|
|
178
183
|
};
|
|
179
184
|
}
|
|
180
|
-
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions):
|
|
185
|
+
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): Actor<State<TC, TE>, TE>;
|
|
181
186
|
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): Actor;
|
|
182
187
|
/**
|
|
183
188
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|