@solidjs/signals 0.0.9 → 0.0.11

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/prod.js CHANGED
@@ -30,6 +30,104 @@ var EFFECT_RENDER = 1;
30
30
  var EFFECT_USER = 2;
31
31
  var SUPPORTS_PROXY = typeof Proxy === "function";
32
32
 
33
+ // src/core/scheduler.ts
34
+ var clock = 0;
35
+ function getClock() {
36
+ return clock;
37
+ }
38
+ function incrementClock() {
39
+ clock++;
40
+ }
41
+ var scheduled = false;
42
+ function schedule() {
43
+ if (scheduled)
44
+ return;
45
+ scheduled = true;
46
+ if (!globalQueue.H)
47
+ queueMicrotask(flushSync);
48
+ }
49
+ var Queue = class {
50
+ H = false;
51
+ r = [[], [], []];
52
+ D = [];
53
+ created = clock;
54
+ enqueue(type, node) {
55
+ this.r[0].push(node);
56
+ if (type)
57
+ this.r[type].push(node);
58
+ schedule();
59
+ }
60
+ run(type) {
61
+ if (this.r[type].length) {
62
+ if (type === EFFECT_PURE) {
63
+ runPureQueue(this.r[type]);
64
+ this.r[type] = [];
65
+ } else {
66
+ const effects = this.r[type];
67
+ this.r[type] = [];
68
+ runEffectQueue(effects);
69
+ }
70
+ }
71
+ let rerun = false;
72
+ for (let i = 0; i < this.D.length; i++) {
73
+ rerun = this.D[i].run(type) || rerun;
74
+ }
75
+ if (type === EFFECT_PURE && this.r[type].length)
76
+ return true;
77
+ }
78
+ flush() {
79
+ if (this.H)
80
+ return;
81
+ this.H = true;
82
+ try {
83
+ while (this.run(EFFECT_PURE)) {
84
+ }
85
+ incrementClock();
86
+ scheduled = false;
87
+ this.run(EFFECT_RENDER);
88
+ this.run(EFFECT_USER);
89
+ } finally {
90
+ this.H = false;
91
+ }
92
+ }
93
+ addChild(child) {
94
+ this.D.push(child);
95
+ }
96
+ removeChild(child) {
97
+ const index = this.D.indexOf(child);
98
+ if (index >= 0)
99
+ this.D.splice(index, 1);
100
+ }
101
+ };
102
+ var globalQueue = new Queue();
103
+ function flushSync() {
104
+ while (scheduled) {
105
+ globalQueue.flush();
106
+ }
107
+ }
108
+ function runTop(node) {
109
+ const ancestors = [];
110
+ for (let current = node; current !== null; current = current.s) {
111
+ if (current.a !== STATE_CLEAN) {
112
+ ancestors.push(current);
113
+ }
114
+ }
115
+ for (let i = ancestors.length - 1; i >= 0; i--) {
116
+ if (ancestors[i].a !== STATE_DISPOSED)
117
+ ancestors[i].y();
118
+ }
119
+ }
120
+ function runPureQueue(queue) {
121
+ for (let i = 0; i < queue.length; i++) {
122
+ if (queue[i].a !== STATE_CLEAN)
123
+ runTop(queue[i]);
124
+ }
125
+ }
126
+ function runEffectQueue(queue) {
127
+ for (let i = 0; i < queue.length; i++)
128
+ queue[i].T();
129
+ }
130
+
33
131
  // src/core/utils.ts
