@solidjs/signals 0.3.0 → 0.3.1

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
@@ -43,11 +43,12 @@ function schedule() {
43
43
  if (scheduled)
44
44
  return;
45
45
  scheduled = true;
46
- if (!globalQueue.J)
46
+ if (!globalQueue.K)
47
47
  queueMicrotask(flushSync);
48
48
  }
49
49
  var Queue = class {
50
- J = false;
50
+ n = null;
51
+ K = false;
51
52
  s = [[], [], []];
52
53
  F = [];
53
54
  created = clock;
@@ -76,9 +77,9 @@ var Queue = class {
76
77
  return rerun || !!this.s[type].length;
77
78
  }
78
79
  flush() {
79
- if (this.J)
80
+ if (this.K)
80
81
  return;
81
- this.J = true;
82
+ this.K = true;
82
83
  try {
83
84
  while (this.run(EFFECT_PURE)) {
84
85
  }
@@ -87,17 +88,23 @@ var Queue = class {
87
88
  this.run(EFFECT_RENDER);
88
89
  this.run(EFFECT_USER);
89
90
  } finally {
90
- this.J = false;
91
+ this.K = false;
91
92
  }
92
93
  }
93
94
  addChild(child) {
94
95
  this.F.push(child);
96
+ child.n = this;
95
97
  }
96
98
  removeChild(child) {
97
99
  const index = this.F.indexOf(child);
98
100
  if (index >= 0)
99
101
  this.F.splice(index, 1);
100
102
  }
103
+ notify(...args) {
104
+ if (this.n)
105
+ return this.n.notify(...args);
106
+ return false;
107
+ }
101
108
  };
102
109
  var globalQueue = new Queue();
103
110
  function flushSync() {
@@ -107,14 +114,14 @@ function flushSync() {
107
114
  }
108
115
  function runTop(node) {
109
116
  const ancestors = [];
110
- for (let current = node; current !== null; current = current.x) {
117
+ for (let current = node; current !== null; current = current.n) {
111
118
  if (current.a !== STATE_CLEAN) {
112
119
  ancestors.push(current);
113
120
  }
114
121
  }
115
122
  for (let i = ancestors.length - 1; i >= 0; i--) {
116
123
  if (ancestors[i].a !== STATE_DISPOSED)
117
- ancestors[i].y();
124
+ ancestors[i].x();
118
125
  }
119
126
  }
120
127
  function runPureQueue(queue) {
@@ -125,7 +132,7 @@ function runPureQueue(queue) {
125
132
  }
126
133
  function runEffectQueue(queue) {
127
134
  for (let i = 0; i < queue.length; i++)
128
- queue[i].T();
135
+ queue[i].V();
129
136
  }
130
137
 
131
138
  // src/core/utils.ts
@@ -172,104 +179,80 @@ var Owner = class {
172
179
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
173
180
  // However, the children are actually added in reverse creation order
174
181
  // See comment at the top of the file for an example of the _nextSibling traversal
175
- x = null;
176
- l = null;
182
+ n = null;
183
+ m = null;
177
184
  t = null;
178
185
  a = STATE_CLEAN;
179
- m = null;
186
+ l = null;
180
187
  o = defaultContext;
181
- n = null;
182
188
  h = globalQueue;
183
- O = null;
184
- X = 0;
189
+ W = 0;
185
190
  id = null;
186
191
  constructor(id = null, skipAppend = false) {
187
192
  this.id = id;
188
- if (currentOwner && !skipAppend)
189
- currentOwner.append(this);
193
+ if (currentOwner) {
194
+ if (!id && currentOwner.id)
195
+ this.id = currentOwner.getNextChildId();
196
+ !skipAppend && currentOwner.append(this);
197
+ }
190
198
  }
191
199
  append(child) {
192
- child.x = this;
200
+ child.n = this;
193
201
  child.t = this;
194
- if (this.id) {
195
- child.O = this.l ? this.l.O + 1 : 0;
196
- child.id = formatId(this.id, child.O);
197
- }
198
- if (this.l)
199
- this.l.t = child;
200
- child.l = this.l;
201
- this.l = child;
202
+ if (this.m)
203
+ this.m.t = child;
204
+ child.m = this.m;
205
+ this.m = child;
202
206
  if (child.o !== this.o) {
203
207
  child.o = { ...this.o, ...child.o };
204
208
  }
205
- if (this.n) {
206
- child.n = !child.n ? this.n : [...child.n, ...this.n];
207
- }
208
209
  if (this.h)
209
210
  child.h = this.h;
210
211
  }
211
212
  dispose(self = true) {
212
213
  if (this.a === STATE_DISPOSED)
213
214
  return;
214
- let head = self ? this.t || this.x : this, current = this.l, next = null;
215
- while (current && current.x === this) {
215
+ let head = self ? this.t || this.n : this, current = this.m, next = null;
216
+ while (current && current.n === this) {
216
217
  current.dispose(true);
217
- current.z();
218
- next = current.l;
219
- current.l = null;
218
+ current.y();
219
+ next = current.m;
220
+ current.m = null;
220
221
  current = next;
221
222
  }
223
+ this.W = 0;
222
224
  if (self)
223
- this.z();
225
+ this.y();
224
226
  if (current)
225
227
  current.t = !self ? this : this.t;
226
228
  if (head)
227
- head.l = current;
229
+ head.m = current;
228
230
  }
229
- z() {
231
+ y() {
230
232
  if (this.t)
231
- this.t.l = null;
232
- this.x = null;
233
+ this.t.m = null;
234
+ this.n = null;
233
235
  this.t = null;
234
236
  this.o = defaultContext;
235
- this.n = null;
236
237
  this.a = STATE_DISPOSED;
237
238
  this.emptyDisposal();
238
239
  }
239
240
  emptyDisposal() {
240
- if (!this.m)
241
+ if (!this.l)
241
242
  return;
242
- if (Array.isArray(this.m)) {
243
- for (let i = 0; i < this.m.length; i++) {
244
- const callable = this.m[i];
243
+ if (Array.isArray(this.l)) {
244
+ for (let i = 0; i < this.l.length; i++) {
245
+ const callable = this.l[i];
245
246
  callable.call(callable);
246
247
  }
247
248
  } else {
248
- this.m.call(this.m);
249
- }
250
- this.m = null;
251
- }
252
- addErrorHandler(handler) {
253
- this.n = this.n ? [handler, ...this.n] : [handler];
254
- }
255
- handleError(error) {
256
- if (!this.n)
257
- throw error;
258
- let i = 0, len = this.n.length;
259
- for (i = 0; i < len; i++) {
260
- try {
261
- this.n[i](error, this);
262
- break;
263
- } catch (e) {
264
- error = e;
265
- }
249
+ this.l.call(this.l);
266
250
  }
267
- if (i === len)
268
- throw error;
251
+ this.l = null;
269
252
  }
270
253
  getNextChildId() {
271
254
  if (this.id)
272
- return formatId(this.id + "-", this.X++);
255
+ return formatId(this.id, this.W++);
273
256
  throw new Error("Cannot get child id from owner without an id");
274
257
  }
275
258
  };
@@ -302,12 +285,12 @@ function onCleanup(fn) {
302
285
  if (!currentOwner)
303
286
  return fn;
304
287
  const node = currentOwner;
305
- if (!node.m) {
306
- node.m = fn;
307
- } else if (Array.isArray(node.m)) {
308
- node.m.push(fn);
288
+ if (!node.l) {
289
+ node.l = fn;
290
+ } else if (Array.isArray(node.l)) {
291
+ node.l.push(fn);
309
292
  } else {
310
- node.m = [node.m, fn];
293
+ node.l = [node.l, fn];
311
294
  }
312
295
  return fn;
313
296
  }
@@ -336,43 +319,43 @@ function getObserver() {
336
319
  var UNCHANGED = Symbol(0);
337
320
  var Computation = class extends Owner {
338
321
  c = null;
339
- f = null;
322
+ e = null;
340
323
  g;
341
324
  G;
342
- A;
325
+ z;
343
326
  // Used in __DEV__ mode, hopefully removed in production
344
- $;
327
+ ba;
345
328
  // Using false is an optimization as an alternative to _equals: () => false
346
329
  // which could enable more efficient DIRTY notification
347
- P = isEqual;
348
- U;
330
+ S = isEqual;
331
+ X;
349
332
  /** Whether the computation is an error or has ancestors that are unresolved */
350
- d = 0;
333
+ f = 0;
351
334
  /** Which flags raised by sources are handled, vs. being passed through. */
352
- Q = DEFAULT_FLAGS;
353
- B = -1;
354
- K = false;
335
+ T = DEFAULT_FLAGS;
336
+ A = -1;
337
+ B = false;
355
338
  constructor(initialValue, compute2, options) {
356
339
  super(null, compute2 === null);
357
- this.A = compute2;
340
+ this.z = compute2;
358
341
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
359
- this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
342
+ this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
360
343
  this.g = initialValue;
361
344
  if (options?.equals !== void 0)
362
- this.P = options.equals;
345
+ this.S = options.equals;
363
346
  if (options?.unobserved)
364
- this.U = options?.unobserved;
347
+ this.X = options?.unobserved;
365
348
  }
366
- V() {
367
- if (this.A) {
368
- if (this.d & ERROR_BIT && this.B <= getClock())
349
+ Y() {
350
+ if (this.z) {
351
+ if (this.f & ERROR_BIT && this.A <= getClock())
369
352
  update(this);
370
353
  else
371
- this.y();
354
+ this.x();
372
355
  }
373
356
  track(this);
374
- newFlags |= this.d & ~currentMask;
375
- if (this.d & ERROR_BIT) {
357
+ newFlags |= this.f & ~currentMask;
358
+ if (this.f & ERROR_BIT) {
376
359
  throw this.G;
377
360
  } else {
378
361
  return this.g;
@@ -383,7 +366,7 @@ var Computation = class extends Owner {
383
366
  * Automatically re-executes the surrounding computation when the value changes
384
367
  */
385
368
  read() {
386
- return this.V();
369
+ return this.Y();
387
370
  }
388
371
  /**
389
372
  * Return the current value of this computation
@@ -393,37 +376,37 @@ var Computation = class extends Owner {
393
376
  * before continuing
394
377
  */
395
378
  wait() {
396
- if (this.A && this.d & ERROR_BIT && this.B <= getClock()) {
379
+ if (this.z && this.f & ERROR_BIT && this.A <= getClock()) {
397
380
  update(this);
398
381
  } else {
399
- this.y();
382
+ this.x();
400
383
  }
401
384
  track(this);
402
- if ((notStale || this.d & UNINITIALIZED_BIT) && this.d & LOADING_BIT) {
385
+ if ((notStale || this.f & UNINITIALIZED_BIT) && this.f & LOADING_BIT) {
403
386
  throw new NotReadyError();
404
387
  }
405
- if (staleCheck && this.d & LOADING_BIT) {
388
+ if (staleCheck && this.f & LOADING_BIT) {
406
389
  staleCheck.g = true;
407
390
  }
408
- return this.V();
391
+ return this.Y();
409
392
  }
410
393
  /** Update the computation with a new value. */
411
394
  write(value, flags = 0, raw = false) {
412
395
  const newValue = !raw && typeof value === "function" ? value(this.g) : value;
413
- const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.d & LOADING_BIT & ~flags || this.P === false || !this.P(this.g, newValue));
396
+ const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || this.f & LOADING_BIT & ~flags || this.S === false || !this.S(this.g, newValue));
414
397
  if (valueChanged) {
415
398
  this.g = newValue;
416
399
  this.G = void 0;
417
400
  }
418
- const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
419
- this.d = flags;
420
- this.B = getClock() + 1;
421
- if (this.f) {
422
- for (let i = 0; i < this.f.length; i++) {
401
+ const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
402
+ this.f = flags;
403
+ this.A = getClock() + 1;
404
+ if (this.e) {
405
+ for (let i = 0; i < this.e.length; i++) {
423
406
  if (valueChanged) {
424
- this.f[i].r(STATE_DIRTY);
407
+ this.e[i].r(STATE_DIRTY);
425
408
  } else if (changedFlagsMask) {
426
- this.f[i].W(changedFlagsMask, changedFlags);
409
+ this.e[i].Z(changedFlagsMask, changedFlags);
427
410
  }
428
411
  }
429
412
  }
@@ -433,13 +416,13 @@ var Computation = class extends Owner {
433
416
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
434
417
  */
435
418
  r(state, skipQueue) {
436
- if (this.a >= state && !this.K)
419
+ if (this.a >= state && !this.B)
437
420
  return;
438
- this.K = !!skipQueue;
421
+ this.B = !!skipQueue;
439
422
  this.a = state;
440
- if (this.f) {
441
- for (let i = 0; i < this.f.length; i++) {
442
- this.f[i].r(STATE_CHECK, skipQueue);
423
+ if (this.e) {
424
+ for (let i = 0; i < this.e.length; i++) {
425
+ this.e[i].r(STATE_CHECK, skipQueue);
443
426
  }
444
427
  }
445
428
  }
@@ -449,31 +432,31 @@ var Computation = class extends Owner {
449
432
  * @param mask A bitmask for which flag(s) were changed.
450
433
  * @param newFlags The source's new flags, masked to just the changed ones.
451
434
  */
452
- W(mask, newFlags2) {
435
+ Z(mask, newFlags2) {
453
436
  if (this.a >= STATE_DIRTY)
454
437
  return;
455
- if (mask & this.Q) {
438
+ if (mask & this.T) {
456
439
  this.r(STATE_DIRTY);
457
440
  return;
458
441
  }
459
442
  if (this.a >= STATE_CHECK)
460
443
  return;
461
- const prevFlags = this.d & mask;
444
+ const prevFlags = this.f & mask;
462
445
  const deltaFlags = prevFlags ^ newFlags2;
463
446
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
464
447
  this.r(STATE_CHECK);
465
448
  } else {
466
- this.d ^= deltaFlags;
467
- if (this.f) {
468
- for (let i = 0; i < this.f.length; i++) {
469
- this.f[i].W(mask, newFlags2);
449
+ this.f ^= deltaFlags;
450
+ if (this.e) {
451
+ for (let i = 0; i < this.e.length; i++) {
452
+ this.e[i].Z(mask, newFlags2);
470
453
  }
471
454
  }
472
455
  }
473
456
  }
474
- H(error) {
457
+ L(error) {
475
458
  this.G = error;
476
- this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
459
+ this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
477
460
  }
478
461
  /**
479
462
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -482,8 +465,8 @@ var Computation = class extends Owner {
482
465
  *
483
466
  * This function will ensure that the value and states we read from the computation are up to date
484
467
  */
485
- y() {
486
- if (!this.A) {
468
+ x() {
469
+ if (!this.z) {
487
470
  return;
488
471
  }
489
472
  if (this.a === STATE_DISPOSED) {
@@ -495,8 +478,8 @@ var Computation = class extends Owner {
495
478
  let observerFlags = 0;
496
479
  if (this.a === STATE_CHECK) {
497
480
  for (let i = 0; i < this.c.length; i++) {
498
- this.c[i].y();
499
- observerFlags |= this.c[i].d;
481
+ this.c[i].x();
482
+ observerFlags |= this.c[i].f;
500
483
  if (this.a === STATE_DIRTY) {
501
484
  break;
502
485
  }
@@ -512,12 +495,12 @@ var Computation = class extends Owner {
512
495
  /**
513
496
  * Remove ourselves from the owner graph and the computation graph
514
497
  */
515
- z() {
498
+ y() {
516
499
  if (this.a === STATE_DISPOSED)
517
500
  return;
518
501
  if (this.c)
519
502
  removeSourceObservers(this, 0);
520
- super.z();
503
+ super.y();
521
504
  }
522
505
  };
523
506
  function track(computation) {
@@ -530,7 +513,7 @@ function track(computation) {
530
513
  newSources.push(computation);
531
514
  }
532
515
  if (updateCheck) {
533
- updateCheck.g = computation.B > currentObserver.B;
516
+ updateCheck.g = computation.A > currentObserver.A;
534
517
  }
535
518
  }
536
519
  }
@@ -542,13 +525,13 @@ function update(node) {
542
525
  try {
543
526
  node.dispose(false);
544
527
  node.emptyDisposal();
545
- const result = compute(node, node.A, node);
528
+ const result = compute(node, node.z, node);
546
529
  node.write(result, newFlags, true);
547
530
  } catch (error) {
548
531
  if (error instanceof NotReadyError) {
549
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
532
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
550
533
  } else {
551
- node.H(error);
534
+ node.L(error);
552
535
  }
553
536
  } finally {
554
537
  if (newSources) {
@@ -565,10 +548,10 @@ function update(node) {
565
548
  let source;
566
549
  for (let i = newSourcesIndex; i < node.c.length; i++) {
567
550
  source = node.c[i];
568
- if (!source.f)
569
- source.f = [node];
551
+ if (!source.e)
552
+ source.e = [node];
570
553
  else
571
- source.f.push(node);
554
+ source.e.push(node);
572
555
  }
573
556
  } else if (node.c && newSourcesIndex < node.c.length) {
574
557
  removeSourceObservers(node, newSourcesIndex);
@@ -577,7 +560,7 @@ function update(node) {
577
560
  newSources = prevSources;
578
561
  newSourcesIndex = prevSourcesIndex;
579
562
  newFlags = prevFlags;
580
- node.B = getClock() + 1;
563
+ node.A = getClock() + 1;
581
564
  node.a = STATE_CLEAN;
582
565
  }
583
566
  }
@@ -586,12 +569,12 @@ function removeSourceObservers(node, index) {
586
569
  let swap;
587
570
  for (let i = index; i < node.c.length; i++) {
588
571
  source = node.c[i];
589
- if (source.f) {
590
- swap = source.f.indexOf(node);
591
- source.f[swap] = source.f[source.f.length - 1];
592
- source.f.pop();
593
- if (!source.f.length)
594
- source.U?.();
572
+ if (source.e) {
573
+ swap = source.e.indexOf(node);
574
+ source.e[swap] = source.e[source.e.length - 1];
575
+ source.e.pop();
576
+ if (!source.e.length)
577
+ source.X?.();
595
578
  }
596
579
  }
597
580
  }
@@ -633,7 +616,7 @@ function isPending(fn, loadingValue) {
633
616
  if (!currentObserver)
634
617
  return pendingCheck(fn, loadingValue);
635
618
  const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
636
- c.Q |= LOADING_BIT;
619
+ c.T |= LOADING_BIT;
637
620
  return c.read();
638
621
  }
639
622
  function latest(fn, fallback) {
@@ -663,10 +646,10 @@ function runWithObserver(observer, run) {
663
646
  if (error instanceof NotReadyError) {
664
647
  observer.write(
665
648
  UNCHANGED,
666
- newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
649
+ newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
667
650
  );
668
651
  } else {
669
- observer.H(error);
652
+ observer.L(error);
670
653
  }
671
654
  } finally {
672
655
  if (newSources) {
@@ -681,10 +664,10 @@ function runWithObserver(observer, run) {
681
664
  let source;
682
665
  for (let i = newSourcesIndex; i < observer.c.length; i++) {
683
666
  source = observer.c[i];
684
- if (!source.f)
685
- source.f = [observer];
667
+ if (!source.e)
668
+ source.e = [observer];
686
669
  else
687
- source.f.push(observer);
670
+ source.e.push(observer);
688
671
  }
689
672
  }
690
673
  newSources = prevSources;
@@ -695,7 +678,7 @@ function runWithObserver(observer, run) {
695
678
  function compute(owner, fn, observer) {
696
679
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
697
680
  currentObserver = observer;
698
- currentMask = observer?.Q ?? DEFAULT_FLAGS;
681
+ currentMask = observer?.T ?? DEFAULT_FLAGS;
699
682
  notStale = true;
700
683
  try {
701
684
  return fn(observer ? observer.g : void 0);
@@ -771,36 +754,36 @@ function flattenArray(children, results = [], options) {
771
754
 
772
755
  // src/core/effect.ts
773
756
  var Effect = class extends Computation {
774
- L;
775
757
  M;
776
- C;
777
- R = false;
778
758
  N;
759
+ C;
760
+ U = false;
761
+ O;
779
762
  u;
780
763
  constructor(initialValue, compute2, effect, error, options) {
781
764
  super(initialValue, compute2, options);
782
- this.L = effect;
783
- this.M = error;
784
- this.N = initialValue;
765
+ this.M = effect;
766
+ this.N = error;
767
+ this.O = initialValue;
785
768
  this.u = options?.render ? EFFECT_RENDER : EFFECT_USER;
786
769
  if (this.u === EFFECT_RENDER) {
787
- this.A = (p) => getClock() > this.h.created && !(this.d & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
770
+ this.z = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
788
771
  }
789
- this.y();
790
- !options?.defer && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
772
+ this.x();
773
+ !options?.defer && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.V());
791
774
  }
792
775
  write(value, flags = 0) {
793
776
  if (this.a == STATE_DIRTY) {
794
- const currentFlags = this.d;
795
- this.d = flags;
796
- if (this.u === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
797
- this.h.S?.(this);
777
+ this.f;
778
+ this.f = flags;
779
+ if (this.u === EFFECT_RENDER) {
780
+ this.h.notify(this, LOADING_BIT | ERROR_BIT, flags);
798
781
  }
799
782
  }
800
783
  if (value === UNCHANGED)
801
784
  return this.g;
802
785
  this.g = value;
803
- this.R = true;
786
+ this.U = true;
804
787
  return value;
805
788
  }
806
789
  r(state, skipQueue) {
@@ -810,41 +793,42 @@ var Effect = class extends Computation {
810
793
  this.h.enqueue(this.u, this);
811
794
  this.a = state;
812
795
  }
813
- H(error) {
796
+ L(error) {
797
+ this.G = error;
814
798
  this.C?.();
815
- if (this.d & LOADING_BIT) {
816
- this.h.S?.(this);
817
- }
818
- this.d = ERROR_BIT;
799
+ this.h.notify(this, LOADING_BIT, 0);
800
+ this.f = ERROR_BIT;
819
801
  if (this.u === EFFECT_USER) {
820
802
  try {
821
- return this.M ? this.C = this.M(error) : console.error(new EffectError(this.L, error));
803
+ return this.N ? this.C = this.N(error) : console.error(new EffectError(this.M, error));
822
804
  } catch (e) {
823
805
  error = e;
824
806
  }
825
807
  }
826
- this.handleError(error);
808
+ if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
809
+ throw error;
827
810
  }
828
- z() {
811
+ y() {
829
812
  if (this.a === STATE_DISPOSED)
830
813
  return;
831
- this.L = void 0;
832
- this.N = void 0;
833
814
  this.M = void 0;
815
+ this.O = void 0;
816
+ this.N = void 0;
834
817
  this.C?.();
835
818
  this.C = void 0;
836
- super.z();
819
+ super.y();
837
820
  }
838
- T() {
839
- if (this.R && this.a !== STATE_DISPOSED) {
821
+ V() {
822
+ if (this.U && this.a !== STATE_DISPOSED) {
840
823
  this.C?.();
841
824
  try {
842
- this.C = this.L(this.g, this.N);
825
+ this.C = this.M(this.g, this.O);
843
826
  } catch (e) {
844
- this.handleError(e);
827
+ if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
828
+ throw e;
845
829
  } finally {
846
- this.N = this.g;
847
- this.R = false;
830
+ this.O = this.g;
831
+ this.U = false;
848
832
  }
849
833
  }
850
834
  }
@@ -852,10 +836,10 @@ var Effect = class extends Computation {
852
836
  var EagerComputation = class extends Computation {
853
837
  constructor(initialValue, compute2, options) {
854
838
  super(initialValue, compute2, options);
855
- !options?.defer && this.y();
839
+ !options?.defer && this.x();
856
840
  }
857
841
  r(state, skipQueue) {
858
- if (this.a >= state && !this.K)
842
+ if (this.a >= state && !this.B)
859
843
  return;
860
844
  if (this.a === STATE_CLEAN && !skipQueue)
861
845
  this.h.enqueue(EFFECT_PURE, this);
@@ -867,51 +851,82 @@ var ProjectionComputation = class extends Computation {
867
851
  super(void 0, compute2);
868
852
  }
869
853
  r(state, skipQueue) {
870
- if (this.a >= state && !this.K)
854
+ if (this.a >= state && !this.B)
871
855
  return;
872
- if (this.a === STATE_CLEAN && !skipQueue)
856
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.B))
873
857
  this.h.enqueue(EFFECT_PURE, this);
874
858
  super.r(state, true);
859
+ this.B = !!skipQueue;
875
860
  }
876
861
  };
877
862
 
878
863
  // src/core/boundaries.ts
879
- function createBoundary(owner, fn, queue) {
880
- if (queue) {
881
- const parentQueue = owner.h;
882
- parentQueue.addChild(owner.h = queue);
883
- onCleanup(() => parentQueue.removeChild(owner.h));
864
+ var BoundaryComputation = class extends EagerComputation {
865
+ H;
866
+ constructor(compute2, propagationMask) {
867
+ super(void 0, compute2, { defer: true });
868
+ this.H = propagationMask;
869
+ }
870
+ write(value, flags) {
871
+ super.write(value, flags & ~this.H);
872
+ if (this.H & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
873
+ flags &= ~LOADING_BIT;
874
+ }
875
+ this.h.notify(this, this.H, flags);
876
+ return this.g;
884
877
  }
878
+ };
879
+ function createBoundChildren(owner, fn, queue, mask) {
880
+ const parentQueue = owner.h;
881
+ parentQueue.addChild(owner.h = queue);
882
+ onCleanup(() => parentQueue.removeChild(owner.h));
885
883
  return compute(
886
884
  owner,
887
885
  () => {
888
886
  const c = new Computation(void 0, fn);
889
- return new EagerComputation(void 0, () => flatten(c.wait()), { defer: true });
887
+ return new BoundaryComputation(() => flatten(c.wait()), mask);
890
888
  },
891
889
  null
892
890
  );
893
891
  }
894
- function createDecision(main, condition, fallback) {
895
- const decision = new Computation(void 0, () => {
896
- if (!condition.read()) {
897
- const resolved = main.read();
898
- if (!condition.read())
899
- return resolved;
900
- }
901
- return fallback();
902
- });
903
- return decision.read.bind(decision);
904
- }
905
- var SuspenseQueue = class extends Queue {
906
- b = /* @__PURE__ */ new Set();
907
- p = new Computation(false, null);
892
+ var ConditionalQueue = class extends Queue {
893
+ p;
894
+ P = /* @__PURE__ */ new Set();
895
+ Q = /* @__PURE__ */ new Set();
896
+ constructor(disabled) {
897
+ super();
898
+ this.p = disabled;
899
+ }
908
900
  run(type) {
909
901
  if (type && this.p.read())
910
902
  return;
911
903
  return super.run(type);
912
904
  }
913
- S(node) {
914
- if (node.d & LOADING_BIT) {
905
+ notify(node, type, flags) {
906
+ if (this.p.read()) {
907
+ if (type === LOADING_BIT) {
908
+ flags & LOADING_BIT ? this.Q.add(node) : this.Q.delete(node);
909
+ }
910
+ if (type === ERROR_BIT) {
911
+ flags & ERROR_BIT ? this.P.add(node) : this.P.delete(node);
912
+ }
913
+ return true;
914
+ }
915
+ return super.notify(node, type, flags);
916
+ }
917
+ };
918
+ var CollectionQueue = class extends Queue {
919
+ R;
920
+ b = /* @__PURE__ */ new Set();
921
+ p = new Computation(false, null);
922
+ constructor(type) {
923
+ super();
924
+ this.R = type;
925
+ }
926
+ notify(node, type, flags) {
927
+ if (!(type & this.R))
928
+ return super.notify(node, type, flags);
929
+ if (flags & this.R) {
915
930
  this.b.add(node);
916
931
  if (this.b.size === 1)
917
932
  this.p.write(true);
@@ -920,53 +935,50 @@ var SuspenseQueue = class extends Queue {
920
935
  if (this.b.size === 0)
921
936
  this.p.write(false);
922
937
  }
938
+ type &= ~this.R;
939
+ return type ? super.notify(node, type, flags) : true;
923
940
  }
924
941
  };
925
- function createSuspense(fn, fallback) {
942
+ function createBoundary(fn, condition) {
926
943
  const owner = new Owner();
927
- const queue = new SuspenseQueue();
928
- const tree = createBoundary(owner, fn, queue);
929
- const ogWrite = tree.write;
930
- tree.write = function(value, flags = 0) {
931
- const currentFlags = this.d;
932
- const dirty = this.a === STATE_DIRTY;
933
- ogWrite.call(this, value, flags);
934
- if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
935
- this.h.S?.(this);
944
+ const queue = new ConditionalQueue(new Computation(void 0, () => condition() === "hidden" /* HIDDEN */));
945
+ const tree = createBoundChildren(owner, fn, queue, 0);
946
+ new EagerComputation(void 0, () => {
947
+ const disabled = queue.p.read();
948
+ tree.H = disabled ? ERROR_BIT | LOADING_BIT : 0;
949
+ if (!disabled) {
950
+ queue.Q.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
951
+ queue.P.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
952
+ queue.Q.clear();
953
+ queue.P.clear();
936
954
  }
937
- return this.g;
938
- };
939
- return createDecision(tree, queue.p, fallback);
955
+ });
956
+ return () => queue.p.read() ? void 0 : tree.read();
940
957
  }
941
- function createErrorBoundary(fn, fallback) {
958
+ function createCollectionBoundary(type, fn, fallback) {
942
959
  const owner = new Owner();
943
- const error = new Computation(void 0, null);
944
- const nodes = /* @__PURE__ */ new Set();
945
- function handler(err, node) {
946
- if (nodes.has(node))
947
- return;
948
- compute(
949
- node,
950
- () => onCleanup(() => {
951
- nodes.delete(node);
952
- if (!nodes.size)
953
- error.write(void 0);
954
- }),
955
- null
956
- );
957
- nodes.add(node);
958
- if (nodes.size === 1)
959
- error.write({ G: err });
960
- }
961
- owner.addErrorHandler(handler);
962
- const tree = createBoundary(owner, fn);
963
- tree.H = tree.handleError;
964
- return createDecision(
965
- tree,
966
- error,
967
- () => fallback(error.read().G, () => {
960
+ const queue = new CollectionQueue(type);
961
+ const tree = createBoundChildren(owner, fn, queue, type);
962
+ const decision = new Computation(void 0, () => {
963
+ if (!queue.p.read()) {
964
+ const resolved = tree.read();
965
+ if (!queue.p.read())
966
+ return resolved;
967
+ }
968
+ return fallback(queue);
969
+ });
970
+ return decision.read.bind(decision);
971
+ }
972
+ function createSuspense(fn, fallback) {
973
+ return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
974
+ }
975
+ function createErrorBoundary(fn, fallback) {
976
+ return createCollectionBoundary(
977
+ ERROR_BIT,
978
+ fn,
979
+ (queue) => fallback(queue.b.values().next().value.G, () => {
968
980
  incrementClock();
969
- for (let node of nodes) {
981
+ for (let node of queue.b) {
970
982
  node.a = STATE_DIRTY;
971
983
  node.h?.enqueue(node.u, node);
972
984
  }
@@ -1004,7 +1016,7 @@ function createMemo(compute2, value, options) {
1004
1016
  return resolvedValue;
1005
1017
  }
1006
1018
  resolvedValue = node.wait();
1007
- if (!node.c?.length && node.l?.x !== node) {
1019
+ if (!node.c?.length && node.m?.n !== node) {
1008
1020
  node.dispose();
1009
1021
  node = void 0;
1010
1022
  }
@@ -1034,7 +1046,7 @@ function createAsync(compute2, value, options) {
1034
1046
  (error) => {
1035
1047
  if (abort)
1036
1048
  return;
1037
- node.H(error);
1049
+ node.L(error);
1038
1050
  }
1039
1051
  );
1040
1052
  } else {
@@ -1225,7 +1237,7 @@ function ownKeys(target) {
1225
1237
  trackSelf(target);
1226
1238
  return Reflect.ownKeys(target[STORE_VALUE]);
1227
1239
  }
1228
- var Writing = /* @__PURE__ */ new Set();
1240
+ var Writing = null;
1229
1241
  var proxyTraps = {
1230
1242
  get(target, property, receiver) {
1231
1243
  if (property === $TARGET)
@@ -1246,7 +1258,7 @@ var proxyTraps = {
1246
1258
  if (desc && desc.get)
1247
1259
  return desc.get.call(receiver);
1248
1260
  }
1249
- if (Writing.has(storeValue)) {
1261
+ if (Writing?.has(storeValue)) {
1250
1262
  const value2 = tracked ? tracked.g : storeValue[property];
1251
1263
  return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
1252
1264
  }
@@ -1269,11 +1281,11 @@ var proxyTraps = {
1269
1281
  return has;
1270
1282
  },
1271
1283
  set(target, property, value) {
1272
- Writing.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, unwrap(value, false));
1284
+ Writing?.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, unwrap(value, false));
1273
1285
  return true;
1274
1286
  },
1275
1287
  deleteProperty(target, property) {
1276
- Writing.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, void 0, true);
1288
+ Writing?.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, void 0, true);
1277
1289
  return true;
1278
1290
  },
1279
1291
  ownKeys,
@@ -1356,11 +1368,14 @@ function createStore(first, second) {
1356
1368
  const unwrappedStore = unwrap(store);
1357
1369
  let wrappedStore = wrap2(unwrappedStore);
1358
1370
  const setStore = (fn) => {
1371
+ const prevWriting = Writing;
1372
+ Writing = /* @__PURE__ */ new Set();
1373
+ Writing.add(unwrappedStore);
1359
1374
  try {
1360
- Writing.add(unwrappedStore);
1361
1375
  fn(wrappedStore);
1362
1376
  } finally {
1363
1377
  Writing.clear();
1378
+ Writing = prevWriting;
1364
1379
  }
1365
1380
  };
1366
1381
  if (derived)
@@ -1638,19 +1653,19 @@ function mapArray(list, map, options) {
1638
1653
  return updateKeyedMap.bind({
1639
1654
  I: new Owner(),
1640
1655
  i: 0,
1641
- Y: list,
1656
+ _: list,
1642
1657
  w: [],
1643
1658
  D: map,
1644
- e: [],
1659
+ d: [],
1645
1660
  b: [],
1646
1661
  E: keyFn,
1647
1662
  j: keyFn || options?.keyed === false ? [] : void 0,
1648
1663
  k: map.length > 1 ? [] : void 0,
1649
- p: options?.fallback
1664
+ J: options?.fallback
1650
1665
  });
1651
1666
  }
1652
1667
  function updateKeyedMap() {
1653
- const newItems = this.Y() || [], newLen = newItems.length;
1668
+ const newItems = this._() || [], newLen = newItems.length;
1654
1669
  newItems[$TRACK];
1655
1670
  runWithOwner(this.I, () => {
1656
1671
  let i, j, mapper = this.j ? () => {
@@ -1673,25 +1688,25 @@ function updateKeyedMap() {
1673
1688
  this.I.dispose(false);
1674
1689
  this.b = [];
1675
1690
  this.w = [];
1676
- this.e = [];
1691
+ this.d = [];
1677
1692
  this.i = 0;
1678
1693
  this.j && (this.j = []);
1679
1694
  this.k && (this.k = []);
1680
1695
  }
1681
- if (this.p && !this.e[0]) {
1682
- this.e[0] = compute(
1696
+ if (this.J && !this.d[0]) {
1697
+ this.d[0] = compute(
1683
1698
  this.b[0] = new Owner(),
1684
- this.p,
1699
+ this.J,
1685
1700
  null
1686
1701
  );
1687
1702
  }
1688
1703
  } else if (this.i === 0) {
1689
1704
  if (this.b[0])
1690
1705
  this.b[0].dispose();
1691
- this.e = new Array(newLen);
1706
+ this.d = new Array(newLen);
1692
1707
  for (j = 0; j < newLen; j++) {
1693
1708
  this.w[j] = newItems[j];
1694
- this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1709
+ this.d[j] = compute(this.b[j] = new Owner(), mapper, null);
1695
1710
  }
1696
1711
  this.i = newLen;
1697
1712
  } else {
@@ -1701,7 +1716,7 @@ function updateKeyedMap() {
1701
1716
  this.j[start].write(newItems[start]);
1702
1717
  }
1703
1718
  for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.E, this.w[end], newItems[newEnd])); end--, newEnd--) {
1704
- temp[newEnd] = this.e[end];
1719
+ temp[newEnd] = this.d[end];
1705
1720
  tempNodes[newEnd] = this.b[end];
1706
1721
  tempRows && (tempRows[newEnd] = this.j[end]);
1707
1722
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
@@ -1720,7 +1735,7 @@ function updateKeyedMap() {
1720
1735
  key = this.E ? this.E(item) : item;
1721
1736
  j = newIndices.get(key);
1722
1737
  if (j !== void 0 && j !== -1) {
1723
- temp[j] = this.e[i];
1738
+ temp[j] = this.d[i];
1724
1739
  tempNodes[j] = this.b[i];
1725
1740
  tempRows && (tempRows[j] = this.j[i]);
1726
1741
  tempIndexes && (tempIndexes[j] = this.k[i]);
@@ -1731,7 +1746,7 @@ function updateKeyedMap() {
1731
1746
  }
1732
1747
  for (j = start; j < newLen; j++) {
1733
1748
  if (j in temp) {
1734
- this.e[j] = temp[j];
1749
+ this.d[j] = temp[j];
1735
1750
  this.b[j] = tempNodes[j];
1736
1751
  if (tempRows) {
1737
1752
  this.j[j] = tempRows[j];
@@ -1742,43 +1757,43 @@ function updateKeyedMap() {
1742
1757
  this.k[j].write(j);
1743
1758
  }
1744
1759
  } else {
1745
- this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1760
+ this.d[j] = compute(this.b[j] = new Owner(), mapper, null);
1746
1761
  }
1747
1762
  }
1748
- this.e = this.e.slice(0, this.i = newLen);
1763
+ this.d = this.d.slice(0, this.i = newLen);
1749
1764
  this.w = newItems.slice(0);
1750
1765
  }
1751
1766
  });
1752
- return this.e;
1767
+ return this.d;
1753
1768
  }
1754
1769
  function repeat(count, map, options) {
1755
1770
  return updateRepeat.bind({
1756
1771
  I: new Owner(),
1757
1772
  i: 0,
1758
1773
  q: 0,
1759
- Z: count,
1774
+ $: count,
1760
1775
  D: map,
1761
1776
  b: [],
1762
- e: [],
1763
- _: options?.from,
1764
- p: options?.fallback
1777
+ d: [],
1778
+ aa: options?.from,
1779
+ J: options?.fallback
1765
1780
  });
1766
1781
  }
1767
1782
  function updateRepeat() {
1768
- const newLen = this.Z();
1769
- const from = this._?.() || 0;
1783
+ const newLen = this.$();
1784
+ const from = this.aa?.() || 0;
1770
1785
  runWithOwner(this.I, () => {
1771
1786
  if (newLen === 0) {
1772
1787
  if (this.i !== 0) {
1773
1788
  this.I.dispose(false);
1774
1789
  this.b = [];
1775
- this.e = [];
1790
+ this.d = [];
1776
1791
  this.i = 0;
1777
1792
  }
1778
- if (this.p && !this.e[0]) {
1779
- this.e[0] = compute(
1793
+ if (this.J && !this.d[0]) {
1794
+ this.d[0] = compute(
1780
1795
  this.b[0] = new Owner(),
1781
- this.p,
1796
+ this.J,
1782
1797
  null
1783
1798
  );
1784
1799
  }
@@ -1795,18 +1810,18 @@ function updateRepeat() {
1795
1810
  while (i < from && i < this.i)
1796
1811
  this.b[i++].dispose();
1797
1812
  this.b.splice(0, from - this.q);
1798
- this.e.splice(0, from - this.q);
1813
+ this.d.splice(0, from - this.q);
1799
1814
  } else if (this.q > from) {
1800
1815
  let i = prevTo - this.q - 1;
1801
1816
  let difference = this.q - from;
1802
- this.b.length = this.e.length = newLen;
1817
+ this.b.length = this.d.length = newLen;
1803
1818
  while (i >= difference) {
1804
1819
  this.b[i] = this.b[i - difference];
1805
- this.e[i] = this.e[i - difference];
1820
+ this.d[i] = this.d[i - difference];
1806
1821
  i--;
1807
1822
  }
1808
1823
  for (let i2 = 0; i2 < difference; i2++) {
1809
- this.e[i2] = compute(
1824
+ this.d[i2] = compute(
1810
1825
  this.b[i2] = new Owner(),
1811
1826
  () => this.D(i2 + from),
1812
1827
  null
@@ -1814,20 +1829,20 @@ function updateRepeat() {
1814
1829
  }
1815
1830
  }
1816
1831
  for (let i = prevTo; i < to; i++) {
1817
- this.e[i - from] = compute(
1832
+ this.d[i - from] = compute(
1818
1833
  this.b[i - from] = new Owner(),
1819
1834
  () => this.D(i),
1820
1835
  null
1821
1836
  );
1822
1837
  }
1823
- this.e = this.e.slice(0, newLen);
1838
+ this.d = this.d.slice(0, newLen);
1824
1839
  this.q = from;
1825
1840
  this.i = newLen;
1826
1841
  });
1827
- return this.e;
1842
+ return this.d;
1828
1843
  }
1829
1844
  function compare(key, a, b) {
1830
1845
  return key ? key(a) === key(b) : true;
1831
1846
  }
1832
1847
 
1833
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, tryCatch, untrack, unwrap };
1848
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, tryCatch, untrack, unwrap };