xstate 5.13.2 → 5.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/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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.js +18 -15
- package/actors/dist/xstate-actors.development.cjs.js +18 -15
- package/actors/dist/xstate-actors.development.esm.js +18 -15
- package/actors/dist/xstate-actors.esm.js +18 -15
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/actors/callback.d.ts +4 -3
- package/dist/declarations/src/actors/observable.d.ts +9 -7
- package/dist/declarations/src/actors/promise.d.ts +5 -4
- package/dist/declarations/src/actors/transition.d.ts +1 -1
- package/dist/declarations/src/system.d.ts +2 -2
- package/dist/declarations/src/types.d.ts +7 -4
- package/dist/{log-d06dd00b.development.cjs.js → log-505687fd.development.cjs.js} +1 -1
- package/dist/{log-5b14d850.cjs.js → log-7ae0ddf8.cjs.js} +1 -1
- package/dist/{log-c447a931.esm.js → log-b87cb6bd.esm.js} +1 -1
- package/dist/{log-b3b03961.development.esm.js → log-c943e6aa.development.esm.js} +1 -1
- package/dist/{raise-bf7a8462.development.cjs.js → raise-0cd7e521.development.cjs.js} +138 -130
- package/dist/{raise-150d5679.development.esm.js → raise-0f400094.development.esm.js} +138 -130
- package/dist/{raise-f406edbd.esm.js → raise-4e39e875.esm.js} +138 -130
- package/dist/{raise-ff8990f7.cjs.js → raise-f79d2832.cjs.js} +138 -130
- package/dist/xstate.cjs.js +2 -2
- package/dist/xstate.development.cjs.js +2 -2
- package/dist/xstate.development.esm.js +4 -4
- package/dist/xstate.esm.js +4 -4
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-0cd7e521.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
6
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-f79d2832.cjs.js');
|
|
4
4
|
|
|
5
5
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
6
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-4e39e875.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-0f400094.development.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -97,13 +97,15 @@ function createDoneStateEvent(id, output) {
|
|
|
97
97
|
function createDoneActorEvent(invokeId, output) {
|
|
98
98
|
return {
|
|
99
99
|
type: `xstate.done.actor.${invokeId}`,
|
|
100
|
-
output
|
|
100
|
+
output,
|
|
101
|
+
actorId: invokeId
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
104
|
function createErrorActorEvent(id, error) {
|
|
104
105
|
return {
|
|
105
106
|
type: `xstate.error.actor.${id}`,
|
|
106
|
-
error
|
|
107
|
+
error,
|
|
108
|
+
actorId: id
|
|
107
109
|
};
|
|
108
110
|
}
|
|
109
111
|
function createInitEvent(input) {
|
|
@@ -128,134 +130,6 @@ function reportUnhandledError(err) {
|
|
|
128
130
|
|
|
129
131
|
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
130
132
|
|
|
131
|
-
function createScheduledEventId(actorRef, id) {
|
|
132
|
-
return `${actorRef.sessionId}.${id}`;
|
|
133
|
-
}
|
|
134
|
-
let idCounter = 0;
|
|
135
|
-
function createSystem(rootActor, options) {
|
|
136
|
-
const children = new Map();
|
|
137
|
-
const keyedActors = new Map();
|
|
138
|
-
const reverseKeyedActors = new WeakMap();
|
|
139
|
-
const inspectionObservers = new Set();
|
|
140
|
-
const timerMap = {};
|
|
141
|
-
const {
|
|
142
|
-
clock,
|
|
143
|
-
logger
|
|
144
|
-
} = options;
|
|
145
|
-
const scheduler = {
|
|
146
|
-
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
147
|
-
const scheduledEvent = {
|
|
148
|
-
source,
|
|
149
|
-
target,
|
|
150
|
-
event,
|
|
151
|
-
delay,
|
|
152
|
-
id,
|
|
153
|
-
startedAt: Date.now()
|
|
154
|
-
};
|
|
155
|
-
const scheduledEventId = createScheduledEventId(source, id);
|
|
156
|
-
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
157
|
-
const timeout = clock.setTimeout(() => {
|
|
158
|
-
delete timerMap[scheduledEventId];
|
|
159
|
-
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
160
|
-
system._relay(source, target, event);
|
|
161
|
-
}, delay);
|
|
162
|
-
timerMap[scheduledEventId] = timeout;
|
|
163
|
-
},
|
|
164
|
-
cancel: (source, id) => {
|
|
165
|
-
const scheduledEventId = createScheduledEventId(source, id);
|
|
166
|
-
const timeout = timerMap[scheduledEventId];
|
|
167
|
-
delete timerMap[scheduledEventId];
|
|
168
|
-
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
169
|
-
clock.clearTimeout(timeout);
|
|
170
|
-
},
|
|
171
|
-
cancelAll: actorRef => {
|
|
172
|
-
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
173
|
-
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
174
|
-
if (scheduledEvent.source === actorRef) {
|
|
175
|
-
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
const sendInspectionEvent = event => {
|
|
181
|
-
if (!inspectionObservers.size) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const resolvedInspectionEvent = {
|
|
185
|
-
...event,
|
|
186
|
-
rootId: rootActor.sessionId
|
|
187
|
-
};
|
|
188
|
-
inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
189
|
-
};
|
|
190
|
-
const system = {
|
|
191
|
-
_snapshot: {
|
|
192
|
-
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
193
|
-
},
|
|
194
|
-
_bookId: () => `x:${idCounter++}`,
|
|
195
|
-
_register: (sessionId, actorRef) => {
|
|
196
|
-
children.set(sessionId, actorRef);
|
|
197
|
-
return sessionId;
|
|
198
|
-
},
|
|
199
|
-
_unregister: actorRef => {
|
|
200
|
-
children.delete(actorRef.sessionId);
|
|
201
|
-
const systemId = reverseKeyedActors.get(actorRef);
|
|
202
|
-
if (systemId !== undefined) {
|
|
203
|
-
keyedActors.delete(systemId);
|
|
204
|
-
reverseKeyedActors.delete(actorRef);
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
get: systemId => {
|
|
208
|
-
return keyedActors.get(systemId);
|
|
209
|
-
},
|
|
210
|
-
_set: (systemId, actorRef) => {
|
|
211
|
-
const existing = keyedActors.get(systemId);
|
|
212
|
-
if (existing && existing !== actorRef) {
|
|
213
|
-
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
214
|
-
}
|
|
215
|
-
keyedActors.set(systemId, actorRef);
|
|
216
|
-
reverseKeyedActors.set(actorRef, systemId);
|
|
217
|
-
},
|
|
218
|
-
inspect: observer => {
|
|
219
|
-
inspectionObservers.add(observer);
|
|
220
|
-
},
|
|
221
|
-
_sendInspectionEvent: sendInspectionEvent,
|
|
222
|
-
_relay: (source, target, event) => {
|
|
223
|
-
system._sendInspectionEvent({
|
|
224
|
-
type: '@xstate.event',
|
|
225
|
-
sourceRef: source,
|
|
226
|
-
actorRef: target,
|
|
227
|
-
event
|
|
228
|
-
});
|
|
229
|
-
target._send(event);
|
|
230
|
-
},
|
|
231
|
-
scheduler,
|
|
232
|
-
getSnapshot: () => {
|
|
233
|
-
return {
|
|
234
|
-
_scheduledEvents: {
|
|
235
|
-
...system._snapshot._scheduledEvents
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
start: () => {
|
|
240
|
-
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
241
|
-
system._snapshot._scheduledEvents = {};
|
|
242
|
-
for (const scheduledId in scheduledEvents) {
|
|
243
|
-
const {
|
|
244
|
-
source,
|
|
245
|
-
target,
|
|
246
|
-
event,
|
|
247
|
-
delay,
|
|
248
|
-
id
|
|
249
|
-
} = scheduledEvents[scheduledId];
|
|
250
|
-
scheduler.schedule(source, target, event, delay, id);
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
_clock: clock,
|
|
254
|
-
_logger: logger
|
|
255
|
-
};
|
|
256
|
-
return system;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
133
|
function matchesState(parentStateId, childStateId) {
|
|
260
134
|
const parentStateValue = toStateValue(parentStateId);
|
|
261
135
|
const childStateValue = toStateValue(childStateId);
|
|
@@ -413,6 +287,140 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
413
287
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
414
288
|
}
|
|
415
289
|
|
|
290
|
+
function createScheduledEventId(actorRef, id) {
|
|
291
|
+
return `${actorRef.sessionId}.${id}`;
|
|
292
|
+
}
|
|
293
|
+
let idCounter = 0;
|
|
294
|
+
function createSystem(rootActor, options) {
|
|
295
|
+
const children = new Map();
|
|
296
|
+
const keyedActors = new Map();
|
|
297
|
+
const reverseKeyedActors = new WeakMap();
|
|
298
|
+
const inspectionObservers = new Set();
|
|
299
|
+
const timerMap = {};
|
|
300
|
+
const {
|
|
301
|
+
clock,
|
|
302
|
+
logger
|
|
303
|
+
} = options;
|
|
304
|
+
const scheduler = {
|
|
305
|
+
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
306
|
+
const scheduledEvent = {
|
|
307
|
+
source,
|
|
308
|
+
target,
|
|
309
|
+
event,
|
|
310
|
+
delay,
|
|
311
|
+
id,
|
|
312
|
+
startedAt: Date.now()
|
|
313
|
+
};
|
|
314
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
315
|
+
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
316
|
+
const timeout = clock.setTimeout(() => {
|
|
317
|
+
delete timerMap[scheduledEventId];
|
|
318
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
319
|
+
system._relay(source, target, event);
|
|
320
|
+
}, delay);
|
|
321
|
+
timerMap[scheduledEventId] = timeout;
|
|
322
|
+
},
|
|
323
|
+
cancel: (source, id) => {
|
|
324
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
325
|
+
const timeout = timerMap[scheduledEventId];
|
|
326
|
+
delete timerMap[scheduledEventId];
|
|
327
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
328
|
+
clock.clearTimeout(timeout);
|
|
329
|
+
},
|
|
330
|
+
cancelAll: actorRef => {
|
|
331
|
+
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
332
|
+
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
333
|
+
if (scheduledEvent.source === actorRef) {
|
|
334
|
+
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const sendInspectionEvent = event => {
|
|
340
|
+
if (!inspectionObservers.size) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const resolvedInspectionEvent = {
|
|
344
|
+
...event,
|
|
345
|
+
rootId: rootActor.sessionId
|
|
346
|
+
};
|
|
347
|
+
inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
348
|
+
};
|
|
349
|
+
const system = {
|
|
350
|
+
_snapshot: {
|
|
351
|
+
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
352
|
+
},
|
|
353
|
+
_bookId: () => `x:${idCounter++}`,
|
|
354
|
+
_register: (sessionId, actorRef) => {
|
|
355
|
+
children.set(sessionId, actorRef);
|
|
356
|
+
return sessionId;
|
|
357
|
+
},
|
|
358
|
+
_unregister: actorRef => {
|
|
359
|
+
children.delete(actorRef.sessionId);
|
|
360
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
361
|
+
if (systemId !== undefined) {
|
|
362
|
+
keyedActors.delete(systemId);
|
|
363
|
+
reverseKeyedActors.delete(actorRef);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
get: systemId => {
|
|
367
|
+
return keyedActors.get(systemId);
|
|
368
|
+
},
|
|
369
|
+
_set: (systemId, actorRef) => {
|
|
370
|
+
const existing = keyedActors.get(systemId);
|
|
371
|
+
if (existing && existing !== actorRef) {
|
|
372
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
373
|
+
}
|
|
374
|
+
keyedActors.set(systemId, actorRef);
|
|
375
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
376
|
+
},
|
|
377
|
+
inspect: observerOrFn => {
|
|
378
|
+
const observer = toObserver(observerOrFn);
|
|
379
|
+
inspectionObservers.add(observer);
|
|
380
|
+
return {
|
|
381
|
+
unsubscribe() {
|
|
382
|
+
inspectionObservers.delete(observer);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
_sendInspectionEvent: sendInspectionEvent,
|
|
387
|
+
_relay: (source, target, event) => {
|
|
388
|
+
system._sendInspectionEvent({
|
|
389
|
+
type: '@xstate.event',
|
|
390
|
+
sourceRef: source,
|
|
391
|
+
actorRef: target,
|
|
392
|
+
event
|
|
393
|
+
});
|
|
394
|
+
target._send(event);
|
|
395
|
+
},
|
|
396
|
+
scheduler,
|
|
397
|
+
getSnapshot: () => {
|
|
398
|
+
return {
|
|
399
|
+
_scheduledEvents: {
|
|
400
|
+
...system._snapshot._scheduledEvents
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
start: () => {
|
|
405
|
+
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
406
|
+
system._snapshot._scheduledEvents = {};
|
|
407
|
+
for (const scheduledId in scheduledEvents) {
|
|
408
|
+
const {
|
|
409
|
+
source,
|
|
410
|
+
target,
|
|
411
|
+
event,
|
|
412
|
+
delay,
|
|
413
|
+
id
|
|
414
|
+
} = scheduledEvents[scheduledId];
|
|
415
|
+
scheduler.schedule(source, target, event, delay, id);
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
_clock: clock,
|
|
419
|
+
_logger: logger
|
|
420
|
+
};
|
|
421
|
+
return system;
|
|
422
|
+
}
|
|
423
|
+
|
|
416
424
|
const $$ACTOR_TYPE = 1;
|
|
417
425
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
418
426
|
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
@@ -95,13 +95,15 @@ function createDoneStateEvent(id, output) {
|
|
|
95
95
|
function createDoneActorEvent(invokeId, output) {
|
|
96
96
|
return {
|
|
97
97
|
type: `xstate.done.actor.${invokeId}`,
|
|
98
|
-
output
|
|
98
|
+
output,
|
|
99
|
+
actorId: invokeId
|
|
99
100
|
};
|
|
100
101
|
}
|
|
101
102
|
function createErrorActorEvent(id, error) {
|
|
102
103
|
return {
|
|
103
104
|
type: `xstate.error.actor.${id}`,
|
|
104
|
-
error
|
|
105
|
+
error,
|
|
106
|
+
actorId: id
|
|
105
107
|
};
|
|
106
108
|
}
|
|
107
109
|
function createInitEvent(input) {
|
|
@@ -126,134 +128,6 @@ function reportUnhandledError(err) {
|
|
|
126
128
|
|
|
127
129
|
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
128
130
|
|
|
129
|
-
function createScheduledEventId(actorRef, id) {
|
|
130
|
-
return `${actorRef.sessionId}.${id}`;
|
|
131
|
-
}
|
|
132
|
-
let idCounter = 0;
|
|
133
|
-
function createSystem(rootActor, options) {
|
|
134
|
-
const children = new Map();
|
|
135
|
-
const keyedActors = new Map();
|
|
136
|
-
const reverseKeyedActors = new WeakMap();
|
|
137
|
-
const inspectionObservers = new Set();
|
|
138
|
-
const timerMap = {};
|
|
139
|
-
const {
|
|
140
|
-
clock,
|
|
141
|
-
logger
|
|
142
|
-
} = options;
|
|
143
|
-
const scheduler = {
|
|
144
|
-
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
145
|
-
const scheduledEvent = {
|
|
146
|
-
source,
|
|
147
|
-
target,
|
|
148
|
-
event,
|
|
149
|
-
delay,
|
|
150
|
-
id,
|
|
151
|
-
startedAt: Date.now()
|
|
152
|
-
};
|
|
153
|
-
const scheduledEventId = createScheduledEventId(source, id);
|
|
154
|
-
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
155
|
-
const timeout = clock.setTimeout(() => {
|
|
156
|
-
delete timerMap[scheduledEventId];
|
|
157
|
-
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
158
|
-
system._relay(source, target, event);
|
|
159
|
-
}, delay);
|
|
160
|
-
timerMap[scheduledEventId] = timeout;
|
|
161
|
-
},
|
|
162
|
-
cancel: (source, id) => {
|
|
163
|
-
const scheduledEventId = createScheduledEventId(source, id);
|
|
164
|
-
const timeout = timerMap[scheduledEventId];
|
|
165
|
-
delete timerMap[scheduledEventId];
|
|
166
|
-
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
167
|
-
clock.clearTimeout(timeout);
|
|
168
|
-
},
|
|
169
|
-
cancelAll: actorRef => {
|
|
170
|
-
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
171
|
-
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
172
|
-
if (scheduledEvent.source === actorRef) {
|
|
173
|
-
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const sendInspectionEvent = event => {
|
|
179
|
-
if (!inspectionObservers.size) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const resolvedInspectionEvent = {
|
|
183
|
-
...event,
|
|
184
|
-
rootId: rootActor.sessionId
|
|
185
|
-
};
|
|
186
|
-
inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
187
|
-
};
|
|
188
|
-
const system = {
|
|
189
|
-
_snapshot: {
|
|
190
|
-
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
191
|
-
},
|
|
192
|
-
_bookId: () => `x:${idCounter++}`,
|
|
193
|
-
_register: (sessionId, actorRef) => {
|
|
194
|
-
children.set(sessionId, actorRef);
|
|
195
|
-
return sessionId;
|
|
196
|
-
},
|
|
197
|
-
_unregister: actorRef => {
|
|
198
|
-
children.delete(actorRef.sessionId);
|
|
199
|
-
const systemId = reverseKeyedActors.get(actorRef);
|
|
200
|
-
if (systemId !== undefined) {
|
|
201
|
-
keyedActors.delete(systemId);
|
|
202
|
-
reverseKeyedActors.delete(actorRef);
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
get: systemId => {
|
|
206
|
-
return keyedActors.get(systemId);
|
|
207
|
-
},
|
|
208
|
-
_set: (systemId, actorRef) => {
|
|
209
|
-
const existing = keyedActors.get(systemId);
|
|
210
|
-
if (existing && existing !== actorRef) {
|
|
211
|
-
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
212
|
-
}
|
|
213
|
-
keyedActors.set(systemId, actorRef);
|
|
214
|
-
reverseKeyedActors.set(actorRef, systemId);
|
|
215
|
-
},
|
|
216
|
-
inspect: observer => {
|
|
217
|
-
inspectionObservers.add(observer);
|
|
218
|
-
},
|
|
219
|
-
_sendInspectionEvent: sendInspectionEvent,
|
|
220
|
-
_relay: (source, target, event) => {
|
|
221
|
-
system._sendInspectionEvent({
|
|
222
|
-
type: '@xstate.event',
|
|
223
|
-
sourceRef: source,
|
|
224
|
-
actorRef: target,
|
|
225
|
-
event
|
|
226
|
-
});
|
|
227
|
-
target._send(event);
|
|
228
|
-
},
|
|
229
|
-
scheduler,
|
|
230
|
-
getSnapshot: () => {
|
|
231
|
-
return {
|
|
232
|
-
_scheduledEvents: {
|
|
233
|
-
...system._snapshot._scheduledEvents
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
},
|
|
237
|
-
start: () => {
|
|
238
|
-
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
239
|
-
system._snapshot._scheduledEvents = {};
|
|
240
|
-
for (const scheduledId in scheduledEvents) {
|
|
241
|
-
const {
|
|
242
|
-
source,
|
|
243
|
-
target,
|
|
244
|
-
event,
|
|
245
|
-
delay,
|
|
246
|
-
id
|
|
247
|
-
} = scheduledEvents[scheduledId];
|
|
248
|
-
scheduler.schedule(source, target, event, delay, id);
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
_clock: clock,
|
|
252
|
-
_logger: logger
|
|
253
|
-
};
|
|
254
|
-
return system;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
131
|
function matchesState(parentStateId, childStateId) {
|
|
258
132
|
const parentStateValue = toStateValue(parentStateId);
|
|
259
133
|
const childStateValue = toStateValue(childStateId);
|
|
@@ -411,6 +285,140 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
411
285
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
412
286
|
}
|
|
413
287
|
|
|
288
|
+
function createScheduledEventId(actorRef, id) {
|
|
289
|
+
return `${actorRef.sessionId}.${id}`;
|
|
290
|
+
}
|
|
291
|
+
let idCounter = 0;
|
|
292
|
+
function createSystem(rootActor, options) {
|
|
293
|
+
const children = new Map();
|
|
294
|
+
const keyedActors = new Map();
|
|
295
|
+
const reverseKeyedActors = new WeakMap();
|
|
296
|
+
const inspectionObservers = new Set();
|
|
297
|
+
const timerMap = {};
|
|
298
|
+
const {
|
|
299
|
+
clock,
|
|
300
|
+
logger
|
|
301
|
+
} = options;
|
|
302
|
+
const scheduler = {
|
|
303
|
+
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
304
|
+
const scheduledEvent = {
|
|
305
|
+
source,
|
|
306
|
+
target,
|
|
307
|
+
event,
|
|
308
|
+
delay,
|
|
309
|
+
id,
|
|
310
|
+
startedAt: Date.now()
|
|
311
|
+
};
|
|
312
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
313
|
+
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
314
|
+
const timeout = clock.setTimeout(() => {
|
|
315
|
+
delete timerMap[scheduledEventId];
|
|
316
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
317
|
+
system._relay(source, target, event);
|
|
318
|
+
}, delay);
|
|
319
|
+
timerMap[scheduledEventId] = timeout;
|
|
320
|
+
},
|
|
321
|
+
cancel: (source, id) => {
|
|
322
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
323
|
+
const timeout = timerMap[scheduledEventId];
|
|
324
|
+
delete timerMap[scheduledEventId];
|
|
325
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
326
|
+
clock.clearTimeout(timeout);
|
|
327
|
+
},
|
|
328
|
+
cancelAll: actorRef => {
|
|
329
|
+
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
330
|
+
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
331
|
+
if (scheduledEvent.source === actorRef) {
|
|
332
|
+
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const sendInspectionEvent = event => {
|
|
338
|
+
if (!inspectionObservers.size) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const resolvedInspectionEvent = {
|
|
342
|
+
...event,
|
|
343
|
+
rootId: rootActor.sessionId
|
|
344
|
+
};
|
|
345
|
+
inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
346
|
+
};
|
|
347
|
+
const system = {
|
|
348
|
+
_snapshot: {
|
|
349
|
+
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
350
|
+
},
|
|
351
|
+
_bookId: () => `x:${idCounter++}`,
|
|
352
|
+
_register: (sessionId, actorRef) => {
|
|
353
|
+
children.set(sessionId, actorRef);
|
|
354
|
+
return sessionId;
|
|
355
|
+
},
|
|
356
|
+
_unregister: actorRef => {
|
|
357
|
+
children.delete(actorRef.sessionId);
|
|
358
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
359
|
+
if (systemId !== undefined) {
|
|
360
|
+
keyedActors.delete(systemId);
|
|
361
|
+
reverseKeyedActors.delete(actorRef);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
get: systemId => {
|
|
365
|
+
return keyedActors.get(systemId);
|
|
366
|
+
},
|
|
367
|
+
_set: (systemId, actorRef) => {
|
|
368
|
+
const existing = keyedActors.get(systemId);
|
|
369
|
+
if (existing && existing !== actorRef) {
|
|
370
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
371
|
+
}
|
|
372
|
+
keyedActors.set(systemId, actorRef);
|
|
373
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
374
|
+
},
|
|
375
|
+
inspect: observerOrFn => {
|
|
376
|
+
const observer = toObserver(observerOrFn);
|
|
377
|
+
inspectionObservers.add(observer);
|
|
378
|
+
return {
|
|
379
|
+
unsubscribe() {
|
|
380
|
+
inspectionObservers.delete(observer);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
},
|
|
384
|
+
_sendInspectionEvent: sendInspectionEvent,
|
|
385
|
+
_relay: (source, target, event) => {
|
|
386
|
+
system._sendInspectionEvent({
|
|
387
|
+
type: '@xstate.event',
|
|
388
|
+
sourceRef: source,
|
|
389
|
+
actorRef: target,
|
|
390
|
+
event
|
|
391
|
+
});
|
|
392
|
+
target._send(event);
|
|
393
|
+
},
|
|
394
|
+
scheduler,
|
|
395
|
+
getSnapshot: () => {
|
|
396
|
+
return {
|
|
397
|
+
_scheduledEvents: {
|
|
398
|
+
...system._snapshot._scheduledEvents
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
},
|
|
402
|
+
start: () => {
|
|
403
|
+
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
404
|
+
system._snapshot._scheduledEvents = {};
|
|
405
|
+
for (const scheduledId in scheduledEvents) {
|
|
406
|
+
const {
|
|
407
|
+
source,
|
|
408
|
+
target,
|
|
409
|
+
event,
|
|
410
|
+
delay,
|
|
411
|
+
id
|
|
412
|
+
} = scheduledEvents[scheduledId];
|
|
413
|
+
scheduler.schedule(source, target, event, delay, id);
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
_clock: clock,
|
|
417
|
+
_logger: logger
|
|
418
|
+
};
|
|
419
|
+
return system;
|
|
420
|
+
}
|
|
421
|
+
|
|
414
422
|
const $$ACTOR_TYPE = 1;
|
|
415
423
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
416
424
|
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|