34
132
  function isUndefined(value) {
35
133
  return typeof value === "undefined";
@@ -104,23 +202,23 @@ var Owner = class {
104
202
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
105
203
  // However, the children are actually added in reverse creation order
106
204
  // See comment at the top of the file for an example of the _nextSibling traversal
107
- r = null;
108
- n = null;
109
205
  s = null;
206
+ n = null;
207
+ t = null;
110
208
  a = STATE_CLEAN;
111
209
  l = null;
112
210
  p = defaultContext;
113
211
  m = null;
114
- b = null;
212
+ h = globalQueue;
115
213
  constructor(signal = false) {
116
214
  if (currentOwner && !signal)
117
215
  currentOwner.append(this);
118
216
  }
119
217
  append(child) {
120
- child.r = this;
121
218
  child.s = this;
219
+ child.t = this;
122
220
  if (this.n)
123
- this.n.s = child;
221
+ this.n.t = child;
124
222
  child.n = this.n;
125
223
  this.n = child;
126
224
  if (child.p !== this.p) {
@@ -129,32 +227,32 @@ var Owner = class {
129
227
  if (this.m) {
130
228
  child.m = !child.m ? this.m : [...child.m, ...this.m];
131
229
  }
132
- if (this.b)
133
- child.b = this.b;
230
+ if (this.h)
231
+ child.h = this.h;
134
232
  }
135
233
  dispose(self = true) {
136
234
  if (this.a === STATE_DISPOSED)
137
235
  return;
138
- let head = self ? this.s || this.r : this, current = this.n, next = null;
139
- while (current && current.r === this) {
236
+ let head = self ? this.t || this.s : this, current = this.n, next = null;
237
+ while (current && current.s === this) {
140
238
  current.dispose(true);
141
- current.z();
239
+ current.A();
142
240
  next = current.n;
143
241
  current.n = null;
144
242
  current = next;
145
243
  }
146
244
  if (self)
147
- this.z();
245
+ this.A();
148
246
  if (current)
149
- current.s = !self ? this : this.s;
247
+ current.t = !self ? this : this.t;
150
248
  if (head)
151
249
  head.n = current;
152
250
  }
153
- z() {
154
- if (this.s)
155
- this.s.n = null;
156
- this.r = null;
251
+ A() {
252
+ if (this.t)
253
+ this.t.n = null;
157
254
  this.s = null;
255
+ this.t = null;
158
256
  this.p = defaultContext;
159
257
  this.m = null;
160
258
  this.a = STATE_DISPOSED;
@@ -179,7 +277,7 @@ var Owner = class {
179
277
  let i = 0, len = this.m.length;
180
278
  for (i = 0; i < len; i++) {
181
279
  try {
182
- this.m[i](error);
280
+ this.m[i](error, this);
183
281
  break;
184
282
  } catch (e) {
185
283
  error = e;
@@ -243,60 +341,57 @@ var currentMask = DEFAULT_FLAGS;
243
341
  var newSources = null;
244
342
  var newSourcesIndex = 0;
245
343
  var newFlags = 0;
246
- var clock = 0;
247
344
  var notStale = false;
248
345
  var updateCheck = null;
249
346
  var staleCheck = null;
250
347
  function getObserver() {
251
348
  return currentObserver;
252
349
  }
253
- function getClock() {
254
- return clock;
255
- }
256
- function incrementClock() {
257
- clock++;
258
- }
259
350
  var UNCHANGED = Symbol(0);
260
351
  var Computation = class extends Owner {
261
- g = null;
262
- e = null;
263
- c;
264
- D;
265
- t;
352
+ f = null;
353
+ d = null;
354
+ b;
355
+ E;
356
+ u;
266
357
  // Used in __DEV__ mode, hopefully removed in production
267
358
  Z;
268
359
  // Using false is an optimization as an alternative to _equals: () => false
269
360
  // which could enable more efficient DIRTY notification
270
361
  N = isEqual;
271
- T;
362
+ U;
272
363
  /** Whether the computation is an error or has ancestors that are unresolved */
273
- d = 0;
364
+ c = 0;
274
365
  /** Which flags raised by sources are handled, vs. being passed through. */
275
366
  O = DEFAULT_FLAGS;
276
367
  P = null;
277
- A = -1;
278
- H = false;
368
+ z = -1;
369
+ I = false;
279
370
  constructor(initialValue, compute2, options) {
280
371
  super(compute2 === null);
281
- this.t = compute2;
372
+ this.u = compute2;
282
373
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
283
- this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
284
- this.c = initialValue;
374
+ this.c = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
375
+ this.b = initialValue;
285
376
  if (options?.equals !== void 0)
286
377
  this.N = options.equals;
287
378
  if (options?.unobserved)
288
- this.T = options?.unobserved;
379
+ this.U = options?.unobserved;
289
380
  }
290
- U() {
291
- if (this.t)
292
- this.x();
293
- if (!this.t || this.g?.length)
381
+ V() {
382
+ if (this.u) {
383
+ if (this.c & ERROR_BIT && this.z <= getClock())
384
+ update(this);
385
+ else
386
+ this.y();
387
+ }
388
+ if (!this.u || this.f?.length)
294
389
  track(this);
295
- newFlags |= this.d & ~currentMask;
296
- if (this.d & ERROR_BIT) {
297
- throw this.D;
390
+ newFlags |= this.c & ~currentMask;
391
+ if (this.c & ERROR_BIT) {
392
+ throw this.E;
298
393
  } else {
299
- return this.c;
394
+ return this.b;
300
395
  }
301
396
  }
302
397
  /**
@@ -304,7 +399,7 @@ var Computation = class extends Owner {
304
399
  * Automatically re-executes the surrounding computation when the value changes
305
400
  */
306
401
  read() {
307
- return this.U();
402
+ return this.V();
308
403
  }
309
404
  /**
310
405
  * Return the current value of this computation
@@ -314,15 +409,15 @@ var Computation = class extends Owner {
314
409
  * before continuing
315
410
  */
316
411
  wait() {
317
- if (this.t && this.d & ERROR_BIT && this.A <= clock) {
412
+ if (this.u && this.c & ERROR_BIT && this.z <= getClock()) {
318
413
  update(this);
319
414
  }
320
- if ((notStale || this.d & UNINITIALIZED_BIT) && this.loading()) {
415
+ if ((notStale || this.c & UNINITIALIZED_BIT) && this.loading()) {
321
416
  throw new NotReadyError();
322
417
  }
323
- if (staleCheck && this.d & LOADING_BIT)
324
- staleCheck.c = true;
325
- return this.U();
418
+ if (staleCheck && this.loading())
419
+ staleCheck.b = true;
420
+ return this.V();
326
421
  }
327
422
  /**
328
423
  * Return true if the computation is the value is dependent on an unresolved promise
@@ -339,37 +434,37 @@ var Computation = class extends Owner {
339
434
  }
340
435
  /** Update the computation with a new value. */
341
436
  write(value, flags = 0, raw = false) {
342
- const newValue = !raw && typeof value === "function" ? value(this.c) : value;
343
- const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.N === false || !this.N(this.c, newValue));
437
+ const newValue = !raw && typeof value === "function" ? value(this.b) : value;
438
+ const valueChanged = newValue !== UNCHANGED && (!!(this.c & UNINITIALIZED_BIT) || this.N === false || !this.N(this.b, newValue));
344
439
  if (valueChanged) {
345
- this.c = newValue;
346
- this.D = void 0;
440
+ this.b = newValue;
441
+ this.E = void 0;
347
442
  }
348
- const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
349
- this.d = flags;
350
- this.A = clock + 1;
351
- if (this.e) {
352
- for (let i = 0; i < this.e.length; i++) {
443
+ const changedFlagsMask = this.c ^ flags, changedFlags = changedFlagsMask & flags;
444
+ this.c = flags;
445
+ this.z = getClock() + 1;
446
+ if (this.d) {
447
+ for (let i = 0; i < this.d.length; i++) {
353
448
  if (valueChanged) {
354
- this.e[i].q(STATE_DIRTY);
449
+ this.d[i].q(STATE_DIRTY);
355
450
  } else if (changedFlagsMask) {
356
- this.e[i].V(changedFlagsMask, changedFlags);
451
+ this.d[i].W(changedFlagsMask, changedFlags);
357
452
  }
358
453
  }
359
454
  }
360
- return this.c;
455
+ return this.b;
361
456
  }
362
457
  /**
363
458
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
364
459
  */
365
460
  q(state, skipQueue) {
366
- if (this.a >= state && !this.H)
461
+ if (this.a >= state && !this.I)
367
462
  return;
368
- this.H = !!skipQueue;
463
+ this.I = !!skipQueue;
369
464
  this.a = state;
370
- if (this.e) {
371
- for (let i = 0; i < this.e.length; i++) {
372
- this.e[i].q(STATE_CHECK, skipQueue);
465
+ if (this.d) {
466
+ for (let i = 0; i < this.d.length; i++) {
467
+ this.d[i].q(STATE_CHECK, skipQueue);
373
468
  }
374
469
  }
375
470
  }
@@ -379,7 +474,7 @@ var Computation = class extends Owner {
379
474
  * @param mask A bitmask for which flag(s) were changed.
380
475
  * @param newFlags The source's new flags, masked to just the changed ones.
381
476
  */
382
- V(mask, newFlags2) {
477
+ W(mask, newFlags2) {
383
478
  if (this.a >= STATE_DIRTY)
384
479
  return;
385
480
  if (mask & this.O) {
@@ -388,22 +483,22 @@ var Computation = class extends Owner {
388
483
  }
389
484
  if (this.a >= STATE_CHECK)
390
485
  return;
391
- const prevFlags = this.d & mask;
486
+ const prevFlags = this.c & mask;
392
487
  const deltaFlags = prevFlags ^ newFlags2;
393
488
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
394
489
  this.q(STATE_CHECK);
395
490
  } else {
396
- this.d ^= deltaFlags;
397
- if (this.e) {
398
- for (let i = 0; i < this.e.length; i++) {
399
- this.e[i].V(mask, newFlags2);
491
+ this.c ^= deltaFlags;
492
+ if (this.d) {
493
+ for (let i = 0; i < this.d.length; i++) {
494
+ this.d[i].W(mask, newFlags2);
400
495
  }
401
496
  }
402
497
  }
403
498
  }
404
- I(error) {
405
- this.D = error;
406
- this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
499
+ J(error) {
500
+ this.E = error;
501
+ this.write(UNCHANGED, this.c & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
407
502
  }
408
503
  /**
409
504
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -412,7 +507,7 @@ var Computation = class extends Owner {
412
507
  *
413
508
  * This function will ensure that the value and states we read from the computation are up to date
414
509
  */
415
- x() {
510
+ y() {
416
511
  if (this.a === STATE_DISPOSED) {
417
512
  throw new Error("Tried to read a disposed computation");
418
513
  }
@@ -421,9 +516,9 @@ var Computation = class extends Owner {
421
516
  }
422
517
  let observerFlags = 0;
423
518
  if (this.a === STATE_CHECK) {
424
- for (let i = 0; i < this.g.length; i++) {
425
- this.g[i].x();
426
- observerFlags |= this.g[i].d;
519
+ for (let i = 0; i < this.f.length; i++) {
520
+ this.f[i].y();
521
+ observerFlags |= this.f[i].c;
427
522
  if (this.a === STATE_DIRTY) {
428
523
  break;
429
524
  }
@@ -439,23 +534,23 @@ var Computation = class extends Owner {
439
534
  /**
440
535
  * Remove ourselves from the owner graph and the computation graph
441
536
  */
442
- z() {
537
+ A() {
443
538
  if (this.a === STATE_DISPOSED)
444
539
  return;
445
- if (this.g)
540
+ if (this.f)
446
541
  removeSourceObservers(this, 0);
447
- super.z();
542
+ super.A();
448
543
  }
449
544
  };
450
545
  function loadingState(node) {
451
- const prevOwner = setOwner(node.r);
546
+ const prevOwner = setOwner(node.s);
452
547
  const options = void 0;
453
548
  const computation = new Computation(
454
549
  void 0,
455
550
  () => {
456
551
  track(node);
457
- node.x();
458
- return !!(node.d & LOADING_BIT);
552
+ node.y();
553
+ return !!(node.c & LOADING_BIT);
459
554
  },
460
555
  options
461
556
  );
@@ -465,7 +560,7 @@ function loadingState(node) {
465
560
  }
466
561
  function track(computation) {
467
562
  if (currentObserver) {
468
- if (!newSources && currentObserver.g && currentObserver.g[newSourcesIndex] === computation) {
563
+ if (!newSources && currentObserver.f && currentObserver.f[newSourcesIndex] === computation) {
469
564
  newSourcesIndex++;
470
565
  } else if (!newSources)
471
566
  newSources = [computation];
@@ -473,7 +568,7 @@ function track(computation) {
473
568
  newSources.push(computation);
474
569
  }
475
570
  if (updateCheck) {
476
- updateCheck.c = computation.A > currentObserver.A;
571
+ updateCheck.b = computation.z > currentObserver.z;
477
572
  }
478
573
  }
479
574
  }
@@ -485,56 +580,56 @@ function update(node) {
485
580
  try {
486
581
  node.dispose(false);
487
582
  node.emptyDisposal();
488
- const result = compute(node, node.t, node);
583
+ const result = compute(node, node.u, node);
489
584
  node.write(result, newFlags, true);
490
585
  } catch (error) {
491
586
  if (error instanceof NotReadyError) {
492
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
587
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.c & UNINITIALIZED_BIT);
493
588
  } else {
494
- node.I(error);
589
+ node.J(error);
495
590
  }
496
591
  } finally {
497
592
  if (newSources) {
498
- if (node.g)
593
+ if (node.f)
499
594
  removeSourceObservers(node, newSourcesIndex);
500
- if (node.g && newSourcesIndex > 0) {
501
- node.g.length = newSourcesIndex + newSources.length;
595
+ if (node.f && newSourcesIndex > 0) {
596
+ node.f.length = newSourcesIndex + newSources.length;
502
597
  for (let i = 0; i < newSources.length; i++) {
503
- node.g[newSourcesIndex + i] = newSources[i];
598
+ node.f[newSourcesIndex + i] = newSources[i];
504
599
  }
505
600
  } else {
506
- node.g = newSources;
601
+ node.f = newSources;
507
602
  }
508
603
  let source;
509
- for (let i = newSourcesIndex; i < node.g.length; i++) {
510
- source = node.g[i];
511
- if (!source.e)
512
- source.e = [node];
604
+ for (let i = newSourcesIndex; i < node.f.length; i++) {
605
+ source = node.f[i];
606
+ if (!source.d)
607
+ source.d = [node];
513
608
  else
514
- source.e.push(node);
609
+ source.d.push(node);
515
610
  }
516
- } else if (node.g && newSourcesIndex < node.g.length) {
611
+ } else if (node.f && newSourcesIndex < node.f.length) {
517
612
  removeSourceObservers(node, newSourcesIndex);
518
- node.g.length = newSourcesIndex;
613
+ node.f.length = newSourcesIndex;
519
614
  }
520
615
  newSources = prevSources;
521
616
  newSourcesIndex = prevSourcesIndex;
522
617
  newFlags = prevFlags;
523
- node.A = clock + 1;
618
+ node.z = getClock() + 1;
524
619
  node.a = STATE_CLEAN;
525
620
  }
526
621
  }
527
622
  function removeSourceObservers(node, index) {
528
623
  let source;
529
624
  let swap;
530
- for (let i = index; i < node.g.length; i++) {
531
- source = node.g[i];
532
- if (source.e) {
533
- swap = source.e.indexOf(node);
534
- source.e[swap] = source.e[source.e.length - 1];
535
- source.e.pop();
536
- if (!source.e.length)
537
- source.T?.();
625
+ for (let i = index; i < node.f.length; i++) {
626
+ source = node.f[i];
627
+ if (source.d) {
628
+ swap = source.d.indexOf(node);
629
+ source.d[swap] = source.d[source.d.length - 1];
630
+ source.d.pop();
631
+ if (!source.d.length)
632
+ source.U?.();
538
633
  }
539
634
  }
540
635
  }
@@ -548,20 +643,20 @@ function untrack(fn) {
548
643
  }
549
644
  function hasUpdated(fn) {
550
645
  const current = updateCheck;
551
- updateCheck = { c: false };
646
+ updateCheck = { b: false };
552
647
  try {
553
648
  fn();
554
- return updateCheck.c;
649
+ return updateCheck.b;
555
650
  } finally {
556
651
  updateCheck = current;
557
652
  }
558
653
  }
559
654
  function isStale(fn) {
560
655
  const current = staleCheck;
561
- staleCheck = { c: false };
656
+ staleCheck = { b: false };
562
657
  try {
563
658
  latest(fn);
564
- return staleCheck.c;
659
+ return staleCheck.b;
565
660
  } catch {
566
661
  } finally {
567
662
  staleCheck = current;
@@ -594,7 +689,7 @@ function compute(owner, fn, observer) {
594
689
  currentMask = observer?.O ?? DEFAULT_FLAGS;
595
690
  notStale = true;
596
691
  try {
597
- return fn(observer ? observer.c : void 0);
692
+ return fn(observer ? observer.b : void 0);
598
693
  } finally {
599
694
  setOwner(prevOwner);
600
695
  currentObserver = prevObserver;
@@ -602,103 +697,13 @@ function compute(owner, fn, observer) {
602
697
  notStale = prevNotStale;
603
698
  }
604
699
  }
605
-
606
- // src/core/scheduler.ts
607
- var scheduled = false;
608
- function schedule() {
609
- if (scheduled)
610
- return;
611
- scheduled = true;
612
- if (!globalQueue.J)
613
- queueMicrotask(flushSync);
614
- }
615
- var Queue = class {
616
- J = false;
617
- u = [[], [], []];
618
- E = [];
619
- enqueue(type, node) {
620
- this.u[0].push(node);
621
- if (type)
622
- this.u[type].push(node);
623
- schedule();
624
- }
625
- run(type) {
626
- if (this.u[type].length) {
627
- if (type === EFFECT_PURE) {
628
- runPureQueue(this.u[type]);
629
- this.u[type] = [];
630
- } else {
631
- const effects = this.u[type];
632
- this.u[type] = [];
633
- runEffectQueue(effects);
634
- }
635
- }
636
- let rerun = false;
637
- for (let i = 0; i < this.E.length; i++) {
638
- rerun = this.E[i].run(type) || rerun;
639
- }
640
- if (type === EFFECT_PURE && this.u[type].length)
641
- return true;
642
- }
643
- flush() {
644
- if (this.J)
645
- return;
646
- this.J = true;
647
- try {
648
- while (this.run(EFFECT_PURE)) {
649
- }
650
- incrementClock();
651
- scheduled = false;
652
- this.run(EFFECT_RENDER);
653
- this.run(EFFECT_USER);
654
- } finally {
655
- this.J = false;
656
- }
657
- }
658
- addChild(child) {
659
- this.E.push(child);
660
- }
661
- removeChild(child) {
662
- const index = this.E.indexOf(child);
663
- if (index >= 0)
664
- this.E.splice(index, 1);
665
- }
666
- };
667
- var globalQueue = new Queue();
668
- function flushSync() {
669
- while (scheduled) {
670
- globalQueue.flush();
671
- }
672
- }
673
700
  function createBoundary(fn, queue) {
674
701
  const owner = new Owner();
675
- const parentQueue = owner.b || globalQueue;
676
- parentQueue.addChild(owner.b = queue);
677
- onCleanup(() => parentQueue.removeChild(owner.b));
702
+ const parentQueue = owner.h;
703
+ parentQueue.addChild(owner.h = queue);
704
+ onCleanup(() => parentQueue.removeChild(owner.h));
678
705
  return compute(owner, fn, null);
679
706
  }
680
- function runTop(node) {
681
- const ancestors = [];
682
- for (let current = node; current !== null; current = current.r) {
683
- if (current.a !== STATE_CLEAN) {
684
- ancestors.push(current);
685
- }
686
- }
687
- for (let i = ancestors.length - 1; i >= 0; i--) {
688
- if (ancestors[i].a !== STATE_DISPOSED)
689
- ancestors[i].x();
690
- }
691
- }
692
- function runPureQueue(queue) {
693
- for (let i = 0; i < queue.length; i++) {
694
- if (queue[i].a !== STATE_CLEAN)
695
- runTop(queue[i]);
696
- }
697
- }
698
- function runEffectQueue(queue) {
699
- for (let i = 0; i < queue.length; i++)
700
- queue[i].W();
701
- }
702
707
 
703
708
  // src/core/effect.ts
704
709
  var Effect = class extends Computation {
@@ -707,34 +712,32 @@ var Effect = class extends Computation {
707
712
  B;
708
713
  Q = false;
709
714
  M;
710
- y;
711
- b;
715
+ w;
712
716
  constructor(initialValue, compute2, effect, error, options) {
713
717
  super(initialValue, compute2, options);
714
718
  this.K = effect;
715
719
  this.L = error;
716
720
  this.M = initialValue;
717
- this.y = options?.render ? EFFECT_RENDER : EFFECT_USER;
718
- if (this.y === EFFECT_RENDER) {
719
- this.t = (p) => latest(() => compute2(p));
721
+ this.w = options?.render ? EFFECT_RENDER : EFFECT_USER;
722
+ if (this.w === EFFECT_RENDER) {
723
+ this.u = (p) => getClock() > this.h.created ? latest(() => compute2(p)) : compute2(p);
720
724
  }
721
- this.b = getOwner()?.b || globalQueue;
722
725
  if (!options?.defer) {
723
- this.x();
724
- this.y === EFFECT_USER ? this.b.enqueue(this.y, this) : this.W();
726
+ this.y();
727
+ this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.T();
725
728
  }
726
729
  }
727
730
  write(value, flags = 0) {
728
731
  if (this.a == STATE_DIRTY) {
729
- const currentFlags = this.d;
730
- this.d = flags;
731
- if (this.y === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
732
- this.b.R?.(this);
732
+ const currentFlags = this.c;
733
+ this.c = flags;
734
+ if (this.w === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
735
+ this.h.R?.(this);
733
736
  }
734
737
  }
735
738
  if (value === UNCHANGED)
736
- return this.c;
737
- this.c = value;
739
+ return this.b;
740
+ this.b = value;
738
741
  this.Q = true;
739
742
  return value;
740
743
  }
@@ -742,16 +745,16 @@ var Effect = class extends Computation {
742
745
  if (this.a >= state || skipQueue)
743
746
  return;
744
747
  if (this.a === STATE_CLEAN)
745
- this.b.enqueue(this.y, this);
748
+ this.h.enqueue(this.w, this);
746
749
  this.a = state;
747
750
  }
748
- I(error) {
751
+ J(error) {
749
752
  this.B?.();
750
- if (this.d & LOADING_BIT) {
751
- this.d = 0;
752
- this.b.R?.(this);
753
+ if (this.c & LOADING_BIT) {
754
+ this.c = 0;
755
+ this.h.R?.(this);
753
756
  }
754
- if (this.y === EFFECT_USER) {
757
+ if (this.w === EFFECT_USER) {
755
758
  try {
756
759
  return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
757
760
  } catch (e) {
@@ -760,7 +763,7 @@ var Effect = class extends Computation {
760
763
  }
761
764
  this.handleError(error);
762
765
  }
763
- z() {
766
+ A() {
764
767
  if (this.a === STATE_DISPOSED)
765
768
  return;
766
769
  this.K = void 0;
@@ -768,55 +771,51 @@ var Effect = class extends Computation {
768
771
  this.L = void 0;
769
772
  this.B?.();
770
773
  this.B = void 0;
771
- super.z();
774
+ super.A();
772
775
  }
773
- W() {
776
+ T() {
774
777
  if (this.Q && this.a !== STATE_DISPOSED) {
775
778
  this.B?.();
776
779
  try {
777
- this.B = this.K(this.c, this.M);
780
+ this.B = this.K(this.b, this.M);
778
781
  } catch (e) {
779
782
  this.handleError(e);
780
783
  } finally {
781
- this.M = this.c;
784
+ this.M = this.b;
782
785
  this.Q = false;
783
786
  }
784
787
  }
785
788
  }
786
789
  };
787
790
  var EagerComputation = class extends Computation {
788
- b;
789
791
  constructor(initialValue, compute2, options) {
790
792
  super(initialValue, compute2, options);
791
- this.b = getOwner()?.b || globalQueue;
792
- this.x();
793
+ !options?.defer && this.y();
793
794
  }
794
795
  q(state, skipQueue) {
795
- if (this.a >= state && !this.H)
796
+ if (this.a >= state && !this.I)
796
797
  return;
797
798
  if (this.a === STATE_CLEAN && !skipQueue)
798
- this.b.enqueue(EFFECT_PURE, this);
799
+ this.h.enqueue(EFFECT_PURE, this);
799
800
  super.q(state, skipQueue);
800
801
  }
801
802
  };
802
803
  var ProjectionComputation = class extends Computation {
803
- b;
804
804
  constructor(compute2) {
805
805
  super(null, compute2);
806
- this.b = getOwner()?.b || globalQueue;
807
806
  }
808
807
  q(state, skipQueue) {
809
- if (this.a >= state && !this.H)
808
+ if (this.a >= state && !this.I)
810
809
  return;
811
810
  if (this.a === STATE_CLEAN && !skipQueue)
812
- this.b.enqueue(EFFECT_PURE, this);
811
+ this.h.enqueue(EFFECT_PURE, this);
813
812
  super.q(state, true);
814
813
  }
815
814
  };
816
815
 
817
816
  // src/core/suspense.ts
818
817
  var SuspenseQueue = class extends Queue {
819
- f = /* @__PURE__ */ new Set();
818
+ e = /* @__PURE__ */ new Set();
820
819
  o = false;
821
820
  S = new Computation(false, null);
822
821
  run(type) {
@@ -825,15 +824,15 @@ var SuspenseQueue = class extends Queue {
825
824
  return super.run(type);
826
825
  }
827
826
  R(node) {
828
- if (node.d & LOADING_BIT) {
829
- this.f.add(node);
827
+ if (node.c & LOADING_BIT) {
828
+ this.e.add(node);
830
829
  if (!this.o) {
831
830
  this.o = true;
832
831
  this.S.write(true);
833
832
  }
834
833
  } else {
835
- this.f.delete(node);
836
- if (this.f.size === 0) {
834
+ this.e.delete(node);
835
+ if (this.e.size === 0) {
837
836
  this.o = false;
838
837
  this.S.write(false);
839
838
  }
@@ -842,12 +841,13 @@ var SuspenseQueue = class extends Queue {
842
841
  };
843
842
  var LiveComputation = class extends EagerComputation {
844
843
  write(value, flags = 0) {
845
- const currentFlags = this.d;
844
+ const currentFlags = this.c;
845
+ const dirty = this.a === STATE_DIRTY;
846
846
  super.write(value, flags);
847
- if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
848
- this.b.R?.(this);
847
+ if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
848
+ this.h.R?.(this);
849
849
  }
850
- return this.c;
850
+ return this.b;
851
851
  }
852
852
  };
853
853
  function createSuspense(fn, fallback) {
@@ -887,10 +887,10 @@ function createMemo(compute2, value, options) {
887
887
  return () => {
888
888
  if (node) {
889
889
  resolvedValue = node.wait();
890
- if (!node.g?.length && node.n?.r !== node) {
890
+ if (!node.f?.length && node.n?.s !== node) {
891
891
  node.dispose();
892
892
  node = void 0;
893
- } else if (!node.r && !node.e?.length) {
893
+ } else if (!node.s && !node.d?.length) {
894
894
  node.dispose();
895
895
  node.a = STATE_DIRTY;
896
896
  }
@@ -902,10 +902,10 @@ function createAsync(compute2, value, options) {
902
902
  let uninitialized = value === void 0;
903
903
  const lhs = new EagerComputation(
904
904
  {
905
- c: value
905
+ b: value
906
906
  },
907
907
  (p) => {
908
- const value2 = p?.c;
908
+ const value2 = p?.b;
909
909
  const source = compute2(value2);
910
910
  const isPromise = source instanceof Promise;
911
911
  const iterator = source[Symbol.asyncIterator];
@@ -914,13 +914,13 @@ function createAsync(compute2, value, options) {
914
914
  wait() {
915
915
  return source;
916
916
  },
917
- c: source
917
+ b: source
918
918
  };
919
919
  }
920
920
  const signal = new Computation(value2, null, options);
921
921
  const w = signal.wait;
922
922
  signal.wait = function() {
923
- if (signal.d & ERROR_BIT && signal.A <= getClock()) {
923
+ if (signal.c & ERROR_BIT && signal.z <= getClock()) {
924
924
  lhs.q(STATE_DIRTY);
925
925
  throw new NotReadyError();
926
926
  }
@@ -935,7 +935,7 @@ function createAsync(compute2, value, options) {
935
935
  },
936
936
  (error) => {
937
937
  uninitialized = true;
938
- signal.I(error);
938
+ signal.J(error);
939
939
  }
940
940
  );
941
941
  } else {
@@ -987,16 +987,31 @@ function runWithOwner(owner, run) {
987
987
  }
988
988
  function createErrorBoundary(fn, fallback) {
989
989
  const owner = new Owner();
990
- const error = new Computation(null, null);
991
- const reset = new Computation(null, null, { equals: false });
992
- const handler = (err) => error.write({ D: err });
990
+ const error = new Computation(void 0, null);
991
+ const nodes = /* @__PURE__ */ new Set();
992
+ function handler(err, node) {
993
+ if (nodes.has(node))
994
+ return;
995
+ compute(
996
+ node,
997
+ () => onCleanup(() => {
998
+ nodes.delete(node);
999
+ if (!nodes.size)
1000
+ error.write(void 0);
1001
+ }),
1002
+ null
1003
+ );
1004
+ nodes.add(node);
1005
+ if (nodes.size === 1)
1006
+ error.write({ E: err });
1007
+ }
993
1008
  owner.m = owner.m ? [handler, ...owner.m] : [handler];
994
1009
  const guarded = compute(
995
1010
  owner,
996
1011
  () => {
997
- const c = new Computation(null, () => (reset.read(), fn()));
998
- const f = new Computation(null, () => flatten(c.read()));
999
- f.I = function(error2) {
1012
+ const c = new Computation(void 0, fn);
1013
+ const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
1014
+ f.J = function(error2) {
1000
1015
  this.handleError(error2);
1001
1016
  };
1002
1017
  return f;
@@ -1009,24 +1024,29 @@ function createErrorBoundary(fn, fallback) {
1009
1024
  if (!error.read())
1010
1025
  return resolved;
1011
1026
  }
1012
- return fallback(error.read().D, () => {
1013
- error.write(null);
1014
- reset.write(null);
1027
+ return fallback(error.read().E, () => {
1028
+ incrementClock();
1029
+ for (let node of nodes) {
1030
+ node.a = STATE_DIRTY;
1031
+ node.h?.enqueue(node.w, node);
1032
+ }
1015
1033
  });
1016
1034
  });
1017
1035
  return decision.read.bind(decision);
1018
1036
  }
1019
1037
  function resolve(fn) {
1020
1038
  return new Promise((res, rej) => {
1021
- let node = new EagerComputation(void 0, () => {
1022
- try {
1023
- res(fn());
1024
- } catch (err) {
1025
- if (err instanceof NotReadyError)
1026
- throw err;
1027
- rej(err);
1028
- }
1029
- node.dispose(true);
1039
+ createRoot((dispose) => {
1040
+ new EagerComputation(void 0, () => {
1041
+ try {
1042
+ res(fn());
1043
+ } catch (err) {
1044
+ if (err instanceof NotReadyError)
1045
+ throw err;
1046
+ rej(err);
1047
+ }
1048
+ dispose();
1049
+ });
1030
1050
  });
1031
1051
  });
1032
1052
  }
@@ -1037,10 +1057,10 @@ function createReaction(effect, error, options) {
1037
1057
  ...void 0
1038
1058
  });
1039
1059
  return (tracking) => {
1040
- node.t = tracking;
1060
+ node.u = tracking;
1041
1061
  node.a = STATE_DIRTY;
1042
- node.x();
1043
- node.t = null;
1062
+ node.y();
1063
+ node.u = null;
1044
1064
  };
1045
1065
  }
1046
1066
 
@@ -1189,7 +1209,7 @@ var proxyTraps = {
1189
1209
  return desc.get.call(receiver);
1190
1210
  }
1191
1211
  if (Writing.has(storeValue)) {
1192
- const value2 = tracked ? tracked.c : storeValue[property];
1212
+ const value2 = tracked ? tracked.b : storeValue[property];
1193
1213
  return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
1194
1214
  }
1195
1215
  let value = tracked ? nodes[property].read() : storeValue[property];
@@ -1531,10 +1551,10 @@ function mapArray(list, map, options) {
1531
1551
  F: new Owner(),
1532
1552
  i: 0,
1533
1553
  X: list,
1534
- w: [],
1554
+ x: [],
1535
1555
  G: map,
1536
- h: [],
1537
- f: [],
1556
+ g: [],
1557
+ e: [],
1538
1558
  C: keyFn,
1539
1559
  j: keyFn || options?.keyed === false ? [] : void 0,
1540
1560
  k: map.length > 1 ? [] : void 0,
@@ -1563,38 +1583,38 @@ function updateKeyedMap() {
1563
1583
  if (newLen === 0) {
1564
1584
  if (this.i !== 0) {
1565
1585
  this.F.dispose(false);
1566
- this.f = [];
1567
- this.w = [];
1568
- this.h = [];
1586
+ this.e = [];
1587
+ this.x = [];
1588
+ this.g = [];
1569
1589
  this.i = 0;
1570
1590
  this.j && (this.j = []);
1571
1591
  this.k && (this.k = []);
1572
1592
  }
1573
- if (this.o && !this.h[0]) {
1574
- this.h[0] = compute(
1575
- this.f[0] = new Owner(),
1593
+ if (this.o && !this.g[0]) {
1594
+ this.g[0] = compute(
1595
+ this.e[0] = new Owner(),
1576
1596
  this.o,
1577
1597
  null
1578
1598
  );
1579
1599
  }
1580
1600
  } else if (this.i === 0) {
1581
- if (this.f[0])
1582
- this.f[0].dispose();
1583
- this.h = new Array(newLen);
1601
+ if (this.e[0])
1602
+ this.e[0].dispose();
1603
+ this.g = new Array(newLen);
1584
1604
  for (j = 0; j < newLen; j++) {
1585
- this.w[j] = newItems[j];
1586
- this.h[j] = compute(this.f[j] = new Owner(), mapper, null);
1605
+ this.x[j] = newItems[j];
1606
+ this.g[j] = compute(this.e[j] = new Owner(), mapper, null);
1587
1607
  }
1588
1608
  this.i = newLen;
1589
1609
  } else {
1590
1610
  let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
1591
- for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.C, this.w[start], newItems[start])); start++) {
1611
+ for (start = 0, end = Math.min(this.i, newLen); start < end && (this.x[start] === newItems[start] || this.j && compare(this.C, this.x[start], newItems[start])); start++) {
1592
1612
  if (this.j)
1593
1613
  this.j[start].write(newItems[start]);
1594
1614
  }
1595
- for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.C, this.w[end], newItems[newEnd])); end--, newEnd--) {
1596
- temp[newEnd] = this.h[end];
1597
- tempNodes[newEnd] = this.f[end];
1615
+ for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.x[end] === newItems[newEnd] || this.j && compare(this.C, this.x[end], newItems[newEnd])); end--, newEnd--) {
1616
+ temp[newEnd] = this.g[end];
1617
+ tempNodes[newEnd] = this.e[end];
1598
1618
  tempRows && (tempRows[newEnd] = this.j[end]);
1599
1619
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
1600
1620
  }
@@ -1608,23 +1628,23 @@ function updateKeyedMap() {
1608
1628
  newIndices.set(key, j);
1609
1629
  }
1610
1630
  for (i = start; i <= end; i++) {
1611
- item = this.w[i];
1631
+ item = this.x[i];
1612
1632
  key = this.C ? this.C(item) : item;
1613
1633
  j = newIndices.get(key);
1614
1634
  if (j !== void 0 && j !== -1) {
1615
- temp[j] = this.h[i];
1616
- tempNodes[j] = this.f[i];
1635
+ temp[j] = this.g[i];
1636
+ tempNodes[j] = this.e[i];
1617
1637
  tempRows && (tempRows[j] = this.j[i]);
1618
1638
  tempIndexes && (tempIndexes[j] = this.k[i]);
1619
1639
  j = newIndicesNext[j];
1620
1640
  newIndices.set(key, j);
1621
1641
  } else
1622
- this.f[i].dispose();
1642
+ this.e[i].dispose();
1623
1643
  }
1624
1644
  for (j = start; j < newLen; j++) {
1625
1645
  if (j in temp) {
1626
- this.h[j] = temp[j];
1627
- this.f[j] = tempNodes[j];
1646
+ this.g[j] = temp[j];
1647
+ this.e[j] = tempNodes[j];
1628
1648
  if (tempRows) {
1629
1649
  this.j[j] = tempRows[j];
1630
1650
  this.j[j].write(newItems[j]);
@@ -1634,14 +1654,14 @@ function updateKeyedMap() {
1634
1654
  this.k[j].write(j);
1635
1655
  }
1636
1656
  } else {
1637
- this.h[j] = compute(this.f[j] = new Owner(), mapper, null);
1657
+ this.g[j] = compute(this.e[j] = new Owner(), mapper, null);
1638
1658
  }
1639
1659
  }
1640
- this.h = this.h.slice(0, this.i = newLen);
1641
- this.w = newItems.slice(0);
1660
+ this.g = this.g.slice(0, this.i = newLen);
1661
+ this.x = newItems.slice(0);
1642
1662
  }
1643
1663
  });
1644
- return this.h;
1664
+ return this.g;
1645
1665
  }
1646
1666
  function repeat(count, map, options) {
1647
1667
  return updateRepeat.bind({
@@ -1649,8 +1669,8 @@ function repeat(count, map, options) {
1649
1669
  i: 0,
1650
1670
  Y: count,
1651
1671
  G: map,
1652
- f: [],
1653
- h: [],
1672
+ e: [],
1673
+ g: [],
1654
1674
  o: options?.fallback
1655
1675
  });
1656
1676
  }
@@ -1660,34 +1680,34 @@ function updateRepeat() {
1660
1680
  if (newLen === 0) {
1661
1681
  if (this.i !== 0) {
1662
1682
  this.F.dispose(false);
1663
- this.f = [];
1664
- this.h = [];
1683
+ this.e = [];
1684
+ this.g = [];
1665
1685
  this.i = 0;
1666
1686
  }
1667
- if (this.o && !this.h[0]) {
1668
- this.h[0] = compute(
1669
- this.f[0] = new Owner(),
1687
+ if (this.o && !this.g[0]) {
1688
+ this.g[0] = compute(
1689
+ this.e[0] = new Owner(),
1670
1690
  this.o,
1671
1691
  null
1672
1692
  );
1673
1693
  }
1674
1694
  } else {
1675
- if (this.i === 0 && this.f[0])
1676
- this.f[0].dispose();
1695
+ if (this.i === 0 && this.e[0])
1696
+ this.e[0].dispose();
1677
1697
  for (let i = this.i; i < newLen; i++) {
1678
- this.h[i] = compute(
1679
- this.f[i] = new Owner(),
1698
+ this.g[i] = compute(
1699
+ this.e[i] = new Owner(),
1680
1700
  () => this.G(i),
1681
1701
  null
1682
1702
  );
1683
1703
  }
1684
1704
  for (let i = newLen; i < this.i; i++)
1685
- this.f[i].dispose();
1686
- this.h = this.h.slice(0, newLen);
1705
+ this.e[i].dispose();
1706
+ this.g = this.g.slice(0, newLen);
1687
1707
  this.i = newLen;
1688
1708
  }
1689
1709
  });
1690
- return this.h;
1710
+ return this.g;
1691
1711
  }
1692
1712
  function compare(key, a, b) {
1693
1713
  return key ? key(a) === key(b) : true;