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
|
@@ -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);
|
|
@@ -408,6 +282,140 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
408
282
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
409
283
|
}
|
|
410
284
|
|
|
285
|
+
function createScheduledEventId(actorRef, id) {
|
|
286
|
+
return `${actorRef.sessionId}.${id}`;
|
|
287
|
+
}
|
|
288
|
+
let idCounter = 0;
|
|
289
|
+
function createSystem(rootActor, options) {
|
|
290
|
+
const children = new Map();
|
|
291
|
+
const keyedActors = new Map();
|
|
292
|
+
const reverseKeyedActors = new WeakMap();
|
|
293
|
+
const inspectionObservers = new Set();
|
|
294
|
+
const timerMap = {};
|
|
295
|
+
const {
|
|
296
|
+
clock,
|
|
297
|
+
logger
|
|
298
|
+
} = options;
|
|
299
|
+
const scheduler = {
|
|
300
|
+
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
301
|
+
const scheduledEvent = {
|
|
302
|
+
source,
|
|
303
|
+
target,
|
|
304
|
+
event,
|
|
305
|
+
delay,
|
|
306
|
+
id,
|
|
307
|
+
startedAt: Date.now()
|
|
308
|
+
};
|
|
309
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
310
|
+
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
311
|
+
const timeout = clock.setTimeout(() => {
|
|
312
|
+
delete timerMap[scheduledEventId];
|
|
313
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
314
|
+
system._relay(source, target, event);
|
|
315
|
+
}, delay);
|
|
316
|
+
timerMap[scheduledEventId] = timeout;
|
|
317
|
+
},
|
|
318
|
+
cancel: (source, id) => {
|
|
319
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
320
|
+
const timeout = timerMap[scheduledEventId];
|
|
321
|
+
delete timerMap[scheduledEventId];
|
|
322
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
323
|
+
clock.clearTimeout(timeout);
|
|
324
|
+
},
|
|
325
|
+
cancelAll: actorRef => {
|
|
326
|
+
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
327
|
+
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
328
|
+
if (scheduledEvent.source === actorRef) {
|
|
329
|
+
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const sendInspectionEvent = event => {
|
|
335
|
+
if (!inspectionObservers.size) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const resolvedInspectionEvent = {
|
|
339
|
+
...event,
|
|
340
|
+
rootId: rootActor.sessionId
|
|
341
|
+
};
|
|
342
|
+
inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
343
|
+
};
|
|
344
|
+
const system = {
|
|
345
|
+
_snapshot: {
|
|
346
|
+
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
347
|
+
},
|
|
348
|
+
_bookId: () => `x:${idCounter++}`,
|
|
349
|
+
_register: (sessionId, actorRef) => {
|
|
350
|
+
children.set(sessionId, actorRef);
|
|
351
|
+
return sessionId;
|
|
352
|
+
},
|
|
353
|
+
_unregister: actorRef => {
|
|
354
|
+
children.delete(actorRef.sessionId);
|
|
355
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
356
|
+
if (systemId !== undefined) {
|
|
357
|
+
keyedActors.delete(systemId);
|
|
358
|
+
reverseKeyedActors.delete(actorRef);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
get: systemId => {
|
|
362
|
+
return keyedActors.get(systemId);
|
|
363
|
+
},
|
|
364
|
+
_set: (systemId, actorRef) => {
|
|
365
|
+
const existing = keyedActors.get(systemId);
|
|
366
|
+
if (existing && existing !== actorRef) {
|
|
367
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
368
|
+
}
|
|
369
|
+
keyedActors.set(systemId, actorRef);
|
|
370
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
371
|
+
},
|
|
372
|
+
inspect: observerOrFn => {
|
|
373
|
+
const observer = toObserver(observerOrFn);
|
|
374
|
+
inspectionObservers.add(observer);
|
|
375
|
+
return {
|
|
376
|
+
unsubscribe() {
|
|
377
|
+
inspectionObservers.delete(observer);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
},
|
|
381
|
+
_sendInspectionEvent: sendInspectionEvent,
|
|
382
|
+
_relay: (source, target, event) => {
|
|
383
|
+
system._sendInspectionEvent({
|
|
384
|
+
type: '@xstate.event',
|
|
385
|
+
sourceRef: source,
|
|
386
|
+
actorRef: target,
|
|
387
|
+
event
|
|
388
|
+
});
|
|
389
|
+
target._send(event);
|
|
390
|
+
},
|
|
391
|
+
scheduler,
|
|
392
|
+
getSnapshot: () => {
|
|
393
|
+
return {
|
|
394
|
+
_scheduledEvents: {
|
|
395
|
+
...system._snapshot._scheduledEvents
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
},
|
|
399
|
+
start: () => {
|
|
400
|
+
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
401
|
+
system._snapshot._scheduledEvents = {};
|
|
402
|
+
for (const scheduledId in scheduledEvents) {
|
|
403
|
+
const {
|
|
404
|
+
source,
|
|
405
|
+
target,
|
|
406
|
+
event,
|
|
407
|
+
delay,
|
|
408
|
+
id
|
|
409
|
+
} = scheduledEvents[scheduledId];
|
|
410
|
+
scheduler.schedule(source, target, event, delay, id);
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
_clock: clock,
|
|
414
|
+
_logger: logger
|
|
415
|
+
};
|
|
416
|
+
return system;
|
|
417
|
+
}
|
|
418
|
+
|
|
411
419
|
const $$ACTOR_TYPE = 1;
|
|
412
420
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
413
421
|
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
@@ -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);
|
|
@@ -410,6 +284,140 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
410
284
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
411
285
|
}
|
|
412
286
|
|
|
287
|
+
function createScheduledEventId(actorRef, id) {
|
|
288
|
+
return `${actorRef.sessionId}.${id}`;
|
|
289
|
+
}
|
|
290
|
+
let idCounter = 0;
|
|
291
|
+
function createSystem(rootActor, options) {
|
|
292
|
+
const children = new Map();
|
|
293
|
+
const keyedActors = new Map();
|
|
294
|
+
const reverseKeyedActors = new WeakMap();
|
|
295
|
+
const inspectionObservers = new Set();
|
|
296
|
+
const timerMap = {};
|
|
297
|
+
const {
|
|
298
|
+
clock,
|
|
299
|
+
logger
|
|
300
|
+
} = options;
|
|
301
|
+
const scheduler = {
|
|
302
|
+
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
303
|
+
const scheduledEvent = {
|
|
304
|
+
source,
|
|
305
|
+
target,
|
|
306
|
+
event,
|
|
307
|
+
delay,
|
|
308
|
+
id,
|
|
309
|
+
startedAt: Date.now()
|
|
310
|
+
};
|
|
311
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
312
|
+
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
313
|
+
const timeout = clock.setTimeout(() => {
|
|
314
|
+
delete timerMap[scheduledEventId];
|
|
315
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
316
|
+
system._relay(source, target, event);
|
|
317
|
+
}, delay);
|
|
318
|
+
timerMap[scheduledEventId] = timeout;
|
|
319
|
+
},
|
|
320
|
+
cancel: (source, id) => {
|
|
321
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
322
|
+
const timeout = timerMap[scheduledEventId];
|
|
323
|
+
delete timerMap[scheduledEventId];
|
|
324
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
325
|
+
clock.clearTimeout(timeout);
|
|
326
|
+
},
|
|
327
|
+
cancelAll: actorRef => {
|
|
328
|
+
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
329
|
+
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
330
|
+
if (scheduledEvent.source === actorRef) {
|
|
331
|
+
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
const sendInspectionEvent = event => {
|
|
337
|
+
if (!inspectionObservers.size) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const resolvedInspectionEvent = {
|
|
341
|
+
...event,
|
|
342
|
+
rootId: rootActor.sessionId
|
|
343
|
+
};
|
|
344
|
+
inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
|
|
345
|
+
};
|
|
346
|
+
const system = {
|
|
347
|
+
_snapshot: {
|
|
348
|
+
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
349
|
+
},
|
|
350
|
+
_bookId: () => `x:${idCounter++}`,
|
|
351
|
+
_register: (sessionId, actorRef) => {
|
|
352
|
+
children.set(sessionId, actorRef);
|
|
353
|
+
return sessionId;
|
|
354
|
+
},
|
|
355
|
+
_unregister: actorRef => {
|
|
356
|
+
children.delete(actorRef.sessionId);
|
|
357
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
358
|
+
if (systemId !== undefined) {
|
|
359
|
+
keyedActors.delete(systemId);
|
|
360
|
+
reverseKeyedActors.delete(actorRef);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
get: systemId => {
|
|
364
|
+
return keyedActors.get(systemId);
|
|
365
|
+
},
|
|
366
|
+
_set: (systemId, actorRef) => {
|
|
367
|
+
const existing = keyedActors.get(systemId);
|
|
368
|
+
if (existing && existing !== actorRef) {
|
|
369
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
370
|
+
}
|
|
371
|
+
keyedActors.set(systemId, actorRef);
|
|
372
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
373
|
+
},
|
|
374
|
+
inspect: observerOrFn => {
|
|
375
|
+
const observer = toObserver(observerOrFn);
|
|
376
|
+
inspectionObservers.add(observer);
|
|
377
|
+
return {
|
|
378
|
+
unsubscribe() {
|
|
379
|
+
inspectionObservers.delete(observer);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
},
|
|
383
|
+
_sendInspectionEvent: sendInspectionEvent,
|
|
384
|
+
_relay: (source, target, event) => {
|
|
385
|
+
system._sendInspectionEvent({
|
|
386
|
+
type: '@xstate.event',
|
|
387
|
+
sourceRef: source,
|
|
388
|
+
actorRef: target,
|
|
389
|
+
event
|
|
390
|
+
});
|
|
391
|
+
target._send(event);
|
|
392
|
+
},
|
|
393
|
+
scheduler,
|
|
394
|
+
getSnapshot: () => {
|
|
395
|
+
return {
|
|
396
|
+
_scheduledEvents: {
|
|
397
|
+
...system._snapshot._scheduledEvents
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
},
|
|
401
|
+
start: () => {
|
|
402
|
+
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
403
|
+
system._snapshot._scheduledEvents = {};
|
|
404
|
+
for (const scheduledId in scheduledEvents) {
|
|
405
|
+
const {
|
|
406
|
+
source,
|
|
407
|
+
target,
|
|
408
|
+
event,
|
|
409
|
+
delay,
|
|
410
|
+
id
|
|
411
|
+
} = scheduledEvents[scheduledId];
|
|
412
|
+
scheduler.schedule(source, target, event, delay, id);
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
_clock: clock,
|
|
416
|
+
_logger: logger
|
|
417
|
+
};
|
|
418
|
+
return system;
|
|
419
|
+
}
|
|
420
|
+
|
|
413
421
|
const $$ACTOR_TYPE = 1;
|
|
414
422
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
415
423
|
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var log = require('./log-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-f79d2832.cjs.js');
|
|
7
|
+
var log = require('./log-7ae0ddf8.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var log = require('./log-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-0cd7e521.development.cjs.js');
|
|
7
|
+
var log = require('./log-505687fd.development.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
3
|
-
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-
|
|
4
|
-
import { a as assign } from './log-
|
|
5
|
-
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-0f400094.development.esm.js';
|
|
3
|
+
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-0f400094.development.esm.js';
|
|
4
|
+
import { a as assign } from './log-c943e6aa.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-c943e6aa.development.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
7
7
|
|
|
8
8
|
class SimulatedClock {
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
3
|
-
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-
|
|
4
|
-
import { a as assign } from './log-
|
|
5
|
-
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-4e39e875.esm.js';
|
|
3
|
+
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-4e39e875.esm.js';
|
|
4
|
+
import { a as assign } from './log-b87cb6bd.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-b87cb6bd.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.esm.js';
|
|
7
7
|
|
|
8
8
|
class SimulatedClock {
|