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