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;
|
|
@@ -202,10 +189,9 @@ function createAttachedLogic(attach) {
|
|
|
202
189
|
self,
|
|
203
190
|
system
|
|
204
191
|
}) => {
|
|
205
|
-
// Don't attach if the target doesn't exist
|
|
206
|
-
// Atoms have no `getSnapshot` / lifecycle, so they always attach.
|
|
192
|
+
// Don't attach if the target doesn't exist or is stopped.
|
|
207
193
|
const target = state.input.actor;
|
|
208
|
-
if (!target ||
|
|
194
|
+
if (!target || target.getSnapshot().status === 'stopped') {
|
|
209
195
|
return;
|
|
210
196
|
}
|
|
211
197
|
const subscription = attach(state.input, {
|
|
@@ -307,620 +293,6 @@ function createListenerLogic() {
|
|
|
307
293
|
// Singleton logic instance
|
|
308
294
|
const listenerLogic = /* #__PURE__ */createListenerLogic();
|
|
309
295
|
|
|
310
|
-
/* eslint-disable */
|
|
311
|
-
// Adapted from Alien Signals
|
|
312
|
-
// https://github.com/stackblitz/alien-signals/
|
|
313
|
-
|
|
314
|
-
let ReactiveFlags = /*#__PURE__*/function (ReactiveFlags) {
|
|
315
|
-
ReactiveFlags[ReactiveFlags["None"] = 0] = "None";
|
|
316
|
-
ReactiveFlags[ReactiveFlags["Mutable"] = 1] = "Mutable";
|
|
317
|
-
ReactiveFlags[ReactiveFlags["Watching"] = 2] = "Watching";
|
|
318
|
-
ReactiveFlags[ReactiveFlags["RecursedCheck"] = 4] = "RecursedCheck";
|
|
319
|
-
ReactiveFlags[ReactiveFlags["Recursed"] = 8] = "Recursed";
|
|
320
|
-
ReactiveFlags[ReactiveFlags["Dirty"] = 16] = "Dirty";
|
|
321
|
-
ReactiveFlags[ReactiveFlags["Pending"] = 32] = "Pending";
|
|
322
|
-
return ReactiveFlags;
|
|
323
|
-
}({});
|
|
324
|
-
function createReactiveSystem({
|
|
325
|
-
update,
|
|
326
|
-
notify,
|
|
327
|
-
unwatched
|
|
328
|
-
}) {
|
|
329
|
-
return {
|
|
330
|
-
link,
|
|
331
|
-
unlink,
|
|
332
|
-
propagate,
|
|
333
|
-
checkDirty,
|
|
334
|
-
shallowPropagate
|
|
335
|
-
};
|
|
336
|
-
function link(dep, sub, version) {
|
|
337
|
-
const prevDep = sub.depsTail;
|
|
338
|
-
if (prevDep !== undefined && prevDep.dep === dep) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
const nextDep = prevDep !== undefined ? prevDep.nextDep : sub.deps;
|
|
342
|
-
if (nextDep !== undefined && nextDep.dep === dep) {
|
|
343
|
-
nextDep.version = version;
|
|
344
|
-
sub.depsTail = nextDep;
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
const prevSub = dep.subsTail;
|
|
348
|
-
if (prevSub !== undefined && prevSub.version === version && prevSub.sub === sub) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
const newLink = sub.depsTail = dep.subsTail = {
|
|
352
|
-
version,
|
|
353
|
-
dep,
|
|
354
|
-
sub,
|
|
355
|
-
prevDep,
|
|
356
|
-
nextDep,
|
|
357
|
-
prevSub,
|
|
358
|
-
nextSub: undefined
|
|
359
|
-
};
|
|
360
|
-
if (nextDep !== undefined) {
|
|
361
|
-
nextDep.prevDep = newLink;
|
|
362
|
-
}
|
|
363
|
-
if (prevDep !== undefined) {
|
|
364
|
-
prevDep.nextDep = newLink;
|
|
365
|
-
} else {
|
|
366
|
-
sub.deps = newLink;
|
|
367
|
-
}
|
|
368
|
-
if (prevSub !== undefined) {
|
|
369
|
-
prevSub.nextSub = newLink;
|
|
370
|
-
} else {
|
|
371
|
-
dep.subs = newLink;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function unlink(link, sub = link.sub) {
|
|
375
|
-
const dep = link.dep;
|
|
376
|
-
const prevDep = link.prevDep;
|
|
377
|
-
const nextDep = link.nextDep;
|
|
378
|
-
const nextSub = link.nextSub;
|
|
379
|
-
const prevSub = link.prevSub;
|
|
380
|
-
if (nextDep !== undefined) {
|
|
381
|
-
nextDep.prevDep = prevDep;
|
|
382
|
-
} else {
|
|
383
|
-
sub.depsTail = prevDep;
|
|
384
|
-
}
|
|
385
|
-
if (prevDep !== undefined) {
|
|
386
|
-
prevDep.nextDep = nextDep;
|
|
387
|
-
} else {
|
|
388
|
-
sub.deps = nextDep;
|
|
389
|
-
}
|
|
390
|
-
if (nextSub !== undefined) {
|
|
391
|
-
nextSub.prevSub = prevSub;
|
|
392
|
-
} else {
|
|
393
|
-
dep.subsTail = prevSub;
|
|
394
|
-
}
|
|
395
|
-
if (prevSub !== undefined) {
|
|
396
|
-
prevSub.nextSub = nextSub;
|
|
397
|
-
} else if ((dep.subs = nextSub) === undefined) {
|
|
398
|
-
unwatched(dep);
|
|
399
|
-
}
|
|
400
|
-
return nextDep;
|
|
401
|
-
}
|
|
402
|
-
function propagate(link) {
|
|
403
|
-
let next = link.nextSub;
|
|
404
|
-
let stack;
|
|
405
|
-
top: do {
|
|
406
|
-
const sub = link.sub;
|
|
407
|
-
let flags = sub.flags;
|
|
408
|
-
if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed | ReactiveFlags.Dirty | ReactiveFlags.Pending))) {
|
|
409
|
-
sub.flags = flags | ReactiveFlags.Pending;
|
|
410
|
-
} else if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed))) {
|
|
411
|
-
flags = ReactiveFlags.None;
|
|
412
|
-
} else if (!(flags & ReactiveFlags.RecursedCheck)) {
|
|
413
|
-
sub.flags = flags & ~ReactiveFlags.Recursed | ReactiveFlags.Pending;
|
|
414
|
-
} else if (!(flags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) && isValidLink(link, sub)) {
|
|
415
|
-
sub.flags = flags | (ReactiveFlags.Recursed | ReactiveFlags.Pending);
|
|
416
|
-
flags &= ReactiveFlags.Mutable;
|
|
417
|
-
} else {
|
|
418
|
-
flags = ReactiveFlags.None;
|
|
419
|
-
}
|
|
420
|
-
if (flags & ReactiveFlags.Watching) {
|
|
421
|
-
notify(sub);
|
|
422
|
-
}
|
|
423
|
-
if (flags & ReactiveFlags.Mutable) {
|
|
424
|
-
const subSubs = sub.subs;
|
|
425
|
-
if (subSubs !== undefined) {
|
|
426
|
-
const nextSub = (link = subSubs).nextSub;
|
|
427
|
-
if (nextSub !== undefined) {
|
|
428
|
-
stack = {
|
|
429
|
-
value: next,
|
|
430
|
-
prev: stack
|
|
431
|
-
};
|
|
432
|
-
next = nextSub;
|
|
433
|
-
}
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
if ((link = next) !== undefined) {
|
|
438
|
-
next = link.nextSub;
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
while (stack !== undefined) {
|
|
442
|
-
link = stack.value;
|
|
443
|
-
stack = stack.prev;
|
|
444
|
-
if (link !== undefined) {
|
|
445
|
-
next = link.nextSub;
|
|
446
|
-
continue top;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
break;
|
|
450
|
-
} while (true);
|
|
451
|
-
}
|
|
452
|
-
function checkDirty(link, sub) {
|
|
453
|
-
let stack;
|
|
454
|
-
let checkDepth = 0;
|
|
455
|
-
let dirty = false;
|
|
456
|
-
top: do {
|
|
457
|
-
const dep = link.dep;
|
|
458
|
-
const flags = dep.flags;
|
|
459
|
-
if (sub.flags & ReactiveFlags.Dirty) {
|
|
460
|
-
dirty = true;
|
|
461
|
-
} else if ((flags & (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) === (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) {
|
|
462
|
-
if (update(dep)) {
|
|
463
|
-
const subs = dep.subs;
|
|
464
|
-
if (subs.nextSub !== undefined) {
|
|
465
|
-
shallowPropagate(subs);
|
|
466
|
-
}
|
|
467
|
-
dirty = true;
|
|
468
|
-
}
|
|
469
|
-
} else if ((flags & (ReactiveFlags.Mutable | ReactiveFlags.Pending)) === (ReactiveFlags.Mutable | ReactiveFlags.Pending)) {
|
|
470
|
-
if (link.nextSub !== undefined || link.prevSub !== undefined) {
|
|
471
|
-
stack = {
|
|
472
|
-
value: link,
|
|
473
|
-
prev: stack
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
link = dep.deps;
|
|
477
|
-
sub = dep;
|
|
478
|
-
++checkDepth;
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
if (!dirty) {
|
|
482
|
-
const nextDep = link.nextDep;
|
|
483
|
-
if (nextDep !== undefined) {
|
|
484
|
-
link = nextDep;
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
while (checkDepth--) {
|
|
489
|
-
const firstSub = sub.subs;
|
|
490
|
-
const hasMultipleSubs = firstSub.nextSub !== undefined;
|
|
491
|
-
if (hasMultipleSubs) {
|
|
492
|
-
link = stack.value;
|
|
493
|
-
stack = stack.prev;
|
|
494
|
-
} else {
|
|
495
|
-
link = firstSub;
|
|
496
|
-
}
|
|
497
|
-
if (dirty) {
|
|
498
|
-
if (update(sub)) {
|
|
499
|
-
if (hasMultipleSubs) {
|
|
500
|
-
shallowPropagate(firstSub);
|
|
501
|
-
}
|
|
502
|
-
sub = link.sub;
|
|
503
|
-
continue;
|
|
504
|
-
}
|
|
505
|
-
dirty = false;
|
|
506
|
-
} else {
|
|
507
|
-
sub.flags &= ~ReactiveFlags.Pending;
|
|
508
|
-
}
|
|
509
|
-
sub = link.sub;
|
|
510
|
-
const nextDep = link.nextDep;
|
|
511
|
-
if (nextDep !== undefined) {
|
|
512
|
-
link = nextDep;
|
|
513
|
-
continue top;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return dirty;
|
|
517
|
-
} while (true);
|
|
518
|
-
}
|
|
519
|
-
function shallowPropagate(link) {
|
|
520
|
-
do {
|
|
521
|
-
const sub = link.sub;
|
|
522
|
-
const flags = sub.flags;
|
|
523
|
-
if ((flags & (ReactiveFlags.Pending | ReactiveFlags.Dirty)) === ReactiveFlags.Pending) {
|
|
524
|
-
sub.flags = flags | ReactiveFlags.Dirty;
|
|
525
|
-
if ((flags & (ReactiveFlags.Watching | ReactiveFlags.RecursedCheck)) === ReactiveFlags.Watching) {
|
|
526
|
-
notify(sub);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
} while ((link = link.nextSub) !== undefined);
|
|
530
|
-
}
|
|
531
|
-
function isValidLink(checkLink, sub) {
|
|
532
|
-
let link = sub.depsTail;
|
|
533
|
-
while (link !== undefined) {
|
|
534
|
-
if (link === checkLink) {
|
|
535
|
-
return true;
|
|
536
|
-
}
|
|
537
|
-
link = link.prevDep;
|
|
538
|
-
}
|
|
539
|
-
return false;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Nominal brand (phantom, compile-time only) marking a value as an XState atom.
|
|
545
|
-
* Real atoms get the runtime brand ({@link $$atom}) in `createAtom`; this type
|
|
546
|
-
* brand keeps atom-only APIs (e.g. `enq.subscribeTo`) from structurally
|
|
547
|
-
* accepting plain readables like `actor.select(...)` that would be dispatched
|
|
548
|
-
* down the non-atom path at runtime.
|
|
549
|
-
*/
|
|
550
|
-
|
|
551
|
-
/** Brand marking an object as an atom, so it can be detected structurally. */
|
|
552
|
-
const $$atom = /* #__PURE__ */Symbol.for('xstate.atom');
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Returns `true` if the value is an atom (writable, computed, async, or
|
|
556
|
-
* reducer). Lets actor-consuming APIs (e.g. `enq.subscribeTo`) accept atoms
|
|
557
|
-
* directly.
|
|
558
|
-
*/
|
|
559
|
-
function isAtom(value) {
|
|
560
|
-
return !!value && typeof value === 'object' && $$atom in value;
|
|
561
|
-
}
|
|
562
|
-
const queuedEffects = [];
|
|
563
|
-
let cycle = 0;
|
|
564
|
-
// Initialized lazily on first atom creation (instead of at module evaluation)
|
|
565
|
-
// so the reactive system stays tree-shakeable for apps that never use atoms —
|
|
566
|
-
|
|
567
|
-
// would be retained by consumer bundlers even when atoms are unused.
|
|
568
|
-
let link;
|
|
569
|
-
let unlink;
|
|
570
|
-
let propagate;
|
|
571
|
-
let checkDirty;
|
|
572
|
-
let shallowPropagate;
|
|
573
|
-
let reactiveSystemInstalled = false;
|
|
574
|
-
function ensureReactiveSystem() {
|
|
575
|
-
if (reactiveSystemInstalled) {
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
reactiveSystemInstalled = true;
|
|
579
|
-
({
|
|
580
|
-
link,
|
|
581
|
-
unlink,
|
|
582
|
-
propagate,
|
|
583
|
-
checkDirty,
|
|
584
|
-
shallowPropagate
|
|
585
|
-
} = createReactiveSystem({
|
|
586
|
-
update(atom) {
|
|
587
|
-
return atom._update();
|
|
588
|
-
},
|
|
589
|
-
notify(effect) {
|
|
590
|
-
queuedEffects[queuedEffectsLength++] = effect;
|
|
591
|
-
effect.flags &= ~ReactiveFlags.Watching;
|
|
592
|
-
},
|
|
593
|
-
unwatched(atom) {
|
|
594
|
-
if (atom.depsTail !== undefined) {
|
|
595
|
-
atom.depsTail = undefined;
|
|
596
|
-
atom.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty;
|
|
597
|
-
purgeDeps(atom);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}));
|
|
601
|
-
}
|
|
602
|
-
let notifyIndex = 0;
|
|
603
|
-
let queuedEffectsLength = 0;
|
|
604
|
-
let activeSub;
|
|
605
|
-
function purgeDeps(sub) {
|
|
606
|
-
const depsTail = sub.depsTail;
|
|
607
|
-
let dep = depsTail !== undefined ? depsTail.nextDep : sub.deps;
|
|
608
|
-
while (dep !== undefined) {
|
|
609
|
-
dep = unlink(dep, sub);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
function flush() {
|
|
613
|
-
while (notifyIndex < queuedEffectsLength) {
|
|
614
|
-
const effect = queuedEffects[notifyIndex];
|
|
615
|
-
queuedEffects[notifyIndex++] = undefined;
|
|
616
|
-
effect.notify();
|
|
617
|
-
}
|
|
618
|
-
notifyIndex = 0;
|
|
619
|
-
queuedEffectsLength = 0;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/** The current state of an async atom. */
|
|
623
|
-
|
|
624
|
-
/** Options passed to an async atom getter. */
|
|
625
|
-
|
|
626
|
-
function compareAsyncAtomState(a, b) {
|
|
627
|
-
if (a.status !== b.status) {
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
if (a.status === 'done' && b.status === 'done') {
|
|
631
|
-
return Object.is(a.data, b.data);
|
|
632
|
-
}
|
|
633
|
-
if (a.status === 'error' && b.status === 'error') {
|
|
634
|
-
return Object.is(a.error, b.error);
|
|
635
|
-
}
|
|
636
|
-
// both 'pending'
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
function updateAsyncAtom(atom, nextValue) {
|
|
640
|
-
if (atom._update(nextValue)) {
|
|
641
|
-
const subs = atom.subs;
|
|
642
|
-
if (subs !== undefined) {
|
|
643
|
-
propagate(subs);
|
|
644
|
-
shallowPropagate(subs);
|
|
645
|
-
flush();
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Creates a read-only atom whose value is loaded from an async getter.
|
|
652
|
-
*
|
|
653
|
-
* The getter receives an `AbortSignal`; when the async atom recomputes, the
|
|
654
|
-
* previous signal is aborted and stale resolutions are ignored.
|
|
655
|
-
*/
|
|
656
|
-
function createAsyncAtom(getValue, options) {
|
|
657
|
-
const ref = {};
|
|
658
|
-
let currentController;
|
|
659
|
-
let currentRunId = 0;
|
|
660
|
-
const atom = createAtom(() => {
|
|
661
|
-
currentController?.abort();
|
|
662
|
-
const controller = new AbortController();
|
|
663
|
-
const runId = ++currentRunId;
|
|
664
|
-
currentController = controller;
|
|
665
|
-
getValue({
|
|
666
|
-
signal: controller.signal
|
|
667
|
-
}).then(data => {
|
|
668
|
-
if (runId !== currentRunId || controller.signal.aborted) {
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
updateAsyncAtom(ref.current, {
|
|
672
|
-
status: 'done',
|
|
673
|
-
data
|
|
674
|
-
});
|
|
675
|
-
}, error => {
|
|
676
|
-
if (runId !== currentRunId || controller.signal.aborted) {
|
|
677
|
-
return;
|
|
678
|
-
}
|
|
679
|
-
updateAsyncAtom(ref.current, {
|
|
680
|
-
status: 'error',
|
|
681
|
-
error
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
return {
|
|
685
|
-
status: 'pending'
|
|
686
|
-
};
|
|
687
|
-
}, {
|
|
688
|
-
compare: compareAsyncAtomState,
|
|
689
|
-
...options
|
|
690
|
-
});
|
|
691
|
-
ref.current = atom;
|
|
692
|
-
return atom;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* Mirror atoms that bump a version whenever a tracked actor emits a snapshot,
|
|
697
|
-
* letting computed atoms depend on `actor.get()` reads.
|
|
698
|
-
*
|
|
699
|
-
* The hook is installed lazily on first atom creation (not at module
|
|
700
|
-
* evaluation) so that it remains tree-shakeable for apps that never use atoms —
|
|
701
|
-
* any tracked read necessarily happens inside an atom computation, so first-use
|
|
702
|
-
* installation is always early enough.
|
|
703
|
-
*/
|
|
704
|
-
let actorInteropInstalled = false;
|
|
705
|
-
function ensureActorInterop() {
|
|
706
|
-
if (actorInteropInstalled) {
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
actorInteropInstalled = true;
|
|
710
|
-
const actorVersions = new WeakMap();
|
|
711
|
-
installActorReadHook(actorRef => {
|
|
712
|
-
if (activeSub === undefined) {
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
let version = actorVersions.get(actorRef);
|
|
716
|
-
if (version === undefined) {
|
|
717
|
-
version = createAtom(0);
|
|
718
|
-
actorVersions.set(actorRef, version);
|
|
719
|
-
actorRef.subscribe({
|
|
720
|
-
next: () => version.set(v => v + 1),
|
|
721
|
-
error: () => {}
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
version.get();
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* Creates an atom.
|
|
730
|
-
*
|
|
731
|
-
* Pass a value for a writable atom or a getter for a computed read-only atom.
|
|
732
|
-
*/
|
|
733
|
-
|
|
734
|
-
function createAtom(valueOrFn, optionsOrInput) {
|
|
735
|
-
ensureReactiveSystem();
|
|
736
|
-
ensureActorInterop();
|
|
737
|
-
const isComputed = typeof valueOrFn === 'function';
|
|
738
|
-
const getter = valueOrFn;
|
|
739
|
-
|
|
740
|
-
// Create plain object atom
|
|
741
|
-
const atom = {
|
|
742
|
-
_snapshot: isComputed ? undefined : valueOrFn,
|
|
743
|
-
subs: undefined,
|
|
744
|
-
subsTail: undefined,
|
|
745
|
-
deps: undefined,
|
|
746
|
-
depsTail: undefined,
|
|
747
|
-
flags: isComputed ? ReactiveFlags.None : ReactiveFlags.Mutable,
|
|
748
|
-
get() {
|
|
749
|
-
if (activeSub !== undefined) {
|
|
750
|
-
link(atom, activeSub, cycle);
|
|
751
|
-
}
|
|
752
|
-
return atom._snapshot;
|
|
753
|
-
},
|
|
754
|
-
subscribe(observerOrFn) {
|
|
755
|
-
const observer = typeof observerOrFn === 'function' ? {
|
|
756
|
-
next: observerOrFn
|
|
757
|
-
} : observerOrFn;
|
|
758
|
-
const observed = {
|
|
759
|
-
current: false
|
|
760
|
-
};
|
|
761
|
-
const e = effect(() => {
|
|
762
|
-
atom.get();
|
|
763
|
-
if (!observed.current) {
|
|
764
|
-
observed.current = true;
|
|
765
|
-
} else {
|
|
766
|
-
const prevSub = activeSub;
|
|
767
|
-
activeSub = undefined;
|
|
768
|
-
try {
|
|
769
|
-
observer.next?.(atom._snapshot);
|
|
770
|
-
} catch (err) {
|
|
771
|
-
reportUnhandledError(err);
|
|
772
|
-
} finally {
|
|
773
|
-
activeSub = prevSub;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// If the observer synchronously updates any of our deps we'll be
|
|
777
|
-
// marked as dirty preventing this effect from re-running. Request
|
|
778
|
-
// the value again to reconcile any dirty deps.
|
|
779
|
-
atom.get();
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
return {
|
|
783
|
-
unsubscribe: () => {
|
|
784
|
-
e.stop();
|
|
785
|
-
}
|
|
786
|
-
};
|
|
787
|
-
},
|
|
788
|
-
_update(getValue) {
|
|
789
|
-
const prevSub = activeSub;
|
|
790
|
-
const compare = optionsOrInput?.compare ?? Object.is;
|
|
791
|
-
activeSub = atom;
|
|
792
|
-
++cycle;
|
|
793
|
-
atom.depsTail = undefined;
|
|
794
|
-
if (isComputed) {
|
|
795
|
-
atom.flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck;
|
|
796
|
-
}
|
|
797
|
-
try {
|
|
798
|
-
const oldValue = atom._snapshot;
|
|
799
|
-
const newValue = typeof getValue === 'function' ? getValue(oldValue) : getValue === undefined && isComputed ? getter(oldValue) : getValue;
|
|
800
|
-
if (oldValue === undefined || !compare(oldValue, newValue)) {
|
|
801
|
-
atom._snapshot = newValue;
|
|
802
|
-
return true;
|
|
803
|
-
}
|
|
804
|
-
return false;
|
|
805
|
-
} finally {
|
|
806
|
-
activeSub = prevSub;
|
|
807
|
-
if (isComputed) {
|
|
808
|
-
atom.flags &= ~ReactiveFlags.RecursedCheck;
|
|
809
|
-
}
|
|
810
|
-
purgeDeps(atom);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
};
|
|
814
|
-
if (isComputed) {
|
|
815
|
-
atom.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty;
|
|
816
|
-
atom.get = function () {
|
|
817
|
-
const flags = atom.flags;
|
|
818
|
-
if (flags & ReactiveFlags.Dirty || flags & ReactiveFlags.Pending && checkDirty(atom.deps, atom)) {
|
|
819
|
-
if (atom._update()) {
|
|
820
|
-
const subs = atom.subs;
|
|
821
|
-
if (subs !== undefined) {
|
|
822
|
-
shallowPropagate(subs);
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
} else if (flags & ReactiveFlags.Pending) {
|
|
826
|
-
atom.flags = flags & ~ReactiveFlags.Pending;
|
|
827
|
-
}
|
|
828
|
-
if (activeSub !== undefined) {
|
|
829
|
-
link(atom, activeSub, cycle);
|
|
830
|
-
}
|
|
831
|
-
return atom._snapshot;
|
|
832
|
-
};
|
|
833
|
-
} else {
|
|
834
|
-
atom.set = function (valueOrFn) {
|
|
835
|
-
if (atom._update(valueOrFn)) {
|
|
836
|
-
const subs = atom.subs;
|
|
837
|
-
if (subs !== undefined) {
|
|
838
|
-
propagate(subs);
|
|
839
|
-
shallowPropagate(subs);
|
|
840
|
-
flush();
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
atom[$$atom] = true;
|
|
846
|
-
return atom;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
/**
|
|
850
|
-
* Creates an inert atom config that can be instantiated later.
|
|
851
|
-
*
|
|
852
|
-
* Useful for framework hooks that need to create a stable local atom from
|
|
853
|
-
* component input.
|
|
854
|
-
*/
|
|
855
|
-
|
|
856
|
-
function createAtomConfig(initialValueOrFn, options) {
|
|
857
|
-
return {
|
|
858
|
-
createAtom(input) {
|
|
859
|
-
const initialValue = typeof initialValueOrFn === 'function' ? initialValueOrFn(input) : initialValueOrFn;
|
|
860
|
-
return createAtom(initialValue, options);
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/** Creates an atom whose updates are handled by a reducer function. */
|
|
866
|
-
function createReducerAtom(initialValue, reducer, options) {
|
|
867
|
-
const atom = createAtom(initialValue, options);
|
|
868
|
-
return {
|
|
869
|
-
[$$atom]: true,
|
|
870
|
-
get: atom.get.bind(atom),
|
|
871
|
-
subscribe: atom.subscribe.bind(atom),
|
|
872
|
-
send(event) {
|
|
873
|
-
const prevSub = activeSub;
|
|
874
|
-
activeSub = undefined;
|
|
875
|
-
let nextState;
|
|
876
|
-
try {
|
|
877
|
-
nextState = reducer(atom.get(), event);
|
|
878
|
-
} finally {
|
|
879
|
-
activeSub = prevSub;
|
|
880
|
-
}
|
|
881
|
-
atom.set(nextState);
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
function effect(fn) {
|
|
886
|
-
const run = () => {
|
|
887
|
-
const prevSub = activeSub;
|
|
888
|
-
activeSub = effectObj;
|
|
889
|
-
++cycle;
|
|
890
|
-
effectObj.depsTail = undefined;
|
|
891
|
-
effectObj.flags = ReactiveFlags.Watching | ReactiveFlags.RecursedCheck;
|
|
892
|
-
try {
|
|
893
|
-
return fn();
|
|
894
|
-
} finally {
|
|
895
|
-
activeSub = prevSub;
|
|
896
|
-
effectObj.flags &= ~ReactiveFlags.RecursedCheck;
|
|
897
|
-
purgeDeps(effectObj);
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
const effectObj = {
|
|
901
|
-
deps: undefined,
|
|
902
|
-
depsTail: undefined,
|
|
903
|
-
subs: undefined,
|
|
904
|
-
subsTail: undefined,
|
|
905
|
-
flags: ReactiveFlags.Watching | ReactiveFlags.RecursedCheck,
|
|
906
|
-
notify() {
|
|
907
|
-
const flags = this.flags;
|
|
908
|
-
if (flags & ReactiveFlags.Dirty || flags & ReactiveFlags.Pending && checkDirty(this.deps, this)) {
|
|
909
|
-
run();
|
|
910
|
-
} else {
|
|
911
|
-
this.flags = ReactiveFlags.Watching;
|
|
912
|
-
}
|
|
913
|
-
},
|
|
914
|
-
stop() {
|
|
915
|
-
this.flags = ReactiveFlags.None;
|
|
916
|
-
this.depsTail = undefined;
|
|
917
|
-
purgeDeps(this);
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
run();
|
|
921
|
-
return effectObj;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
296
|
/**
|
|
925
297
|
* Creates actor logic for subscribing to lifecycle events (done/error/snapshot)
|
|
926
298
|
* from another actor. Used internally by `enq.subscribeTo()`.
|
|
@@ -938,15 +310,6 @@ function createSubscriptionLogic() {
|
|
|
938
310
|
error,
|
|
939
311
|
snapshot: onSnapshot
|
|
940
312
|
} = mappers;
|
|
941
|
-
|
|
942
|
-
// Atoms emit a raw value (no `status`) and have no done/error lifecycle —
|
|
943
|
-
// pass the value straight to the `snapshot` mapper.
|
|
944
|
-
if (isAtom(actor)) {
|
|
945
|
-
if (!onSnapshot) {
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
return actor.subscribe(value => relayMappedToParent(self, system, () => onSnapshot(value)));
|
|
949
|
-
}
|
|
950
313
|
return actor.subscribe({
|
|
951
314
|
next: snapshot => {
|
|
952
315
|
if (snapshot.status === 'done' && done) {
|
|
@@ -1504,27 +867,13 @@ function formatRouteTransitions(rootStateNode) {
|
|
|
1504
867
|
if ('$unserializable' in routeConfig) {
|
|
1505
868
|
throw new Error(`State "${sn.id}" has a route that is not serializable. Re-provide the route function when reviving this machine.`);
|
|
1506
869
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
const userGuard = routeConfig.guard;
|
|
870
|
+
const {
|
|
871
|
+
guard: _guard,
|
|
872
|
+
...routeOptions
|
|
873
|
+
} = routeConfig;
|
|
1512
874
|
const transition = {
|
|
1513
|
-
...
|
|
1514
|
-
guard:
|
|
1515
|
-
if (!routeMatches(args)) return false;
|
|
1516
|
-
if (typeof userGuard === 'function') return userGuard(args);
|
|
1517
|
-
if (typeof userGuard === 'string') {
|
|
1518
|
-
const guardImpl = args.guards?.[userGuard];
|
|
1519
|
-
if (!guardImpl) {
|
|
1520
|
-
// A typo'd guard name must fail loudly — silently passing
|
|
1521
|
-
// would allow the route and corrupt machine behavior.
|
|
1522
|
-
throw new Error(`Guard '${userGuard}' is not implemented in machine '${rootStateNode.machine.id}'.`);
|
|
1523
|
-
}
|
|
1524
|
-
return guardImpl(args);
|
|
1525
|
-
}
|
|
1526
|
-
return true;
|
|
1527
|
-
} : routeMatches,
|
|
875
|
+
...routeOptions,
|
|
876
|
+
guard: routeMatches,
|
|
1528
877
|
target: `#${routeId}`
|
|
1529
878
|
};
|
|
1530
879
|
routeTransitions.push(formatTransition(rootStateNode, 'xstate.route', transition));
|
|
@@ -2522,24 +1871,7 @@ function evaluateCandidate(candidate, event, snapshot, stateNode, self) {
|
|
|
2522
1871
|
delays: stateNode.machine.implementations.delays,
|
|
2523
1872
|
_snapshot: snapshot
|
|
2524
1873
|
};
|
|
2525
|
-
|
|
2526
|
-
const guardParams = typeof guardConfig?.params === 'function' ? guardConfig.params({
|
|
2527
|
-
context: snapshot.context,
|
|
2528
|
-
event
|
|
2529
|
-
}) : guardConfig?.params;
|
|
2530
|
-
let guardPassed = true;
|
|
2531
|
-
if (typeof guardConfig === 'function') {
|
|
2532
|
-
guardPassed = guardConfig(guardArgs, guardParams);
|
|
2533
|
-
} else if (typeof guardConfig?.type === 'string') {
|
|
2534
|
-
const guardImpl = stateNode.machine.implementations.guards[guardConfig.type];
|
|
2535
|
-
if (!guardImpl) {
|
|
2536
|
-
// A typo'd guard name must fail loudly — silently passing would
|
|
2537
|
-
// take the guarded transition and corrupt machine behavior.
|
|
2538
|
-
throw new Error(`Guard '${guardConfig.type}' is not implemented in machine '${stateNode.machine.id}'.`);
|
|
2539
|
-
}
|
|
2540
|
-
guardPassed = guardImpl(guardArgs, guardParams);
|
|
2541
|
-
}
|
|
2542
|
-
if (!guardPassed) {
|
|
1874
|
+
if (!candidate.guard(guardArgs)) {
|
|
2543
1875
|
return false;
|
|
2544
1876
|
}
|
|
2545
1877
|
}
|
|
@@ -3826,7 +3158,7 @@ class Actor {
|
|
|
3826
3158
|
complete: observer.complete
|
|
3827
3159
|
});
|
|
3828
3160
|
},
|
|
3829
|
-
get: () => selector(this.
|
|
3161
|
+
get: () => selector(this.getSnapshot())
|
|
3830
3162
|
};
|
|
3831
3163
|
}
|
|
3832
3164
|
|
|
@@ -4105,12 +3437,6 @@ class Actor {
|
|
|
4105
3437
|
* @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
|
|
4106
3438
|
*/
|
|
4107
3439
|
getSnapshot() {
|
|
4108
|
-
return this.get();
|
|
4109
|
-
}
|
|
4110
|
-
|
|
4111
|
-
/** Read the actor's current snapshot as an atom value. */
|
|
4112
|
-
get() {
|
|
4113
|
-
onActorRead?.(this);
|
|
4114
3440
|
return this._snapshot;
|
|
4115
3441
|
}
|
|
4116
3442
|
}
|
|
@@ -4906,4 +4232,4 @@ function createEmptyActor() {
|
|
|
4906
4232
|
return createActor(emptyLogic);
|
|
4907
4233
|
}
|
|
4908
4234
|
|
|
4909
|
-
export {
|
|
4235
|
+
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 };
|