xstate 6.0.0-alpha.2 → 6.0.0-alpha.3
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/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-0770ac71.development.cjs.js} +1 -1
- package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-8249d511.esm.js} +1 -1
- package/dist/{StateMachine-64813f46.cjs.js → StateMachine-e1048cd6.cjs.js} +1 -1
- package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e6ad61d0.development.esm.js} +1 -1
- package/dist/declarations/src/StateMachine.d.ts +4 -4
- package/dist/declarations/src/createActor.d.ts +0 -2
- package/dist/declarations/src/index.d.ts +1 -3
- package/dist/declarations/src/serialize.d.ts +13 -8
- package/dist/declarations/src/types.d.ts +0 -4
- package/dist/declarations/src/types.v6.d.ts +11 -9
- package/dist/{index-f6ef20d1.development.cjs.js → index-269d256d.development.cjs.js} +10 -689
- package/dist/{index-e61170ba.development.esm.js → index-66ff64a6.development.esm.js} +11 -685
- package/dist/{index-93edd3bd.esm.js → index-a7e3d8b3.esm.js} +11 -685
- package/dist/{index-9cb3b3a0.cjs.js → index-dda021d5.cjs.js} +10 -689
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +85 -32
- package/dist/xstate.cjs.mjs +0 -5
- package/dist/xstate.development.cjs.js +85 -32
- package/dist/xstate.development.cjs.mjs +0 -5
- package/dist/xstate.development.esm.js +87 -29
- package/dist/xstate.esm.js +87 -29
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/atom.d.ts +0 -81
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reactivity interop between actors and atoms.
|
|
3
|
-
*
|
|
4
|
-
* `Actor#get()` calls this hook (when installed) so that computed atoms can
|
|
5
|
-
* track actor reads as dependencies. The hook is installed by `atom.ts` on
|
|
6
|
-
* module evaluation, which only happens when atoms are actually used — apps
|
|
7
|
-
* that never import atoms don't bundle the reactive system.
|
|
8
|
-
*/
|
|
9
|
-
let onActorRead;
|
|
10
|
-
function installActorReadHook(hook) {
|
|
11
|
-
onActorRead = hook;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
1
|
class Mailbox {
|
|
15
2
|
constructor(_process) {
|
|
16
3
|
this._process = _process;
|
|
@@ -203,10 +190,9 @@ function createAttachedLogic(attach) {
|
|
|
203
190
|
self,
|
|
204
191
|
system
|
|
205
192
|
}) => {
|
|
206
|
-
// Don't attach if the target doesn't exist
|
|
207
|
-
// Atoms have no `getSnapshot` / lifecycle, so they always attach.
|
|
193
|
+
// Don't attach if the target doesn't exist or is stopped.
|
|
208
194
|
const target = state.input.actor;
|
|
209
|
-
if (!target ||
|
|
195
|
+
if (!target || target.getSnapshot().status === 'stopped') {
|
|
210
196
|
return;
|
|
211
197
|
}
|
|
212
198
|
const subscription = attach(state.input, {
|
|
@@ -308,620 +294,6 @@ function createListenerLogic() {
|
|
|
308
294
|
// Singleton logic instance
|
|
309
295
|
const listenerLogic = /* #__PURE__ */createListenerLogic();
|
|
310
296
|
|
|
311
|
-
/* eslint-disable */
|
|
312
|
-
// Adapted from Alien Signals
|
|
313
|
-
// https://github.com/stackblitz/alien-signals/
|
|
314
|
-
|
|
315
|
-
let ReactiveFlags = /*#__PURE__*/function (ReactiveFlags) {
|
|
316
|
-
ReactiveFlags[ReactiveFlags["None"] = 0] = "None";
|
|
317
|
-
ReactiveFlags[ReactiveFlags["Mutable"] = 1] = "Mutable";
|
|
318
|
-
ReactiveFlags[ReactiveFlags["Watching"] = 2] = "Watching";
|
|
319
|
-
ReactiveFlags[ReactiveFlags["RecursedCheck"] = 4] = "RecursedCheck";
|
|
320
|
-
ReactiveFlags[ReactiveFlags["Recursed"] = 8] = "Recursed";
|
|
321
|
-
ReactiveFlags[ReactiveFlags["Dirty"] = 16] = "Dirty";
|
|
322
|
-
ReactiveFlags[ReactiveFlags["Pending"] = 32] = "Pending";
|
|
323
|
-
return ReactiveFlags;
|
|
324
|
-
}({});
|
|
325
|
-
function createReactiveSystem({
|
|
326
|
-
update,
|
|
327
|
-
notify,
|
|
328
|
-
unwatched
|
|
329
|
-
}) {
|
|
330
|
-
return {
|
|
331
|
-
link,
|
|
332
|
-
unlink,
|
|
333
|
-
propagate,
|
|
334
|
-
checkDirty,
|
|
335
|
-
shallowPropagate
|
|
336
|
-
};
|
|
337
|
-
function link(dep, sub, version) {
|
|
338
|
-
const prevDep = sub.depsTail;
|
|
339
|
-
if (prevDep !== undefined && prevDep.dep === dep) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
const nextDep = prevDep !== undefined ? prevDep.nextDep : sub.deps;
|
|
343
|
-
if (nextDep !== undefined && nextDep.dep === dep) {
|
|
344
|
-
nextDep.version = version;
|
|
345
|
-
sub.depsTail = nextDep;
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const prevSub = dep.subsTail;
|
|
349
|
-
if (prevSub !== undefined && prevSub.version === version && prevSub.sub === sub) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const newLink = sub.depsTail = dep.subsTail = {
|
|
353
|
-
version,
|
|
354
|
-
dep,
|
|
355
|
-
sub,
|
|
356
|
-
prevDep,
|
|
357
|
-
nextDep,
|
|
358
|
-
prevSub,
|
|
359
|
-
nextSub: undefined
|
|
360
|
-
};
|
|
361
|
-
if (nextDep !== undefined) {
|
|
362
|
-
nextDep.prevDep = newLink;
|
|
363
|
-
}
|
|
364
|
-
if (prevDep !== undefined) {
|
|
365
|
-
prevDep.nextDep = newLink;
|
|
366
|
-
} else {
|
|
367
|
-
sub.deps = newLink;
|
|
368
|
-
}
|
|
369
|
-
if (prevSub !== undefined) {
|
|
370
|
-
prevSub.nextSub = newLink;
|
|
371
|
-
} else {
|
|
372
|
-
dep.subs = newLink;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
function unlink(link, sub = link.sub) {
|
|
376
|
-
const dep = link.dep;
|
|
377
|
-
const prevDep = link.prevDep;
|
|
378
|
-
const nextDep = link.nextDep;
|
|
379
|
-
const nextSub = link.nextSub;
|
|
380
|
-
const prevSub = link.prevSub;
|
|
381
|
-
if (nextDep !== undefined) {
|
|
382
|
-
nextDep.prevDep = prevDep;
|
|
383
|
-
} else {
|
|
384
|
-
sub.depsTail = prevDep;
|
|
385
|
-
}
|
|
386
|
-
if (prevDep !== undefined) {
|
|
387
|
-
prevDep.nextDep = nextDep;
|
|
388
|
-
} else {
|
|
389
|
-
sub.deps = nextDep;
|
|
390
|
-
}
|
|
391
|
-
if (nextSub !== undefined) {
|
|
392
|
-
nextSub.prevSub = prevSub;
|
|
393
|
-
} else {
|
|
394
|
-
dep.subsTail = prevSub;
|
|
395
|
-
}
|
|
396
|
-
if (prevSub !== undefined) {
|
|
397
|
-
prevSub.nextSub = nextSub;
|
|
398
|
-
} else if ((dep.subs = nextSub) === undefined) {
|
|
399
|
-
unwatched(dep);
|
|
400
|
-
}
|
|
401
|
-
return nextDep;
|
|
402
|
-
}
|
|
403
|
-
function propagate(link) {
|
|
404
|
-
let next = link.nextSub;
|
|
405
|
-
let stack;
|
|
406
|
-
top: do {
|
|
407
|
-
const sub = link.sub;
|
|
408
|
-
let flags = sub.flags;
|
|
409
|
-
if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed | ReactiveFlags.Dirty | ReactiveFlags.Pending))) {
|
|
410
|
-
sub.flags = flags | ReactiveFlags.Pending;
|
|
411
|
-
} else if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed))) {
|
|
412
|
-
flags = ReactiveFlags.None;
|
|
413
|
-
} else if (!(flags & ReactiveFlags.RecursedCheck)) {
|
|
414
|
-
sub.flags = flags & ~ReactiveFlags.Recursed | ReactiveFlags.Pending;
|
|
415
|
-
} else if (!(flags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) && isValidLink(link, sub)) {
|
|
416
|
-
sub.flags = flags | (ReactiveFlags.Recursed | ReactiveFlags.Pending);
|
|
417
|
-
flags &= ReactiveFlags.Mutable;
|
|
418
|
-
} else {
|
|
419
|
-
flags = ReactiveFlags.None;
|
|
420
|
-
}
|
|
421
|
-
if (flags & ReactiveFlags.Watching) {
|
|
422
|
-
notify(sub);
|
|
423
|
-
}
|
|
424
|
-
if (flags & ReactiveFlags.Mutable) {
|
|
425
|
-
const subSubs = sub.subs;
|
|
426
|
-
if (subSubs !== undefined) {
|
|
427
|
-
const nextSub = (link = subSubs).nextSub;
|
|
428
|
-
if (nextSub !== undefined) {
|
|
429
|
-
stack = {
|
|
430
|
-
value: next,
|
|
431
|
-
prev: stack
|
|
432
|
-
};
|
|
433
|
-
next = nextSub;
|
|
434
|
-
}
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if ((link = next) !== undefined) {
|
|
439
|
-
next = link.nextSub;
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
while (stack !== undefined) {
|
|
443
|
-
link = stack.value;
|
|
444
|
-
stack = stack.prev;
|
|
445
|
-
if (link !== undefined) {
|
|
446
|
-
next = link.nextSub;
|
|
447
|
-
continue top;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
break;
|
|
451
|
-
} while (true);
|
|
452
|
-
}
|
|
453
|
-
function checkDirty(link, sub) {
|
|
454
|
-
let stack;
|
|
455
|
-
let checkDepth = 0;
|
|
456
|
-
let dirty = false;
|
|
457
|
-
top: do {
|
|
458
|
-
const dep = link.dep;
|
|
459
|
-
const flags = dep.flags;
|
|
460
|
-
if (sub.flags & ReactiveFlags.Dirty) {
|
|
461
|
-
dirty = true;
|
|
462
|
-
} else if ((flags & (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) === (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) {
|
|
463
|
-
if (update(dep)) {
|
|
464
|
-
const subs = dep.subs;
|
|
465
|
-
if (subs.nextSub !== undefined) {
|
|
466
|
-
shallowPropagate(subs);
|
|
467
|
-
}
|
|
468
|
-
dirty = true;
|
|
469
|
-
}
|
|
470
|
-
} else if ((flags & (ReactiveFlags.Mutable | ReactiveFlags.Pending)) === (ReactiveFlags.Mutable | ReactiveFlags.Pending)) {
|
|
471
|
-
if (link.nextSub !== undefined || link.prevSub !== undefined) {
|
|
472
|
-
stack = {
|
|
473
|
-
value: link,
|
|
474
|
-
prev: stack
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
link = dep.deps;
|
|
478
|
-
sub = dep;
|
|
479
|
-
++checkDepth;
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
if (!dirty) {
|
|
483
|
-
const nextDep = link.nextDep;
|
|
484
|
-
if (nextDep !== undefined) {
|
|
485
|
-
link = nextDep;
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
while (checkDepth--) {
|
|
490
|
-
const firstSub = sub.subs;
|
|
491
|
-
const hasMultipleSubs = firstSub.nextSub !== undefined;
|
|
492
|
-
if (hasMultipleSubs) {
|
|
493
|
-
link = stack.value;
|
|
494
|
-
stack = stack.prev;
|
|
495
|
-
} else {
|
|
496
|
-
link = firstSub;
|
|
497
|
-
}
|
|
498
|
-
if (dirty) {
|
|
499
|
-
if (update(sub)) {
|
|
500
|
-
if (hasMultipleSubs) {
|
|
501
|
-
shallowPropagate(firstSub);
|
|
502
|
-
}
|
|
503
|
-
sub = link.sub;
|
|
504
|
-
continue;
|
|
505
|
-
}
|
|
506
|
-
dirty = false;
|
|
507
|
-
} else {
|
|
508
|
-
sub.flags &= ~ReactiveFlags.Pending;
|
|
509
|
-
}
|
|
510
|
-
sub = link.sub;
|
|
511
|
-
const nextDep = link.nextDep;
|
|
512
|
-
if (nextDep !== undefined) {
|
|
513
|
-
link = nextDep;
|
|
514
|
-
continue top;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
return dirty;
|
|
518
|
-
} while (true);
|
|
519
|
-
}
|
|
520
|
-
function shallowPropagate(link) {
|
|
521
|
-
do {
|
|
522
|
-
const sub = link.sub;
|
|
523
|
-
const flags = sub.flags;
|
|
524
|
-
if ((flags & (ReactiveFlags.Pending | ReactiveFlags.Dirty)) === ReactiveFlags.Pending) {
|
|
525
|
-
sub.flags = flags | ReactiveFlags.Dirty;
|
|
526
|
-
if ((flags & (ReactiveFlags.Watching | ReactiveFlags.RecursedCheck)) === ReactiveFlags.Watching) {
|
|
527
|
-
notify(sub);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
} while ((link = link.nextSub) !== undefined);
|
|
531
|
-
}
|
|
532
|
-
function isValidLink(checkLink, sub) {
|
|
533
|
-
let link = sub.depsTail;
|
|
534
|
-
while (link !== undefined) {
|
|
535
|
-
if (link === checkLink) {
|
|
536
|
-
return true;
|
|
537
|
-
}
|
|
538
|
-
link = link.prevDep;
|
|
539
|
-
}
|
|
540
|
-
return false;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Nominal brand (phantom, compile-time only) marking a value as an XState atom.
|
|
546
|
-
* Real atoms get the runtime brand ({@link $$atom}) in `createAtom`; this type
|
|
547
|
-
* brand keeps atom-only APIs (e.g. `enq.subscribeTo`) from structurally
|
|
548
|
-
* accepting plain readables like `actor.select(...)` that would be dispatched
|
|
549
|
-
* down the non-atom path at runtime.
|
|
550
|
-
*/
|
|
551
|
-
|
|
552
|
-
/** Brand marking an object as an atom, so it can be detected structurally. */
|
|
553
|
-
const $$atom = /* #__PURE__ */Symbol.for('xstate.atom');
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* Returns `true` if the value is an atom (writable, computed, async, or
|
|
557
|
-
* reducer). Lets actor-consuming APIs (e.g. `enq.subscribeTo`) accept atoms
|
|
558
|
-
* directly.
|
|
559
|
-
*/
|
|
560
|
-
function isAtom(value) {
|
|
561
|
-
return !!value && typeof value === 'object' && $$atom in value;
|
|
562
|
-
}
|
|
563
|
-
const queuedEffects = [];
|
|
564
|
-
let cycle = 0;
|
|
565
|
-
// Initialized lazily on first atom creation (instead of at module evaluation)
|
|
566
|
-
// so the reactive system stays tree-shakeable for apps that never use atoms —
|
|
567
|
-
|
|
568
|
-
// would be retained by consumer bundlers even when atoms are unused.
|
|
569
|
-
let link;
|
|
570
|
-
let unlink;
|
|
571
|
-
let propagate;
|
|
572
|
-
let checkDirty;
|
|
573
|
-
let shallowPropagate;
|
|
574
|
-
let reactiveSystemInstalled = false;
|
|
575
|
-
function ensureReactiveSystem() {
|
|
576
|
-
if (reactiveSystemInstalled) {
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
reactiveSystemInstalled = true;
|
|
580
|
-
({
|
|
581
|
-
link,
|
|
582
|
-
unlink,
|
|
583
|
-
propagate,
|
|
584
|
-
checkDirty,
|
|
585
|
-
shallowPropagate
|
|
586
|
-
} = createReactiveSystem({
|
|
587
|
-
update(atom) {
|
|
588
|
-
return atom._update();
|
|
589
|
-
},
|
|
590
|
-
notify(effect) {
|
|
591
|
-
queuedEffects[queuedEffectsLength++] = effect;
|
|
592
|
-
effect.flags &= ~ReactiveFlags.Watching;
|
|
593
|
-
},
|
|
594
|
-
unwatched(atom) {
|
|
595
|
-
if (atom.depsTail !== undefined) {
|
|
596
|
-
atom.depsTail = undefined;
|
|
597
|
-
atom.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty;
|
|
598
|
-
purgeDeps(atom);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}));
|
|
602
|
-
}
|
|
603
|
-
let notifyIndex = 0;
|
|
604
|
-
let queuedEffectsLength = 0;
|
|
605
|
-
let activeSub;
|
|
606
|
-
function purgeDeps(sub) {
|
|
607
|
-
const depsTail = sub.depsTail;
|
|
608
|
-
let dep = depsTail !== undefined ? depsTail.nextDep : sub.deps;
|
|
609
|
-
while (dep !== undefined) {
|
|
610
|
-
dep = unlink(dep, sub);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
function flush() {
|
|
614
|
-
while (notifyIndex < queuedEffectsLength) {
|
|
615
|
-
const effect = queuedEffects[notifyIndex];
|
|
616
|
-
queuedEffects[notifyIndex++] = undefined;
|
|
617
|
-
effect.notify();
|
|
618
|
-
}
|
|
619
|
-
notifyIndex = 0;
|
|
620
|
-
queuedEffectsLength = 0;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/** The current state of an async atom. */
|
|
624
|
-
|
|
625
|
-
/** Options passed to an async atom getter. */
|
|
626
|
-
|
|
627
|
-
function compareAsyncAtomState(a, b) {
|
|
628
|
-
if (a.status !== b.status) {
|
|
629
|
-
return false;
|
|
630
|
-
}
|
|
631
|
-
if (a.status === 'done' && b.status === 'done') {
|
|
632
|
-
return Object.is(a.data, b.data);
|
|
633
|
-
}
|
|
634
|
-
if (a.status === 'error' && b.status === 'error') {
|
|
635
|
-
return Object.is(a.error, b.error);
|
|
636
|
-
}
|
|
637
|
-
// both 'pending'
|
|
638
|
-
return true;
|
|
639
|
-
}
|
|
640
|
-
function updateAsyncAtom(atom, nextValue) {
|
|
641
|
-
if (atom._update(nextValue)) {
|
|
642
|
-
const subs = atom.subs;
|
|
643
|
-
if (subs !== undefined) {
|
|
644
|
-
propagate(subs);
|
|
645
|
-
shallowPropagate(subs);
|
|
646
|
-
flush();
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* Creates a read-only atom whose value is loaded from an async getter.
|
|
653
|
-
*
|
|
654
|
-
* The getter receives an `AbortSignal`; when the async atom recomputes, the
|
|
655
|
-
* previous signal is aborted and stale resolutions are ignored.
|
|
656
|
-
*/
|
|
657
|
-
function createAsyncAtom(getValue, options) {
|
|
658
|
-
const ref = {};
|
|
659
|
-
let currentController;
|
|
660
|
-
let currentRunId = 0;
|
|
661
|
-
const atom = createAtom(() => {
|
|
662
|
-
currentController?.abort();
|
|
663
|
-
const controller = new AbortController();
|
|
664
|
-
const runId = ++currentRunId;
|
|
665
|
-
currentController = controller;
|
|
666
|
-
getValue({
|
|
667
|
-
signal: controller.signal
|
|
668
|
-
}).then(data => {
|
|
669
|
-
if (runId !== currentRunId || controller.signal.aborted) {
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
updateAsyncAtom(ref.current, {
|
|
673
|
-
status: 'done',
|
|
674
|
-
data
|
|
675
|
-
});
|
|
676
|
-
}, error => {
|
|
677
|
-
if (runId !== currentRunId || controller.signal.aborted) {
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
updateAsyncAtom(ref.current, {
|
|
681
|
-
status: 'error',
|
|
682
|
-
error
|
|
683
|
-
});
|
|
684
|
-
});
|
|
685
|
-
return {
|
|
686
|
-
status: 'pending'
|
|
687
|
-
};
|
|
688
|
-
}, {
|
|
689
|
-
compare: compareAsyncAtomState,
|
|
690
|
-
...options
|
|
691
|
-
});
|
|
692
|
-
ref.current = atom;
|
|
693
|
-
return atom;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* Mirror atoms that bump a version whenever a tracked actor emits a snapshot,
|
|
698
|
-
* letting computed atoms depend on `actor.get()` reads.
|
|
699
|
-
*
|
|
700
|
-
* The hook is installed lazily on first atom creation (not at module
|
|
701
|
-
* evaluation) so that it remains tree-shakeable for apps that never use atoms —
|
|
702
|
-
* any tracked read necessarily happens inside an atom computation, so first-use
|
|
703
|
-
* installation is always early enough.
|
|
704
|
-
*/
|
|
705
|
-
let actorInteropInstalled = false;
|
|
706
|
-
function ensureActorInterop() {
|
|
707
|
-
if (actorInteropInstalled) {
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
actorInteropInstalled = true;
|
|
711
|
-
const actorVersions = new WeakMap();
|
|
712
|
-
installActorReadHook(actorRef => {
|
|
713
|
-
if (activeSub === undefined) {
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
let version = actorVersions.get(actorRef);
|
|
717
|
-
if (version === undefined) {
|
|
718
|
-
version = createAtom(0);
|
|
719
|
-
actorVersions.set(actorRef, version);
|
|
720
|
-
actorRef.subscribe({
|
|
721
|
-
next: () => version.set(v => v + 1),
|
|
722
|
-
error: () => {}
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
version.get();
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Creates an atom.
|
|
731
|
-
*
|
|
732
|
-
* Pass a value for a writable atom or a getter for a computed read-only atom.
|
|
733
|
-
*/
|
|
734
|
-
|
|
735
|
-
function createAtom(valueOrFn, optionsOrInput) {
|
|
736
|
-
ensureReactiveSystem();
|
|
737
|
-
ensureActorInterop();
|
|
738
|
-
const isComputed = typeof valueOrFn === 'function';
|
|
739
|
-
const getter = valueOrFn;
|
|
740
|
-
|
|
741
|
-
// Create plain object atom
|
|
742
|
-
const atom = {
|
|
743
|
-
_snapshot: isComputed ? undefined : valueOrFn,
|
|
744
|
-
subs: undefined,
|
|
745
|
-
subsTail: undefined,
|
|
746
|
-
deps: undefined,
|
|
747
|
-
depsTail: undefined,
|
|
748
|
-
flags: isComputed ? ReactiveFlags.None : ReactiveFlags.Mutable,
|
|
749
|
-
get() {
|
|
750
|
-
if (activeSub !== undefined) {
|
|
751
|
-
link(atom, activeSub, cycle);
|
|
752
|
-
}
|
|
753
|
-
return atom._snapshot;
|
|
754
|
-
},
|
|
755
|
-
subscribe(observerOrFn) {
|
|
756
|
-
const observer = typeof observerOrFn === 'function' ? {
|
|
757
|
-
next: observerOrFn
|
|
758
|
-
} : observerOrFn;
|
|
759
|
-
const observed = {
|
|
760
|
-
current: false
|
|
761
|
-
};
|
|
762
|
-
const e = effect(() => {
|
|
763
|
-
atom.get();
|
|
764
|
-
if (!observed.current) {
|
|
765
|
-
observed.current = true;
|
|
766
|
-
} else {
|
|
767
|
-
const prevSub = activeSub;
|
|
768
|
-
activeSub = undefined;
|
|
769
|
-
try {
|
|
770
|
-
observer.next?.(atom._snapshot);
|
|
771
|
-
} catch (err) {
|
|
772
|
-
reportUnhandledError(err);
|
|
773
|
-
} finally {
|
|
774
|
-
activeSub = prevSub;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
// If the observer synchronously updates any of our deps we'll be
|
|
778
|
-
// marked as dirty preventing this effect from re-running. Request
|
|
779
|
-
// the value again to reconcile any dirty deps.
|
|
780
|
-
atom.get();
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
return {
|
|
784
|
-
unsubscribe: () => {
|
|
785
|
-
e.stop();
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
},
|
|
789
|
-
_update(getValue) {
|
|
790
|
-
const prevSub = activeSub;
|
|
791
|
-
const compare = optionsOrInput?.compare ?? Object.is;
|
|
792
|
-
activeSub = atom;
|
|
793
|
-
++cycle;
|
|
794
|
-
atom.depsTail = undefined;
|
|
795
|
-
if (isComputed) {
|
|
796
|
-
atom.flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck;
|
|
797
|
-
}
|
|
798
|
-
try {
|
|
799
|
-
const oldValue = atom._snapshot;
|
|
800
|
-
const newValue = typeof getValue === 'function' ? getValue(oldValue) : getValue === undefined && isComputed ? getter(oldValue) : getValue;
|
|
801
|
-
if (oldValue === undefined || !compare(oldValue, newValue)) {
|
|
802
|
-
atom._snapshot = newValue;
|
|
803
|
-
return true;
|
|
804
|
-
}
|
|
805
|
-
return false;
|
|
806
|
-
} finally {
|
|
807
|
-
activeSub = prevSub;
|
|
808
|
-
if (isComputed) {
|
|
809
|
-
atom.flags &= ~ReactiveFlags.RecursedCheck;
|
|
810
|
-
}
|
|
811
|
-
purgeDeps(atom);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
if (isComputed) {
|
|
816
|
-
atom.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty;
|
|
817
|
-
atom.get = function () {
|
|
818
|
-
const flags = atom.flags;
|
|
819
|
-
if (flags & ReactiveFlags.Dirty || flags & ReactiveFlags.Pending && checkDirty(atom.deps, atom)) {
|
|
820
|
-
if (atom._update()) {
|
|
821
|
-
const subs = atom.subs;
|
|
822
|
-
if (subs !== undefined) {
|
|
823
|
-
shallowPropagate(subs);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
} else if (flags & ReactiveFlags.Pending) {
|
|
827
|
-
atom.flags = flags & ~ReactiveFlags.Pending;
|
|
828
|
-
}
|
|
829
|
-
if (activeSub !== undefined) {
|
|
830
|
-
link(atom, activeSub, cycle);
|
|
831
|
-
}
|
|
832
|
-
return atom._snapshot;
|
|
833
|
-
};
|
|
834
|
-
} else {
|
|
835
|
-
atom.set = function (valueOrFn) {
|
|
836
|
-
if (atom._update(valueOrFn)) {
|
|
837
|
-
const subs = atom.subs;
|
|
838
|
-
if (subs !== undefined) {
|
|
839
|
-
propagate(subs);
|
|
840
|
-
shallowPropagate(subs);
|
|
841
|
-
flush();
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
}
|
|
846
|
-
atom[$$atom] = true;
|
|
847
|
-
return atom;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* Creates an inert atom config that can be instantiated later.
|
|
852
|
-
*
|
|
853
|
-
* Useful for framework hooks that need to create a stable local atom from
|
|
854
|
-
* component input.
|
|
855
|
-
*/
|
|
856
|
-
|
|
857
|
-
function createAtomConfig(initialValueOrFn, options) {
|
|
858
|
-
return {
|
|
859
|
-
createAtom(input) {
|
|
860
|
-
const initialValue = typeof initialValueOrFn === 'function' ? initialValueOrFn(input) : initialValueOrFn;
|
|
861
|
-
return createAtom(initialValue, options);
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
/** Creates an atom whose updates are handled by a reducer function. */
|
|
867
|
-
function createReducerAtom(initialValue, reducer, options) {
|
|
868
|
-
const atom = createAtom(initialValue, options);
|
|
869
|
-
return {
|
|
870
|
-
[$$atom]: true,
|
|
871
|
-
get: atom.get.bind(atom),
|
|
872
|
-
subscribe: atom.subscribe.bind(atom),
|
|
873
|
-
send(event) {
|
|
874
|
-
const prevSub = activeSub;
|
|
875
|
-
activeSub = undefined;
|
|
876
|
-
let nextState;
|
|
877
|
-
try {
|
|
878
|
-
nextState = reducer(atom.get(), event);
|
|
879
|
-
} finally {
|
|
880
|
-
activeSub = prevSub;
|
|
881
|
-
}
|
|
882
|
-
atom.set(nextState);
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
function effect(fn) {
|
|
887
|
-
const run = () => {
|
|
888
|
-
const prevSub = activeSub;
|
|
889
|
-
activeSub = effectObj;
|
|
890
|
-
++cycle;
|
|
891
|
-
effectObj.depsTail = undefined;
|
|
892
|
-
effectObj.flags = ReactiveFlags.Watching | ReactiveFlags.RecursedCheck;
|
|
893
|
-
try {
|
|
894
|
-
return fn();
|
|
895
|
-
} finally {
|
|
896
|
-
activeSub = prevSub;
|
|
897
|
-
effectObj.flags &= ~ReactiveFlags.RecursedCheck;
|
|
898
|
-
purgeDeps(effectObj);
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
const effectObj = {
|
|
902
|
-
deps: undefined,
|
|
903
|
-
depsTail: undefined,
|
|
904
|
-
subs: undefined,
|
|
905
|
-
subsTail: undefined,
|
|
906
|
-
flags: ReactiveFlags.Watching | ReactiveFlags.RecursedCheck,
|
|
907
|
-
notify() {
|
|
908
|
-
const flags = this.flags;
|
|
909
|
-
if (flags & ReactiveFlags.Dirty || flags & ReactiveFlags.Pending && checkDirty(this.deps, this)) {
|
|
910
|
-
run();
|
|
911
|
-
} else {
|
|
912
|
-
this.flags = ReactiveFlags.Watching;
|
|
913
|
-
}
|
|
914
|
-
},
|
|
915
|
-
stop() {
|
|
916
|
-
this.flags = ReactiveFlags.None;
|
|
917
|
-
this.depsTail = undefined;
|
|
918
|
-
purgeDeps(this);
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
run();
|
|
922
|
-
return effectObj;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
297
|
/**
|
|
926
298
|
* Creates actor logic for subscribing to lifecycle events (done/error/snapshot)
|
|
927
299
|
* from another actor. Used internally by `enq.subscribeTo()`.
|
|
@@ -939,15 +311,6 @@ function createSubscriptionLogic() {
|
|
|
939
311
|
error,
|
|
940
312
|
snapshot: onSnapshot
|
|
941
313
|
} = mappers;
|
|
942
|
-
|
|
943
|
-
// Atoms emit a raw value (no `status`) and have no done/error lifecycle —
|
|
944
|
-
// pass the value straight to the `snapshot` mapper.
|
|
945
|
-
if (isAtom(actor)) {
|
|
946
|
-
if (!onSnapshot) {
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
return actor.subscribe(value => relayMappedToParent(self, system, () => onSnapshot(value)));
|
|
950
|
-
}
|
|
951
314
|
return actor.subscribe({
|
|
952
315
|
next: snapshot => {
|
|
953
316
|
if (snapshot.status === 'done' && done) {
|
|
@@ -1515,27 +878,13 @@ function formatRouteTransitions(rootStateNode) {
|
|
|
1515
878
|
if ('$unserializable' in routeConfig) {
|
|
1516
879
|
throw new Error(`State "${sn.id}" has a route that is not serializable. Re-provide the route function when reviving this machine.`);
|
|
1517
880
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
const userGuard = routeConfig.guard;
|
|
881
|
+
const {
|
|
882
|
+
guard: _guard,
|
|
883
|
+
...routeOptions
|
|
884
|
+
} = routeConfig;
|
|
1523
885
|
const transition = {
|
|
1524
|
-
...
|
|
1525
|
-
guard:
|
|
1526
|
-
if (!routeMatches(args)) return false;
|
|
1527
|
-
if (typeof userGuard === 'function') return userGuard(args);
|
|
1528
|
-
if (typeof userGuard === 'string') {
|
|
1529
|
-
const guardImpl = args.guards?.[userGuard];
|
|
1530
|
-
if (!guardImpl) {
|
|
1531
|
-
// A typo'd guard name must fail loudly — silently passing
|
|
1532
|
-
// would allow the route and corrupt machine behavior.
|
|
1533
|
-
throw new Error(`Guard '${userGuard}' is not implemented in machine '${rootStateNode.machine.id}'. Available guards: ${Object.keys(args.guards ?? {}).map(key => `'${key}'`).join(', ') || '(none)'}.` );
|
|
1534
|
-
}
|
|
1535
|
-
return guardImpl(args);
|
|
1536
|
-
}
|
|
1537
|
-
return true;
|
|
1538
|
-
} : routeMatches,
|
|
886
|
+
...routeOptions,
|
|
887
|
+
guard: routeMatches,
|
|
1539
888
|
target: `#${routeId}`
|
|
1540
889
|
};
|
|
1541
890
|
routeTransitions.push(formatTransition(rootStateNode, 'xstate.route', transition));
|
|
@@ -2533,24 +1882,7 @@ function evaluateCandidate(candidate, event, snapshot, stateNode, self) {
|
|
|
2533
1882
|
delays: stateNode.machine.implementations.delays,
|
|
2534
1883
|
_snapshot: snapshot
|
|
2535
1884
|
};
|
|
2536
|
-
|
|
2537
|
-
const guardParams = typeof guardConfig?.params === 'function' ? guardConfig.params({
|
|
2538
|
-
context: snapshot.context,
|
|
2539
|
-
event
|
|
2540
|
-
}) : guardConfig?.params;
|
|
2541
|
-
let guardPassed = true;
|
|
2542
|
-
if (typeof guardConfig === 'function') {
|
|
2543
|
-
guardPassed = guardConfig(guardArgs, guardParams);
|
|
2544
|
-
} else if (typeof guardConfig?.type === 'string') {
|
|
2545
|
-
const guardImpl = stateNode.machine.implementations.guards[guardConfig.type];
|
|
2546
|
-
if (!guardImpl) {
|
|
2547
|
-
// A typo'd guard name must fail loudly — silently passing would
|
|
2548
|
-
// take the guarded transition and corrupt machine behavior.
|
|
2549
|
-
throw new Error(`Guard '${guardConfig.type}' is not implemented in machine '${stateNode.machine.id}'. Available guards: ${Object.keys(stateNode.machine.implementations.guards).map(key => `'${key}'`).join(', ') || '(none)'}.` );
|
|
2550
|
-
}
|
|
2551
|
-
guardPassed = guardImpl(guardArgs, guardParams);
|
|
2552
|
-
}
|
|
2553
|
-
if (!guardPassed) {
|
|
1885
|
+
if (!candidate.guard(guardArgs)) {
|
|
2554
1886
|
return false;
|
|
2555
1887
|
}
|
|
2556
1888
|
}
|
|
@@ -3852,7 +3184,7 @@ class Actor {
|
|
|
3852
3184
|
complete: observer.complete
|
|
3853
3185
|
});
|
|
3854
3186
|
},
|
|
3855
|
-
get: () => selector(this.
|
|
3187
|
+
get: () => selector(this.getSnapshot())
|
|
3856
3188
|
};
|
|
3857
3189
|
}
|
|
3858
3190
|
|
|
@@ -4141,15 +3473,9 @@ class Actor {
|
|
|
4141
3473
|
* @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
|
|
4142
3474
|
*/
|
|
4143
3475
|
getSnapshot() {
|
|
4144
|
-
return this.get();
|
|
4145
|
-
}
|
|
4146
|
-
|
|
4147
|
-
/** Read the actor's current snapshot as an atom value. */
|
|
4148
|
-
get() {
|
|
4149
3476
|
if (!this._snapshot) {
|
|
4150
3477
|
throw new Error(`Snapshot can't be read while the actor initializes itself`);
|
|
4151
3478
|
}
|
|
4152
|
-
onActorRead?.(this);
|
|
4153
3479
|
return this._snapshot;
|
|
4154
3480
|
}
|
|
4155
3481
|
}
|
|
@@ -4945,4 +4271,4 @@ function createEmptyActor() {
|
|
|
4945
4271
|
return createActor(emptyLogic);
|
|
4946
4272
|
}
|
|
4947
4273
|
|
|
4948
|
-
export {
|
|
4274
|
+
export { $$ACTOR_TYPE as $, Actor as A, resolveReferencedActor as B, mapValues as C, createInvokeId as D, getDelayedTransitions as E, evaluateCandidate as F, formatTransition as G, toTransitionConfigArray as H, createInvokeTimeoutEvent as I, getCandidates as J, formatRouteTransitions as K, resolveStateValue as L, getAllStateNodes as M, NULL_EVENT as N, createMachineSnapshot as O, ProcessingStatus as P, isInFinalState as Q, transitionNode as R, STATE_DELIMITER as S, TimeoutError as T, resolveAndExecuteActionsWithContext as U, toStatePath as V, isStateId as W, getStateNodeByPath as X, getPersistedSnapshot as Y, XSTATE_INIT as Z, macrostep as a, createInitEvent as b, createActor as c, initialMicrostep as d, isMachineSnapshot as e, getStateNodes as f, getProperAncestors as g, getAllOwnEventDescriptors as h, isAtomicStateNode as i, matchesState as j, checkStateIn as k, pathToStateValue as l, matchesEventDescriptor as m, toObserver as n, createEmptyActor as o, parseDelayToMilliseconds as p, createCallbackLogic as q, createObservableLogic as r, createEventObservableLogic as s, toArray as t, createLogic as u, createAsyncLogic as v, createListenerLogic as w, listenerLogic as x, createSubscriptionLogic as y, subscriptionLogic as z };
|