@solidjs/signals 0.3.2 → 0.4.0

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
@@ -13,12 +13,6 @@ var ContextNotFoundError = class extends Error {
13
13
  );
14
14
  }
15
15
  };
16
- var EffectError = class extends Error {
17
- constructor(effect, cause) {
18
- super("");
19
- this.cause = cause;
20
- }
21
- };
22
16
 
23
17
  // src/core/constants.ts
24
18
  var STATE_CLEAN = 0;
@@ -44,7 +38,7 @@ function schedule() {
44
38
  return;
45
39
  scheduled = true;
46
40
  if (!globalQueue.J)
47
- queueMicrotask(flushSync);
41
+ queueMicrotask(flush);
48
42
  }
49
43
  var pureQueue = [];
50
44
  var Queue = class {
@@ -53,21 +47,21 @@ var Queue = class {
53
47
  K = [[], []];
54
48
  E = [];
55
49
  created = clock;
56
- enqueue(type, node) {
57
- pureQueue.push(node);
50
+ enqueue(type, fn) {
51
+ pureQueue.push(fn);
58
52
  if (type)
59
- this.K[type - 1].push(node);
53
+ this.K[type - 1].push(fn);
60
54
  schedule();
61
55
  }
62
56
  run(type) {
63
57
  if (type === EFFECT_PURE) {
64
- pureQueue.length && runPureQueue(pureQueue);
58
+ pureQueue.length && runQueue(pureQueue, type);
65
59
  pureQueue = [];
66
60
  return;
67
61
  } else if (this.K[type - 1].length) {
68
62
  const effects = this.K[type - 1];
69
63
  this.K[type - 1] = [];
70
- runEffectQueue(effects);
64
+ runQueue(effects, type);
71
65
  }
72
66
  for (let i = 0; i < this.E.length; i++) {
73
67
  this.E[i].run(type);
@@ -103,57 +97,14 @@ var Queue = class {
103
97
  }
104
98
  };
105
99
  var globalQueue = new Queue();
106
- function flushSync() {
100
+ function flush() {
107
101
  while (scheduled) {
108
102
  globalQueue.flush();
109
103
  }
110
104
  }
111
- function runTop(node) {
112
- const ancestors = [];
113
- for (let current = node; current !== null; current = current.o) {
114
- if (current.a !== STATE_CLEAN) {
115
- ancestors.push(current);
116
- }
117
- }
118
- for (let i = ancestors.length - 1; i >= 0; i--) {
119
- if (ancestors[i].a !== STATE_DISPOSED)
120
- ancestors[i].x();
121
- }
122
- }
123
- function runPureQueue(queue) {
124
- for (let i = 0; i < queue.length; i++) {
125
- if (queue[i].a !== STATE_CLEAN)
126
- runTop(queue[i]);
127
- }
128
- }
129
- function runEffectQueue(queue) {
105
+ function runQueue(queue, type) {
130
106
  for (let i = 0; i < queue.length; i++)
131
- queue[i].V();
132
- }
133
-
134
- // src/core/utils.ts
135
- function isUndefined(value) {
136
- return typeof value === "undefined";
137
- }
138
- function tryCatch(fn) {
139
- try {
140
- const v = fn();
141
- if (v instanceof Promise) {
142
- return v.then(
143
- (v2) => [void 0, v2],
144
- (e) => {
145
- if (e instanceof NotReadyError)
146
- throw e;
147
- return [e];
148
- }
149
- );
150
- }
151
- return [void 0, v];
152
- } catch (e) {
153
- if (e instanceof NotReadyError)
154
- throw e;
155
- return [e];
156
- }
107
+ queue[i](type);
157
108
  }
158
109
 
159
110
  // src/core/owner.ts
@@ -167,17 +118,13 @@ function setOwner(owner) {
167
118
  currentOwner = owner;
168
119
  return out;
169
120
  }
170
- function formatId(prefix, id) {
171
- const num = id.toString(36), len = num.length - 1;
172
- return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
173
- }
174
121
  var Owner = class {
175
122
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
176
123
  // However, the children are actually added in reverse creation order
177
124
  // See comment at the top of the file for an example of the _nextSibling traversal
178
125
  o = null;
179
126
  m = null;
180
- s = null;
127
+ t = null;
181
128
  a = STATE_CLEAN;
182
129
  l = null;
183
130
  p = defaultContext;
@@ -187,18 +134,18 @@ var Owner = class {
187
134
  constructor(id = null, skipAppend = false) {
188
135
  this.id = id;
189
136
  if (currentOwner) {
190
- if (id == null && currentOwner.id != null)
191
- this.id = currentOwner.getNextChildId();
192
137
  !skipAppend && currentOwner.append(this);
193
138
  }
194
139
  }
195
140
  append(child) {
196
141
  child.o = this;
197
- child.s = this;
142
+ child.t = this;
198
143
  if (this.m)
199
- this.m.s = child;
144
+ this.m.t = child;
200
145
  child.m = this.m;
201
146
  this.m = child;
147
+ if (this.id != null && child.id == null)
148
+ child.id = this.getNextChildId();
202
149
  if (child.p !== this.p) {
203
150
  child.p = { ...this.p, ...child.p };
204
151
  }
@@ -208,7 +155,7 @@ var Owner = class {
208
155
  dispose(self = true) {
209
156
  if (this.a === STATE_DISPOSED)
210
157
  return;
211
- let head = self ? this.s || this.o : this, current = this.m, next = null;
158
+ let head = self ? this.t || this.o : this, current = this.m, next = null;
212
159
  while (current && current.o === this) {
213
160
  current.dispose(true);
214
161
  current.y();
@@ -220,15 +167,15 @@ var Owner = class {
220
167
  if (self)
221
168
  this.y();
222
169
  if (current)
223
- current.s = !self ? this : this.s;
170
+ current.t = !self ? this : this.t;
224
171
  if (head)
225
172
  head.m = current;
226
173
  }
227
174
  y() {
228
- if (this.s)
229
- this.s.m = null;
175
+ if (this.t)
176
+ this.t.m = null;
230
177
  this.o = null;
231
- this.s = null;
178
+ this.t = null;
232
179
  this.p = defaultContext;
233
180
  this.a = STATE_DISPOSED;
234
181
  this.emptyDisposal();
@@ -290,6 +237,13 @@ function onCleanup(fn) {
290
237
  }
291
238
  return fn;
292
239
  }
240
+ function formatId(prefix, id) {
241
+ const num = id.toString(36), len = num.length - 1;
242
+ return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
243
+ }
244
+ function isUndefined(value) {
245
+ return typeof value === "undefined";
246
+ }
293
247
 
294
248
  // src/core/flags.ts
295
249
  var ERROR_OFFSET = 0;
@@ -306,6 +260,7 @@ var currentMask = DEFAULT_FLAGS;
306
260
  var newSources = null;
307
261
  var newSourcesIndex = 0;
308
262
  var newFlags = 0;
263
+ var unobserved = [];
309
264
  var notStale = false;
310
265
  var updateCheck = null;
311
266
  var staleCheck = null;
@@ -315,30 +270,33 @@ function getObserver() {
315
270
  var UNCHANGED = Symbol(0);
316
271
  var Computation = class extends Owner {
317
272
  c = null;
318
- e = null;
273
+ d = null;
319
274
  g;
320
275
  F;
321
276
  z;
322
277
  // Used in __DEV__ mode, hopefully removed in production
323
- ba;
278
+ ca;
324
279
  // Using false is an optimization as an alternative to _equals: () => false
325
280
  // which could enable more efficient DIRTY notification
326
- S = isEqual;
281
+ R = isEqual;
327
282
  X;
283
+ _ = false;
328
284
  /** Whether the computation is an error or has ancestors that are unresolved */
329
285
  f = 0;
330
286
  /** Which flags raised by sources are handled, vs. being passed through. */
331
- T = DEFAULT_FLAGS;
287
+ S = DEFAULT_FLAGS;
332
288
  A = -1;
333
289
  w = false;
334
290
  constructor(initialValue, compute2, options) {
335
- super(null, compute2 === null);
291
+ super(options?.id, compute2 === null);
336
292
  this.z = compute2;
337
293
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
338
294
  this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
339
295
  this.g = initialValue;
340
296
  if (options?.equals !== void 0)
341
- this.S = options.equals;
297
+ this.R = options.equals;
298
+ if (options?.pureWrite)
299
+ this._ = true;
342
300
  if (options?.unobserved)
343
301
  this.X = options?.unobserved;
344
302
  }
@@ -389,7 +347,8 @@ var Computation = class extends Owner {
389
347
  /** Update the computation with a new value. */
390
348
  write(value, flags = 0, raw = false) {
391
349
  const newValue = !raw && typeof value === "function" ? value(this.g) : value;
392
- const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || this.f & LOADING_BIT & ~flags || this.S === false || !this.S(this.g, newValue));
350
+ const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
351
+ this.R === false || !this.R(this.g, newValue));
393
352
  if (valueChanged) {
394
353
  this.g = newValue;
395
354
  this.F = void 0;
@@ -397,12 +356,12 @@ var Computation = class extends Owner {
397
356
  const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
398
357
  this.f = flags;
399
358
  this.A = getClock() + 1;
400
- if (this.e) {
401
- for (let i = 0; i < this.e.length; i++) {
359
+ if (this.d) {
360
+ for (let i = 0; i < this.d.length; i++) {
402
361
  if (valueChanged) {
403
- this.e[i].r(STATE_DIRTY);
362
+ this.d[i].r(STATE_DIRTY);
404
363
  } else if (changedFlagsMask) {
405
- this.e[i].Z(changedFlagsMask, changedFlags);
364
+ this.d[i].Z(changedFlagsMask, changedFlags);
406
365
  }
407
366
  }
408
367
  }
@@ -416,9 +375,9 @@ var Computation = class extends Owner {
416
375
  return;
417
376
  this.w = !!skipQueue;
418
377
  this.a = state;
419
- if (this.e) {
420
- for (let i = 0; i < this.e.length; i++) {
421
- this.e[i].r(STATE_CHECK, skipQueue);
378
+ if (this.d) {
379
+ for (let i = 0; i < this.d.length; i++) {
380
+ this.d[i].r(STATE_CHECK, skipQueue);
422
381
  }
423
382
  }
424
383
  }
@@ -431,7 +390,7 @@ var Computation = class extends Owner {
431
390
  Z(mask, newFlags2) {
432
391
  if (this.a >= STATE_DIRTY)
433
392
  return;
434
- if (mask & this.T) {
393
+ if (mask & this.S) {
435
394
  this.r(STATE_DIRTY);
436
395
  return;
437
396
  }
@@ -443,9 +402,9 @@ var Computation = class extends Owner {
443
402
  this.r(STATE_CHECK);
444
403
  } else {
445
404
  this.f ^= deltaFlags;
446
- if (this.e) {
447
- for (let i = 0; i < this.e.length; i++) {
448
- this.e[i].Z(mask, newFlags2);
405
+ if (this.d) {
406
+ for (let i = 0; i < this.d.length; i++) {
407
+ this.d[i].Z(mask, newFlags2);
449
408
  }
450
409
  }
451
410
  }
@@ -544,15 +503,16 @@ function update(node) {
544
503
  let source;
545
504
  for (let i = newSourcesIndex; i < node.c.length; i++) {
546
505
  source = node.c[i];
547
- if (!source.e)
548
- source.e = [node];
506
+ if (!source.d)
507
+ source.d = [node];
549
508
  else
550
- source.e.push(node);
509
+ source.d.push(node);
551
510
  }
552
511
  } else if (node.c && newSourcesIndex < node.c.length) {
553
512
  removeSourceObservers(node, newSourcesIndex);
554
513
  node.c.length = newSourcesIndex;
555
514
  }
515
+ unobserved.length && notifyUnobserved();
556
516
  newSources = prevSources;
557
517
  newSourcesIndex = prevSourcesIndex;
558
518
  newFlags = prevFlags;
@@ -565,15 +525,23 @@ function removeSourceObservers(node, index) {
565
525
  let swap;
566
526
  for (let i = index; i < node.c.length; i++) {
567
527
  source = node.c[i];
568
- if (source.e) {
569
- swap = source.e.indexOf(node);
570
- source.e[swap] = source.e[source.e.length - 1];
571
- source.e.pop();
572
- if (!source.e.length)
573
- source.X?.();
528
+ if (source.d) {
529
+ swap = source.d.indexOf(node);
530
+ source.d[swap] = source.d[source.d.length - 1];
531
+ source.d.pop();
532
+ if (!source.d.length)
533
+ unobserved.push(source);
574
534
  }
575
535
  }
576
536
  }
537
+ function notifyUnobserved() {
538
+ for (let i = 0; i < unobserved.length; i++) {
539
+ const source = unobserved[i];
540
+ if (!source.d || !source.d.length)
541
+ unobserved[i].X?.();
542
+ }
543
+ unobserved = [];
544
+ }
577
545
  function isEqual(a, b) {
578
546
  return a === b;
579
547
  }
@@ -612,7 +580,7 @@ function isPending(fn, loadingValue) {
612
580
  if (!currentObserver)
613
581
  return pendingCheck(fn, loadingValue);
614
582
  const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
615
- c.T |= LOADING_BIT;
583
+ c.S |= LOADING_BIT;
616
584
  return c.read();
617
585
  }
618
586
  function latest(fn, fallback) {
@@ -660,10 +628,10 @@ function runWithObserver(observer, run) {
660
628
  let source;
661
629
  for (let i = newSourcesIndex; i < observer.c.length; i++) {
662
630
  source = observer.c[i];
663
- if (!source.e)
664
- source.e = [observer];
631
+ if (!source.d)
632
+ source.d = [observer];
665
633
  else
666
- source.e.push(observer);
634
+ source.d.push(observer);
667
635
  }
668
636
  }
669
637
  newSources = prevSources;
@@ -674,7 +642,7 @@ function runWithObserver(observer, run) {
674
642
  function compute(owner, fn, observer) {
675
643
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
676
644
  currentObserver = observer;
677
- currentMask = observer?.T ?? DEFAULT_FLAGS;
645
+ currentMask = observer?.S ?? DEFAULT_FLAGS;
678
646
  notStale = true;
679
647
  try {
680
648
  return fn(observer ? observer.g : void 0);
@@ -685,94 +653,32 @@ function compute(owner, fn, observer) {
685
653
  notStale = prevNotStale;
686
654
  }
687
655
  }
688
- function flatten(children, options) {
689
- try {
690
- if (typeof children === "function" && !children.length) {
691
- if (options?.doNotUnwrap)
692
- return children;
693
- do {
694
- children = children();
695
- } while (typeof children === "function" && !children.length);
696
- }
697
- if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
698
- return;
699
- if (Array.isArray(children)) {
700
- let results = [];
701
- if (flattenArray(children, results, options)) {
702
- return () => {
703
- let nested = [];
704
- flattenArray(results, nested, { ...options, doNotUnwrap: false });
705
- return nested;
706
- };
707
- }
708
- return results;
709
- }
710
- return children;
711
- } catch (e) {
712
- if (options?.skipNonRendered && e instanceof NotReadyError) {
713
- newFlags |= LOADING_BIT;
714
- return void 0;
715
- }
716
- throw e;
717
- }
718
- }
719
- function flattenArray(children, results = [], options) {
720
- let notReady = null;
721
- let needsUnwrap = false;
722
- for (let i = 0; i < children.length; i++) {
723
- try {
724
- let child = children[i];
725
- if (typeof child === "function" && !child.length) {
726
- if (options?.doNotUnwrap) {
727
- results.push(child);
728
- needsUnwrap = true;
729
- continue;
730
- }
731
- do {
732
- child = child();
733
- } while (typeof child === "function" && !child.length);
734
- }
735
- if (Array.isArray(child)) {
736
- needsUnwrap = flattenArray(child, results, options);
737
- } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
738
- } else
739
- results.push(child);
740
- } catch (e) {
741
- if (!(e instanceof NotReadyError))
742
- throw e;
743
- notReady = e;
744
- }
745
- }
746
- if (notReady)
747
- throw notReady;
748
- return needsUnwrap;
749
- }
750
656
 
751
657
  // src/core/effect.ts
752
658
  var Effect = class extends Computation {
659
+ T;
753
660
  M;
754
- N;
755
661
  B;
756
662
  U = false;
757
- O;
758
- t;
663
+ N;
664
+ s;
759
665
  constructor(initialValue, compute2, effect, error, options) {
760
666
  super(initialValue, compute2, options);
761
- this.M = effect;
762
- this.N = error;
763
- this.O = initialValue;
764
- this.t = options?.render ? EFFECT_RENDER : EFFECT_USER;
765
- if (this.t === EFFECT_RENDER) {
667
+ this.T = effect;
668
+ this.M = error;
669
+ this.N = initialValue;
670
+ this.s = options?.render ? EFFECT_RENDER : EFFECT_USER;
671
+ if (this.s === EFFECT_RENDER) {
766
672
  this.z = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
767
673
  }
768
674
  this.x();
769
- !options?.defer && (this.t === EFFECT_USER ? this.h.enqueue(this.t, this) : this.V());
675
+ !options?.defer && (this.s === EFFECT_USER ? this.h.enqueue(this.s, this.V.bind(this)) : this.V(this.s));
770
676
  }
771
677
  write(value, flags = 0) {
772
678
  if (this.a == STATE_DIRTY) {
773
679
  this.f;
774
680
  this.f = flags;
775
- if (this.t === EFFECT_RENDER) {
681
+ if (this.s === EFFECT_RENDER) {
776
682
  this.h.notify(this, LOADING_BIT | ERROR_BIT, flags);
777
683
  }
778
684
  }
@@ -786,17 +692,19 @@ var Effect = class extends Computation {
786
692
  if (this.a >= state || skipQueue)
787
693
  return;
788
694
  if (this.a === STATE_CLEAN)
789
- this.h.enqueue(this.t, this);
695
+ this.h.enqueue(this.s, this.V.bind(this));
790
696
  this.a = state;
791
697
  }
792
698
  L(error) {
793
699
  this.F = error;
794
- this.B?.();
795
700
  this.h.notify(this, LOADING_BIT, 0);
796
701
  this.f = ERROR_BIT;
797
- if (this.t === EFFECT_USER) {
702
+ if (this.s === EFFECT_USER) {
798
703
  try {
799
- return this.N ? this.B = this.N(error) : console.error(new EffectError(this.M, error));
704
+ return this.M ? this.M(error, () => {
705
+ this.B?.();
706
+ this.B = void 0;
707
+ }) : console.error(error);
800
708
  } catch (e) {
801
709
  error = e;
802
710
  }
@@ -807,28 +715,34 @@ var Effect = class extends Computation {
807
715
  y() {
808
716
  if (this.a === STATE_DISPOSED)
809
717
  return;
810
- this.M = void 0;
811
- this.O = void 0;
718
+ this.T = void 0;
812
719
  this.N = void 0;
720
+ this.M = void 0;
813
721
  this.B?.();
814
722
  this.B = void 0;
815
723
  super.y();
816
724
  }
817
- V() {
818
- if (this.U && this.a !== STATE_DISPOSED) {
819
- this.B?.();
820
- try {
821
- this.B = this.M(this.g, this.O);
822
- } catch (e) {
823
- if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
824
- throw e;
825
- } finally {
826
- this.O = this.g;
827
- this.U = false;
725
+ V(type) {
726
+ if (type) {
727
+ if (this.U && this.a !== STATE_DISPOSED) {
728
+ this.B?.();
729
+ try {
730
+ this.B = this.T(this.g, this.N);
731
+ } catch (e) {
732
+ if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
733
+ throw e;
734
+ } finally {
735
+ this.N = this.g;
736
+ this.U = false;
737
+ }
828
738
  }
829
- }
739
+ } else
740
+ this.a !== STATE_CLEAN && runTop(this);
830
741
  }
831
742
  };
743
+ function runComputation() {
744
+ this.a !== STATE_CLEAN && runTop(this);
745
+ }
832
746
  var EagerComputation = class extends Computation {
833
747
  constructor(initialValue, compute2, options) {
834
748
  super(initialValue, compute2, options);
@@ -838,11 +752,12 @@ var EagerComputation = class extends Computation {
838
752
  if (this.a >= state && !this.w)
839
753
  return;
840
754
  if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.w))
841
- this.h.enqueue(EFFECT_PURE, this);
755
+ this.h.enqueue(EFFECT_PURE, runComputation.bind(this));
842
756
  super.r(state, skipQueue);
843
757
  }
844
758
  };
845
- var ProjectionComputation = class extends Computation {
759
+ var FirewallComputation = class extends Computation {
760
+ firewall = true;
846
761
  constructor(compute2) {
847
762
  super(void 0, compute2);
848
763
  }
@@ -850,141 +765,22 @@ var ProjectionComputation = class extends Computation {
850
765
  if (this.a >= state && !this.w)
851
766
  return;
852
767
  if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.w))
853
- this.h.enqueue(EFFECT_PURE, this);
768
+ this.h.enqueue(EFFECT_PURE, runComputation.bind(this));
854
769
  super.r(state, true);
855
770
  this.w = !!skipQueue;
856
771
  }
857
772
  };
858
-
859
- // src/core/boundaries.ts
860
- var BoundaryComputation = class extends EagerComputation {
861
- G;
862
- constructor(compute2, propagationMask) {
863
- super(void 0, compute2, { defer: true });
864
- this.G = propagationMask;
865
- }
866
- write(value, flags) {
867
- super.write(value, flags & ~this.G);
868
- if (this.G & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
869
- flags &= ~LOADING_BIT;
870
- }
871
- this.h.notify(this, this.G, flags);
872
- return this.g;
873
- }
874
- };
875
- function createBoundChildren(owner, fn, queue, mask) {
876
- const parentQueue = owner.h;
877
- parentQueue.addChild(owner.h = queue);
878
- onCleanup(() => parentQueue.removeChild(owner.h));
879
- return compute(
880
- owner,
881
- () => {
882
- const c = new Computation(void 0, fn);
883
- return new BoundaryComputation(() => flatten(c.wait()), mask);
884
- },
885
- null
886
- );
887
- }
888
- var ConditionalQueue = class extends Queue {
889
- n;
890
- P = /* @__PURE__ */ new Set();
891
- Q = /* @__PURE__ */ new Set();
892
- constructor(disabled) {
893
- super();
894
- this.n = disabled;
895
- }
896
- run(type) {
897
- if (!type || this.n.read())
898
- return;
899
- return super.run(type);
900
- }
901
- notify(node, type, flags) {
902
- if (this.n.read()) {
903
- if (type === LOADING_BIT) {
904
- flags & LOADING_BIT ? this.Q.add(node) : this.Q.delete(node);
905
- }
906
- if (type === ERROR_BIT) {
907
- flags & ERROR_BIT ? this.P.add(node) : this.P.delete(node);
908
- }
909
- return true;
773
+ function runTop(node) {
774
+ const ancestors = [];
775
+ for (let current = node; current !== null; current = current.o) {
776
+ if (current.a !== STATE_CLEAN) {
777
+ ancestors.push(current);
910
778
  }
911
- return super.notify(node, type, flags);
912
779
  }
913
- };
914
- var CollectionQueue = class extends Queue {
915
- R;
916
- b = /* @__PURE__ */ new Set();
917
- n = new Computation(false, null);
918
- constructor(type) {
919
- super();
920
- this.R = type;
921
- }
922
- run(type) {
923
- if (!type || this.n.read())
924
- return;
925
- return super.run(type);
926
- }
927
- notify(node, type, flags) {
928
- if (!(type & this.R))
929
- return super.notify(node, type, flags);
930
- if (flags & this.R) {
931
- this.b.add(node);
932
- if (this.b.size === 1)
933
- this.n.write(true);
934
- } else {
935
- this.b.delete(node);
936
- if (this.b.size === 0)
937
- this.n.write(false);
938
- }
939
- type &= ~this.R;
940
- return type ? super.notify(node, type, flags) : true;
780
+ for (let i = ancestors.length - 1; i >= 0; i--) {
781
+ if (ancestors[i].a !== STATE_DISPOSED)
782
+ ancestors[i].x();
941
783
  }
942
- };
943
- function createBoundary(fn, condition) {
944
- const owner = new Owner();
945
- const queue = new ConditionalQueue(new Computation(void 0, () => condition() === "hidden" /* HIDDEN */));
946
- const tree = createBoundChildren(owner, fn, queue, 0);
947
- new EagerComputation(void 0, () => {
948
- const disabled = queue.n.read();
949
- tree.G = disabled ? ERROR_BIT | LOADING_BIT : 0;
950
- if (!disabled) {
951
- queue.Q.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
952
- queue.P.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
953
- queue.Q.clear();
954
- queue.P.clear();
955
- }
956
- });
957
- return () => queue.n.read() ? void 0 : tree.read();
958
- }
959
- function createCollectionBoundary(type, fn, fallback) {
960
- const owner = new Owner();
961
- const queue = new CollectionQueue(type);
962
- const tree = createBoundChildren(owner, fn, queue, type);
963
- const decision = new Computation(void 0, () => {
964
- if (!queue.n.read()) {
965
- const resolved = tree.read();
966
- if (!queue.n.read())
967
- return resolved;
968
- }
969
- return fallback(queue);
970
- });
971
- return decision.read.bind(decision);
972
- }
973
- function createSuspense(fn, fallback) {
974
- return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
975
- }
976
- function createErrorBoundary(fn, fallback) {
977
- return createCollectionBoundary(
978
- ERROR_BIT,
979
- fn,
980
- (queue) => fallback(queue.b.values().next().value.F, () => {
981
- incrementClock();
982
- for (let node of queue.b) {
983
- node.a = STATE_DIRTY;
984
- node.h?.enqueue(node.t, node);
985
- }
986
- })
987
- );
988
784
  }
989
785
 
990
786
  // src/signals.ts
@@ -1000,7 +796,13 @@ function createSignal(first, second, third) {
1000
796
  });
1001
797
  return [() => memo()[0](), (value) => memo()[1](value)];
1002
798
  }
1003
- const node = new Computation(first, null, second);
799
+ const o = getOwner();
800
+ const needsId = o?.id != null;
801
+ const node = new Computation(
802
+ first,
803
+ null,
804
+ needsId ? { id: o.getNextChildId(), ...second } : second
805
+ );
1004
806
  return [node.read.bind(node), node.write.bind(node)];
1005
807
  }
1006
808
  function createMemo(compute2, value, options) {
@@ -1026,10 +828,12 @@ function createMemo(compute2, value, options) {
1026
828
  };
1027
829
  }
1028
830
  function createAsync(compute2, value, options) {
831
+ let refreshing = false;
1029
832
  const node = new EagerComputation(
1030
833
  value,
1031
834
  (p) => {
1032
- const source = compute2(p);
835
+ const source = compute2(p, refreshing);
836
+ refreshing = false;
1033
837
  const isPromise = source instanceof Promise;
1034
838
  const iterator = source[Symbol.asyncIterator];
1035
839
  if (!isPromise && !iterator) {
@@ -1069,14 +873,20 @@ function createAsync(compute2, value, options) {
1069
873
  },
1070
874
  options
1071
875
  );
1072
- return node.wait.bind(node);
876
+ const read = node.wait.bind(node);
877
+ read.refresh = () => {
878
+ node.a = STATE_DIRTY;
879
+ refreshing = true;
880
+ node.x();
881
+ };
882
+ return read;
1073
883
  }
1074
- function createEffect(compute2, effect, error, value, options) {
884
+ function createEffect(compute2, effect, value, options) {
1075
885
  void new Effect(
1076
886
  value,
1077
887
  compute2,
1078
- effect,
1079
- error,
888
+ effect.effect ? effect.effect : effect,
889
+ effect.error,
1080
890
  options
1081
891
  );
1082
892
  }
@@ -1109,101 +919,97 @@ function resolve(fn) {
1109
919
  });
1110
920
  });
1111
921
  }
922
+ function tryCatch(fn) {
923
+ try {
924
+ const v = fn();
925
+ if (v instanceof Promise) {
926
+ return v.then(
927
+ (v2) => [void 0, v2],
928
+ (e) => {
929
+ if (e instanceof NotReadyError)
930
+ throw e;
931
+ return [e];
932
+ }
933
+ );
934
+ }
935
+ return [void 0, v];
936
+ } catch (e) {
937
+ if (e instanceof NotReadyError)
938
+ throw e;
939
+ return [e];
940
+ }
941
+ }
942
+ function transition(fn) {
943
+ }
944
+ function createOptimistic(initial, compute2, options) {
945
+ return [];
946
+ }
1112
947
 
1113
948
  // src/store/projection.ts
1114
949
  function createProjection(fn, initialValue = {}) {
1115
- const [store] = createStore(fn, initialValue);
1116
- return store;
1117
- }
1118
- function wrapProjection(fn, store, setStore) {
1119
- const node = new ProjectionComputation(() => {
1120
- setStore(fn);
950
+ let wrappedStore;
951
+ const node = new FirewallComputation(() => {
952
+ storeSetter(wrappedStore, fn);
1121
953
  });
1122
- const wrapped = /* @__PURE__ */ new WeakMap();
1123
- return [wrap(store, node, wrapped), setStore];
1124
- }
1125
- function wrap(source, node, wrapped) {
1126
- if (wrapped.has(source))
1127
- return wrapped.get(source);
1128
- const wrap3 = new Proxy(source, {
1129
- get(target, property) {
1130
- node.read();
1131
- const v = target[property];
1132
- return isWrappable(v) ? wrap3(v, node, wrapped) : v;
1133
- },
1134
- set() {
1135
- throw new Error("Projections are readonly");
1136
- },
1137
- deleteProperty() {
1138
- throw new Error("Projections are readonly");
954
+ const wrappedMap = /* @__PURE__ */ new WeakMap();
955
+ const traps = {
956
+ ...storeTraps,
957
+ get(target, property, receiver) {
958
+ const o = getOwner();
959
+ (!o || o !== node) && node.wait();
960
+ return storeTraps.get(target, property, receiver);
1139
961
  }
1140
- });
1141
- wrapped.set(source, wrap3);
1142
- return wrap3;
962
+ };
963
+ function wrapProjection(source) {
964
+ if (wrappedMap.has(source))
965
+ return wrappedMap.get(source);
966
+ if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
967
+ return source;
968
+ const wrapped = createStoreProxy(source, traps, {
969
+ [STORE_WRAP]: wrapProjection,
970
+ [STORE_LOOKUP]: wrappedMap
971
+ });
972
+ wrappedMap.set(source, wrapped);
973
+ return wrapped;
974
+ }
975
+ return wrappedStore = wrapProjection(initialValue);
1143
976
  }
1144
977
 
1145
978
  // src/store/store.ts
1146
- var $RAW = Symbol(0);
1147
979
  var $TRACK = Symbol(0);
1148
980
  var $DEEP = Symbol(0);
1149
981
  var $TARGET = Symbol(0);
1150
982
  var $PROXY = Symbol(0);
983
+ var $DELETED = Symbol(0);
1151
984
  var PARENTS = /* @__PURE__ */ new WeakMap();
1152
985
  var STORE_VALUE = "v";
986
+ var STORE_OVERRIDE = "o";
1153
987
  var STORE_NODE = "n";
1154
988
  var STORE_HAS = "h";
1155
- function wrap2(value) {
1156
- let p = value[$PROXY];
1157
- if (!p) {
1158
- let target;
1159
- if (Array.isArray(value)) {
1160
- target = [];
1161
- target.v = value;
1162
- } else
1163
- target = { v: value };
1164
- Object.defineProperty(value, $PROXY, {
1165
- value: p = new Proxy(target, proxyTraps),
1166
- writable: true
1167
- });
1168
- }
989
+ var STORE_WRAP = "w";
990
+ var STORE_LOOKUP = "l";
991
+ function createStoreProxy(value, traps = storeTraps, extend) {
992
+ let newTarget;
993
+ if (Array.isArray(value)) {
994
+ newTarget = [];
995
+ newTarget.v = value;
996
+ } else
997
+ newTarget = { v: value };
998
+ extend && Object.assign(newTarget, extend);
999
+ return newTarget[$PROXY] = new Proxy(newTarget, traps);
1000
+ }
1001
+ var storeLookup = /* @__PURE__ */ new WeakMap();
1002
+ function wrap(value, target) {
1003
+ if (target?.[STORE_WRAP])
1004
+ return target[STORE_WRAP](value, target);
1005
+ let p = value[$PROXY] || storeLookup.get(value);
1006
+ if (!p)
1007
+ storeLookup.set(value, p = createStoreProxy(value));
1169
1008
  return p;
1170
1009
  }
1171
1010
  function isWrappable(obj) {
1172
1011
  return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
1173
1012
  }
1174
- function unwrap(item, deep2 = true, set) {
1175
- let result, unwrapped, v, prop;
1176
- if (result = item != null && item[$RAW])
1177
- return result;
1178
- if (!deep2)
1179
- return item;
1180
- if (!isWrappable(item) || set?.has(item))
1181
- return item;
1182
- if (!set)
1183
- set = /* @__PURE__ */ new Set();
1184
- set.add(item);
1185
- if (Array.isArray(item)) {
1186
- for (let i = 0, l = item.length; i < l; i++) {
1187
- v = item[i];
1188
- if ((unwrapped = unwrap(v, deep2, set)) !== v)
1189
- item[i] = unwrapped;
1190
- }
1191
- } else {
1192
- if (!deep2)
1193
- return item;
1194
- const keys = Object.keys(item);
1195
- for (let i = 0, l = keys.length; i < l; i++) {
1196
- prop = keys[i];
1197
- const desc = Object.getOwnPropertyDescriptor(item, prop);
1198
- if (desc.get)
1199
- continue;
1200
- v = item[prop];
1201
- if ((unwrapped = unwrap(v, deep2, set)) !== v)
1202
- item[prop] = unwrapped;
1203
- }
1204
- }
1205
- return item;
1206
- }
1207
1013
  function getNodes(target, type) {
1208
1014
  let nodes = target[type];
1209
1015
  if (!nodes)
@@ -1220,31 +1026,38 @@ function getNode(nodes, property, value, equals = isEqual) {
1220
1026
  }
1221
1027
  });
1222
1028
  }
1223
- function proxyDescriptor(target, property) {
1224
- if (property === $PROXY)
1225
- return { value: target[$PROXY], writable: true, configurable: true };
1226
- const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
1227
- if (!desc || desc.get || !desc.configurable)
1228
- return desc;
1229
- delete desc.value;
1230
- delete desc.writable;
1231
- desc.get = () => target[STORE_VALUE][$PROXY][property];
1232
- return desc;
1233
- }
1234
1029
  function trackSelf(target, symbol = $TRACK) {
1235
1030
  getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
1236
1031
  }
1237
- function ownKeys(target) {
1238
- trackSelf(target);
1239
- return Reflect.ownKeys(target[STORE_VALUE]);
1032
+ function getKeys(source, override, enumerable = true) {
1033
+ const baseKeys = untrack(() => enumerable ? Object.keys(source) : Reflect.ownKeys(source));
1034
+ if (!override)
1035
+ return baseKeys;
1036
+ const keys = new Set(baseKeys);
1037
+ const overrides = Reflect.ownKeys(override);
1038
+ for (const key of overrides) {
1039
+ if (override[key] !== $DELETED)
1040
+ keys.add(key);
1041
+ else
1042
+ keys.delete(key);
1043
+ }
1044
+ return Array.from(keys);
1045
+ }
1046
+ function getPropertyDescriptor(source, override, property) {
1047
+ let value = source;
1048
+ if (override && property in override) {
1049
+ if (value[property] === $DELETED)
1050
+ return void 0;
1051
+ if (!(property in value))
1052
+ value = override;
1053
+ }
1054
+ return Reflect.getOwnPropertyDescriptor(value, property);
1240
1055
  }
1241
1056
  var Writing = null;
1242
- var proxyTraps = {
1057
+ var storeTraps = {
1243
1058
  get(target, property, receiver) {
1244
1059
  if (property === $TARGET)
1245
1060
  return target;
1246
- if (property === $RAW)
1247
- return target[STORE_VALUE];
1248
1061
  if (property === $PROXY)
1249
1062
  return receiver;
1250
1063
  if (property === $TRACK || property === $DEEP) {
@@ -1252,92 +1065,156 @@ var proxyTraps = {
1252
1065
  return receiver;
1253
1066
  }
1254
1067
  const nodes = getNodes(target, STORE_NODE);
1255
- const storeValue = target[STORE_VALUE];
1256
1068
  const tracked = nodes[property];
1069
+ const overridden = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE];
1070
+ const proxySource = !!target[STORE_VALUE][$TARGET];
1071
+ const storeValue = overridden ? target[STORE_OVERRIDE] : target[STORE_VALUE];
1257
1072
  if (!tracked) {
1258
1073
  const desc = Object.getOwnPropertyDescriptor(storeValue, property);
1259
1074
  if (desc && desc.get)
1260
1075
  return desc.get.call(receiver);
1261
1076
  }
1262
- if (Writing?.has(storeValue)) {
1263
- const value2 = tracked ? tracked.g : storeValue[property];
1264
- return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
1265
- }
1266
- let value = tracked ? nodes[property].read() : storeValue[property];
1077
+ if (Writing?.has(receiver)) {
1078
+ let value2 = tracked && (overridden || !proxySource) ? tracked.g : storeValue[property];
1079
+ value2 === $DELETED && (value2 = void 0);
1080
+ if (!isWrappable(value2))
1081
+ return value2;
1082
+ const wrapped = wrap(value2, target);
1083
+ Writing.add(wrapped);
1084
+ return wrapped;
1085
+ }
1086
+ let value = tracked ? overridden || !proxySource ? nodes[property].read() : (nodes[property].read(), storeValue[property]) : storeValue[property];
1087
+ value === $DELETED && (value = void 0);
1267
1088
  if (!tracked) {
1268
- if (typeof value === "function" && !storeValue.hasOwnProperty(property)) {
1089
+ if (!overridden && typeof value === "function" && !storeValue.hasOwnProperty(property)) {
1269
1090
  let proto;
1270
- return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
1091
+ return !Array.isArray(target[STORE_VALUE]) && (proto = Object.getPrototypeOf(target[STORE_VALUE])) && proto !== Object.prototype ? value.bind(storeValue) : value;
1271
1092
  } else if (getObserver()) {
1272
- return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
1093
+ return getNode(nodes, property, isWrappable(value) ? wrap(value, target) : value).read();
1273
1094
  }
1274
1095
  }
1275
- return isWrappable(value) ? wrap2(value) : value;
1096
+ return isWrappable(value) ? wrap(value, target) : value;
1276
1097
  },
1277
1098
  has(target, property) {
1278
- if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
1099
+ if (property === $PROXY || property === $TRACK || property === "__proto__")
1279
1100
  return true;
1280
- const has = property in target[STORE_VALUE];
1101
+ const has = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] !== $DELETED : property in target[STORE_VALUE];
1281
1102
  getObserver() && getNode(getNodes(target, STORE_HAS), property, has).read();
1282
1103
  return has;
1283
1104
  },
1284
- set(target, property, value) {
1285
- Writing?.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, unwrap(value, false));
1105
+ set(target, property, rawValue) {
1106
+ const store = target[$PROXY];
1107
+ if (Writing?.has(target[$PROXY])) {
1108
+ untrack(() => {
1109
+ const state = target[STORE_VALUE];
1110
+ const base = state[property];
1111
+ const prev = target[STORE_OVERRIDE]?.[property] || base;
1112
+ const value = rawValue?.[$TARGET]?.[STORE_VALUE] ?? rawValue;
1113
+ if (prev === value)
1114
+ return true;
1115
+ const len = target[STORE_OVERRIDE]?.length || state.length;
1116
+ if (value !== void 0 && value === base)
1117
+ delete target[STORE_OVERRIDE][property];
1118
+ else
1119
+ (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = value;
1120
+ const wrappable = isWrappable(value);
1121
+ if (isWrappable(prev)) {
1122
+ const parents = PARENTS.get(prev);
1123
+ parents && (parents instanceof Set ? parents.delete(store) : PARENTS.delete(prev));
1124
+ }
1125
+ if (recursivelyNotify(store, storeLookup) && wrappable)
1126
+ recursivelyAddParent(value, store);
1127
+ target[STORE_HAS]?.[property]?.write(true);
1128
+ const nodes = getNodes(target, STORE_NODE);
1129
+ nodes[property]?.write(wrappable ? wrap(value, target) : value);
1130
+ if (Array.isArray(state)) {
1131
+ const index = parseInt(property) + 1;
1132
+ if (index > len)
1133
+ nodes.length?.write(index);
1134
+ }
1135
+ nodes[$TRACK]?.write(void 0);
1136
+ });
1137
+ }
1286
1138
  return true;
1287
1139
  },
1288
1140
  deleteProperty(target, property) {
1289
- Writing?.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, void 0, true);
1141
+ if (Writing?.has(target[$PROXY]) && target[STORE_OVERRIDE]?.[property] !== $DELETED) {
1142
+ untrack(() => {
1143
+ const prev = target[STORE_OVERRIDE]?.[property] || target[STORE_VALUE][property];
1144
+ if (property in target[STORE_VALUE]) {
1145
+ (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
1146
+ } else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
1147
+ delete target[STORE_OVERRIDE][property];
1148
+ } else
1149
+ return true;
1150
+ if (isWrappable(prev)) {
1151
+ const parents = PARENTS.get(prev);
1152
+ parents && (parents instanceof Set ? parents.delete(target) : PARENTS.delete(prev));
1153
+ }
1154
+ target[STORE_HAS]?.[property]?.write(false);
1155
+ const nodes = getNodes(target, STORE_NODE);
1156
+ nodes[property]?.write(void 0);
1157
+ nodes[$TRACK]?.write(void 0);
1158
+ });
1159
+ }
1290
1160
  return true;
1291
1161
  },
1292
- ownKeys,
1293
- getOwnPropertyDescriptor: proxyDescriptor,
1162
+ ownKeys(target) {
1163
+ trackSelf(target);
1164
+ return getKeys(target[STORE_VALUE], target[STORE_OVERRIDE], false);
1165
+ },
1166
+ getOwnPropertyDescriptor(target, property) {
1167
+ if (property === $PROXY)
1168
+ return { value: target[$PROXY], writable: true, configurable: true };
1169
+ return getPropertyDescriptor(target[STORE_VALUE], target[STORE_OVERRIDE], property);
1170
+ },
1294
1171
  getPrototypeOf(target) {
1295
1172
  return Object.getPrototypeOf(target[STORE_VALUE]);
1296
1173
  }
1297
1174
  };
1298
- function setProperty(state, property, value, deleting = false) {
1299
- const prev = state[property];
1300
- if (!deleting && prev === value)
1301
- return;
1302
- const len = state.length;
1303
- if (deleting)
1304
- delete state[property];
1305
- else
1306
- state[property] = value;
1307
- const wrappable = isWrappable(value);
1308
- if (isWrappable(prev)) {
1309
- const parents = PARENTS.get(prev);
1310
- parents && (parents instanceof Set ? parents.delete(state) : PARENTS.delete(prev));
1311
- }
1312
- if (recursivelyNotify(state) && wrappable)
1313
- recursivelyAddParent(value[$RAW] || value, state);
1314
- const target = state[$PROXY]?.[$TARGET];
1315
- if (!target)
1316
- return;
1317
- if (deleting)
1318
- target[STORE_HAS]?.[property]?.write(false);
1319
- else
1320
- target[STORE_HAS]?.[property]?.write(true);
1321
- const nodes = getNodes(target, STORE_NODE);
1322
- nodes[property]?.write(wrappable ? wrap2(value) : value);
1323
- Array.isArray(state) && state.length !== len && nodes.length?.write(state.length);
1324
- nodes[$TRACK]?.write(void 0);
1325
- }
1326
- function recursivelyNotify(state) {
1327
- let target = state[$PROXY]?.[$TARGET];
1175
+ function storeSetter(store, fn) {
1176
+ const prevWriting = Writing;
1177
+ Writing = /* @__PURE__ */ new Set();
1178
+ Writing.add(store);
1179
+ try {
1180
+ fn(store);
1181
+ } finally {
1182
+ Writing.clear();
1183
+ Writing = prevWriting;
1184
+ }
1185
+ }
1186
+ function createStore(first, second) {
1187
+ const derived = typeof first === "function", wrappedStore = derived ? createProjection(first, second) : wrap(first);
1188
+ return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
1189
+ }
1190
+ function recursivelyNotify(state, lookup) {
1191
+ let target = state[$TARGET] || lookup?.get(state)?.[$TARGET];
1328
1192
  let notified = false;
1329
- target && (getNodes(target, STORE_NODE)[$DEEP]?.write(void 0), notified = true);
1330
- const parents = PARENTS.get(state);
1193
+ if (target) {
1194
+ const deep2 = getNodes(target, STORE_NODE)[$DEEP];
1195
+ if (deep2) {
1196
+ deep2.write(void 0);
1197
+ notified = true;
1198
+ }
1199
+ lookup = target[STORE_LOOKUP] || lookup;
1200
+ }
1201
+ const parents = PARENTS.get(target?.[STORE_VALUE] || state);
1331
1202
  if (!parents)
1332
1203
  return notified;
1333
1204
  if (parents instanceof Set) {
1334
1205
  for (let parent of parents)
1335
- notified = recursivelyNotify(parent) || notified;
1206
+ notified = recursivelyNotify(parent, lookup) || notified;
1336
1207
  } else
1337
- notified = recursivelyNotify(parents) || notified;
1208
+ notified = recursivelyNotify(parents, lookup) || notified;
1338
1209
  return notified;
1339
1210
  }
1340
1211
  function recursivelyAddParent(state, parent) {
1212
+ let override;
1213
+ const target = state[$TARGET];
1214
+ if (target) {
1215
+ override = target[STORE_OVERRIDE];
1216
+ state = target[STORE_VALUE];
1217
+ }
1341
1218
  if (parent) {
1342
1219
  let parents = PARENTS.get(state);
1343
1220
  if (!parents)
@@ -1352,80 +1229,73 @@ function recursivelyAddParent(state, parent) {
1352
1229
  return;
1353
1230
  }
1354
1231
  if (Array.isArray(state)) {
1355
- for (let i = 0; i < state.length; i++) {
1356
- const item = state[i];
1357
- isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
1232
+ const len = override?.length || state.length;
1233
+ for (let i = 0; i < len; i++) {
1234
+ const item = override && i in override ? override[i] : state[i];
1235
+ isWrappable(item) && recursivelyAddParent(item, state);
1358
1236
  }
1359
1237
  } else {
1360
- const keys = Object.keys(state);
1238
+ const keys = getKeys(state, override);
1361
1239
  for (let i = 0; i < keys.length; i++) {
1362
- const item = state[keys[i]];
1363
- isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
1240
+ const key = keys[i];
1241
+ const item = override && key in override ? override[key] : state[key];
1242
+ isWrappable(item) && recursivelyAddParent(item, state);
1364
1243
  }
1365
1244
  }
1366
1245
  }
1367
- function createStore(first, second) {
1368
- const derived = typeof first === "function", store = derived ? second : first;
1369
- const unwrappedStore = unwrap(store);
1370
- let wrappedStore = wrap2(unwrappedStore);
1371
- const setStore = (fn) => {
1372
- const prevWriting = Writing;
1373
- Writing = /* @__PURE__ */ new Set();
1374
- Writing.add(unwrappedStore);
1375
- try {
1376
- fn(wrappedStore);
1377
- } finally {
1378
- Writing.clear();
1379
- Writing = prevWriting;
1380
- }
1381
- };
1382
- if (derived)
1383
- return wrapProjection(first, wrappedStore, setStore);
1384
- return [wrappedStore, setStore];
1385
- }
1386
1246
  function deep(store) {
1387
- recursivelyAddParent(store[$RAW] || store);
1247
+ recursivelyAddParent(store);
1388
1248
  return store[$DEEP];
1389
1249
  }
1390
1250
 
1391
1251
  // src/store/reconcile.ts
1392
- function applyState(next, state, keyFn) {
1252
+ function unwrap(value) {
1253
+ return value?.[$TARGET]?.[STORE_NODE] ?? value;
1254
+ }
1255
+ function getOverrideValue(value, override, key) {
1256
+ return override && key in override ? override[key] : value[key];
1257
+ }
1258
+ function getAllKeys(value, override, next) {
1259
+ const keys = getKeys(value, override);
1260
+ const nextKeys = Object.keys(next);
1261
+ return Array.from(/* @__PURE__ */ new Set([...keys, ...nextKeys]));
1262
+ }
1263
+ function applyState(next, state, keyFn, all) {
1393
1264
  const target = state?.[$TARGET];
1394
1265
  if (!target)
1395
1266
  return;
1396
1267
  const previous = target[STORE_VALUE];
1397
- if (next === previous)
1268
+ const override = target[STORE_OVERRIDE];
1269
+ if (next === previous && !override)
1398
1270
  return;
1399
- Object.defineProperty(next, $PROXY, {
1400
- value: previous[$PROXY],
1401
- writable: true
1402
- });
1403
- previous[$PROXY] = null;
1271
+ (target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
1404
1272
  target[STORE_VALUE] = next;
1273
+ target[STORE_OVERRIDE] = void 0;
1405
1274
  if (Array.isArray(previous)) {
1406
1275
  let changed = false;
1407
- if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
1276
+ const prevLength = getOverrideValue(previous, override, "length");
1277
+ if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
1408
1278
  let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1409
- for (start = 0, end = Math.min(previous.length, next.length); start < end && (previous[start] === next[start] || previous[start] && next[start] && keyFn(previous[start]) === keyFn(next[start])); start++) {
1410
- applyState(next[start], wrap2(previous[start]), keyFn);
1279
+ for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
1280
+ applyState(next[start], wrap(item, target), keyFn, all);
1411
1281
  }
1412
1282
  const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1413
- for (end = previous.length - 1, newEnd = next.length - 1; end >= start && newEnd >= start && (previous[end] === next[newEnd] || previous[end] && next[newEnd] && keyFn(previous[end]) === keyFn(next[newEnd])); end--, newEnd--) {
1414
- temp[newEnd] = previous[end];
1283
+ for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
1284
+ temp[newEnd] = item;
1415
1285
  }
1416
1286
  if (start > newEnd || start > end) {
1417
1287
  for (j = start; j <= newEnd; j++) {
1418
1288
  changed = true;
1419
- target[STORE_NODE][j]?.write(wrap2(next[j]));
1289
+ target[STORE_NODE][j]?.write(wrap(next[j], target));
1420
1290
  }
1421
1291
  for (; j < next.length; j++) {
1422
1292
  changed = true;
1423
- const wrapped = wrap2(temp[j]);
1293
+ const wrapped = wrap(temp[j], target);
1424
1294
  target[STORE_NODE][j]?.write(wrapped);
1425
- applyState(next[j], wrapped, keyFn);
1295
+ applyState(next[j], wrapped, keyFn, all);
1426
1296
  }
1427
1297
  changed && target[STORE_NODE][$TRACK]?.write(void 0);
1428
- previous.length !== next.length && target[STORE_NODE].length?.write(next.length);
1298
+ prevLength !== next.length && target[STORE_NODE].length?.write(next.length);
1429
1299
  return;
1430
1300
  }
1431
1301
  newIndicesNext = new Array(newEnd + 1);
@@ -1437,31 +1307,32 @@ function applyState(next, state, keyFn) {
1437
1307
  newIndices.set(keyVal, j);
1438
1308
  }
1439
1309
  for (i = start; i <= end; i++) {
1440
- item = previous[i];
1310
+ item = getOverrideValue(previous, override, i);
1441
1311
  keyVal = item ? keyFn(item) : item;
1442
1312
  j = newIndices.get(keyVal);
1443
1313
  if (j !== void 0 && j !== -1) {
1444
- temp[j] = previous[i];
1314
+ temp[j] = item;
1445
1315
  j = newIndicesNext[j];
1446
1316
  newIndices.set(keyVal, j);
1447
1317
  }
1448
1318
  }
1449
1319
  for (j = start; j < next.length; j++) {
1450
1320
  if (j in temp) {
1451
- const wrapped = wrap2(temp[j]);
1321
+ const wrapped = wrap(temp[j], target);
1452
1322
  target[STORE_NODE][j]?.write(wrapped);
1453
- applyState(next[j], wrapped, keyFn);
1323
+ applyState(next[j], wrapped, keyFn, all);
1454
1324
  } else
1455
- target[STORE_NODE][j]?.write(wrap2(next[j]));
1325
+ target[STORE_NODE][j]?.write(wrap(next[j], target));
1456
1326
  }
1457
1327
  if (start < next.length)
1458
1328
  changed = true;
1459
- } else if (previous.length && next.length) {
1329
+ } else if (prevLength && next.length) {
1460
1330
  for (let i = 0, len = next.length; i < len; i++) {
1461
- isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
1331
+ const item = getOverrideValue(previous, override, i);
1332
+ isWrappable(item) && applyState(next[i], wrap(item, target), keyFn, all);
1462
1333
  }
1463
1334
  }
1464
- if (previous.length !== next.length) {
1335
+ if (prevLength !== next.length) {
1465
1336
  changed = true;
1466
1337
  target[STORE_NODE].length?.write(next.length);
1467
1338
  }
@@ -1470,17 +1341,20 @@ function applyState(next, state, keyFn) {
1470
1341
  }
1471
1342
  let nodes = target[STORE_NODE];
1472
1343
  if (nodes) {
1473
- const keys = Object.keys(nodes);
1344
+ const tracked = nodes[$TRACK];
1345
+ const keys = tracked || all ? getAllKeys(previous, override, next) : Object.keys(nodes);
1474
1346
  for (let i = 0, len = keys.length; i < len; i++) {
1475
- const node = nodes[keys[i]];
1476
- const previousValue = unwrap(previous[keys[i]], false);
1477
- let nextValue = unwrap(next[keys[i]], false);
1347
+ const key = keys[i];
1348
+ const node = nodes[key];
1349
+ const previousValue = unwrap(getOverrideValue(previous, override, key));
1350
+ let nextValue = unwrap(next[key]);
1478
1351
  if (previousValue === nextValue)
1479
1352
  continue;
1480
- if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
1481
- node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
1482
- else
1483
- applyState(nextValue, wrap2(previousValue), keyFn);
1353
+ if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue)) {
1354
+ tracked?.write(void 0);
1355
+ node?.write(isWrappable(nextValue) ? wrap(nextValue, target) : nextValue);
1356
+ } else
1357
+ applyState(nextValue, wrap(previousValue, target), keyFn, all);
1484
1358
  }
1485
1359
  }
1486
1360
  if (nodes = target[STORE_HAS]) {
@@ -1490,17 +1364,69 @@ function applyState(next, state, keyFn) {
1490
1364
  }
1491
1365
  }
1492
1366
  }
1493
- function reconcile(value, key) {
1367
+ function reconcile(value, key, all = false) {
1494
1368
  return (state) => {
1495
1369
  const keyFn = typeof key === "string" ? (item) => item[key] : key;
1496
- if (keyFn(value) !== keyFn(state))
1370
+ const eq = keyFn(state);
1371
+ if (eq !== void 0 && keyFn(value) !== keyFn(state))
1497
1372
  throw new Error("Cannot reconcile states with different identity");
1498
- applyState(value, state, keyFn);
1499
- return state;
1373
+ applyState(value, state, keyFn, all);
1500
1374
  };
1501
1375
  }
1502
1376
 
1503
1377
  // src/store/utils.ts
1378
+ function snapshot(item, map, lookup) {
1379
+ let target, isArray, override, result, unwrapped, v;
1380
+ if (!isWrappable(item))
1381
+ return item;
1382
+ if (map && map.has(item))
1383
+ return map.get(item);
1384
+ if (!map)
1385
+ map = /* @__PURE__ */ new Map();
1386
+ if (target = item[$TARGET] || lookup?.get(item)?.[$TARGET]) {
1387
+ override = target[STORE_OVERRIDE];
1388
+ isArray = Array.isArray(target[STORE_VALUE]);
1389
+ map.set(
1390
+ item,
1391
+ override ? result = isArray ? [] : Object.create(Object.getPrototypeOf(target[STORE_VALUE])) : target[STORE_VALUE]
1392
+ );
1393
+ item = target[STORE_VALUE];
1394
+ lookup = storeLookup;
1395
+ } else {
1396
+ isArray = Array.isArray(item);
1397
+ map.set(item, item);
1398
+ }
1399
+ if (isArray) {
1400
+ const len = override?.length || item.length;
1401
+ for (let i = 0; i < len; i++) {
1402
+ v = override && i in override ? override[i] : item[i];
1403
+ if (v === $DELETED)
1404
+ continue;
1405
+ if ((unwrapped = snapshot(v, map, lookup)) !== v || result) {
1406
+ if (!result)
1407
+ map.set(item, result = [...item]);
1408
+ result[i] = unwrapped;
1409
+ }
1410
+ }
1411
+ } else {
1412
+ const keys = getKeys(item, override);
1413
+ for (let i = 0, l = keys.length; i < l; i++) {
1414
+ let prop = keys[i];
1415
+ const desc = getPropertyDescriptor(item, override, prop);
1416
+ if (desc.get)
1417
+ continue;
1418
+ v = override && prop in override ? override[prop] : item[prop];
1419
+ if ((unwrapped = snapshot(v, map, lookup)) !== item[prop] || result) {
1420
+ if (!result) {
1421
+ result = Object.create(Object.getPrototypeOf(item));
1422
+ Object.assign(result, item);
1423
+ }
1424
+ result[prop] = unwrapped;
1425
+ }
1426
+ }
1427
+ }
1428
+ return result || item;
1429
+ }
1504
1430
  function trueFn() {
1505
1431
  return true;
1506
1432
  }
@@ -1652,33 +1578,34 @@ function omit(props, ...keys) {
1652
1578
  function mapArray(list, map, options) {
1653
1579
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1654
1580
  return updateKeyedMap.bind({
1655
- H: new Owner(),
1581
+ G: new Owner(),
1656
1582
  i: 0,
1657
- _: list,
1583
+ $: list,
1658
1584
  u: [],
1659
1585
  C: map,
1660
- d: [],
1586
+ e: [],
1661
1587
  b: [],
1662
1588
  D: keyFn,
1663
1589
  j: keyFn || options?.keyed === false ? [] : void 0,
1664
1590
  k: map.length > 1 ? [] : void 0,
1665
- I: options?.fallback
1591
+ H: options?.fallback
1666
1592
  });
1667
1593
  }
1594
+ var pureOptions = { pureWrite: true };
1668
1595
  function updateKeyedMap() {
1669
- const newItems = this._() || [], newLen = newItems.length;
1596
+ const newItems = this.$() || [], newLen = newItems.length;
1670
1597
  newItems[$TRACK];
1671
- runWithOwner(this.H, () => {
1598
+ runWithOwner(this.G, () => {
1672
1599
  let i, j, mapper = this.j ? () => {
1673
- this.j[j] = new Computation(newItems[j], null);
1674
- this.k && (this.k[j] = new Computation(j, null));
1600
+ this.j[j] = new Computation(newItems[j], null, pureOptions);
1601
+ this.k && (this.k[j] = new Computation(j, null, pureOptions));
1675
1602
  return this.C(
1676
1603
  Computation.prototype.read.bind(this.j[j]),
1677
1604
  this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
1678
1605
  );
1679
1606
  } : this.k ? () => {
1680
1607
  const item = newItems[j];
1681
- this.k[j] = new Computation(j, null);
1608
+ this.k[j] = new Computation(j, null, pureOptions);
1682
1609
  return this.C(() => item, Computation.prototype.read.bind(this.k[j]));
1683
1610
  } : () => {
1684
1611
  const item = newItems[j];
@@ -1686,28 +1613,28 @@ function updateKeyedMap() {
1686
1613
  };
1687
1614
  if (newLen === 0) {
1688
1615
  if (this.i !== 0) {
1689
- this.H.dispose(false);
1616
+ this.G.dispose(false);
1690
1617
  this.b = [];
1691
1618
  this.u = [];
1692
- this.d = [];
1619
+ this.e = [];
1693
1620
  this.i = 0;
1694
1621
  this.j && (this.j = []);
1695
1622
  this.k && (this.k = []);
1696
1623
  }
1697
- if (this.I && !this.d[0]) {
1698
- this.d[0] = compute(
1624
+ if (this.H && !this.e[0]) {
1625
+ this.e[0] = compute(
1699
1626
  this.b[0] = new Owner(),
1700
- this.I,
1627
+ this.H,
1701
1628
  null
1702
1629
  );
1703
1630
  }
1704
1631
  } else if (this.i === 0) {
1705
1632
  if (this.b[0])
1706
1633
  this.b[0].dispose();
1707
- this.d = new Array(newLen);
1634
+ this.e = new Array(newLen);
1708
1635
  for (j = 0; j < newLen; j++) {
1709
1636
  this.u[j] = newItems[j];
1710
- this.d[j] = compute(this.b[j] = new Owner(), mapper, null);
1637
+ this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1711
1638
  }
1712
1639
  this.i = newLen;
1713
1640
  } else {
@@ -1717,7 +1644,7 @@ function updateKeyedMap() {
1717
1644
  this.j[start].write(newItems[start]);
1718
1645
  }
1719
1646
  for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.u[end] === newItems[newEnd] || this.j && compare(this.D, this.u[end], newItems[newEnd])); end--, newEnd--) {
1720
- temp[newEnd] = this.d[end];
1647
+ temp[newEnd] = this.e[end];
1721
1648
  tempNodes[newEnd] = this.b[end];
1722
1649
  tempRows && (tempRows[newEnd] = this.j[end]);
1723
1650
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
@@ -1736,7 +1663,7 @@ function updateKeyedMap() {
1736
1663
  key = this.D ? this.D(item) : item;
1737
1664
  j = newIndices.get(key);
1738
1665
  if (j !== void 0 && j !== -1) {
1739
- temp[j] = this.d[i];
1666
+ temp[j] = this.e[i];
1740
1667
  tempNodes[j] = this.b[i];
1741
1668
  tempRows && (tempRows[j] = this.j[i]);
1742
1669
  tempIndexes && (tempIndexes[j] = this.k[i]);
@@ -1747,7 +1674,7 @@ function updateKeyedMap() {
1747
1674
  }
1748
1675
  for (j = start; j < newLen; j++) {
1749
1676
  if (j in temp) {
1750
- this.d[j] = temp[j];
1677
+ this.e[j] = temp[j];
1751
1678
  this.b[j] = tempNodes[j];
1752
1679
  if (tempRows) {
1753
1680
  this.j[j] = tempRows[j];
@@ -1758,43 +1685,43 @@ function updateKeyedMap() {
1758
1685
  this.k[j].write(j);
1759
1686
  }
1760
1687
  } else {
1761
- this.d[j] = compute(this.b[j] = new Owner(), mapper, null);
1688
+ this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1762
1689
  }
1763
1690
  }
1764
- this.d = this.d.slice(0, this.i = newLen);
1691
+ this.e = this.e.slice(0, this.i = newLen);
1765
1692
  this.u = newItems.slice(0);
1766
1693
  }
1767
1694
  });
1768
- return this.d;
1695
+ return this.e;
1769
1696
  }
1770
1697
  function repeat(count, map, options) {
1771
1698
  return updateRepeat.bind({
1772
- H: new Owner(),
1699
+ G: new Owner(),
1773
1700
  i: 0,
1774
1701
  q: 0,
1775
- $: count,
1702
+ aa: count,
1776
1703
  C: map,
1777
1704
  b: [],
1778
- d: [],
1779
- aa: options?.from,
1780
- I: options?.fallback
1705
+ e: [],
1706
+ ba: options?.from,
1707
+ H: options?.fallback
1781
1708
  });
1782
1709
  }
1783
1710
  function updateRepeat() {
1784
- const newLen = this.$();
1785
- const from = this.aa?.() || 0;
1786
- runWithOwner(this.H, () => {
1711
+ const newLen = this.aa();
1712
+ const from = this.ba?.() || 0;
1713
+ runWithOwner(this.G, () => {
1787
1714
  if (newLen === 0) {
1788
1715
  if (this.i !== 0) {
1789
- this.H.dispose(false);
1716
+ this.G.dispose(false);
1790
1717
  this.b = [];
1791
- this.d = [];
1718
+ this.e = [];
1792
1719
  this.i = 0;
1793
1720
  }
1794
- if (this.I && !this.d[0]) {
1795
- this.d[0] = compute(
1721
+ if (this.H && !this.e[0]) {
1722
+ this.e[0] = compute(
1796
1723
  this.b[0] = new Owner(),
1797
- this.I,
1724
+ this.H,
1798
1725
  null
1799
1726
  );
1800
1727
  }
@@ -1811,18 +1738,18 @@ function updateRepeat() {
1811
1738
  while (i < from && i < this.i)
1812
1739
  this.b[i++].dispose();
1813
1740
  this.b.splice(0, from - this.q);
1814
- this.d.splice(0, from - this.q);
1741
+ this.e.splice(0, from - this.q);
1815
1742
  } else if (this.q > from) {
1816
1743
  let i = prevTo - this.q - 1;
1817
1744
  let difference = this.q - from;
1818
- this.b.length = this.d.length = newLen;
1745
+ this.b.length = this.e.length = newLen;
1819
1746
  while (i >= difference) {
1820
1747
  this.b[i] = this.b[i - difference];
1821
- this.d[i] = this.d[i - difference];
1748
+ this.e[i] = this.e[i - difference];
1822
1749
  i--;
1823
1750
  }
1824
1751
  for (let i2 = 0; i2 < difference; i2++) {
1825
- this.d[i2] = compute(
1752
+ this.e[i2] = compute(
1826
1753
  this.b[i2] = new Owner(),
1827
1754
  () => this.C(i2 + from),
1828
1755
  null
@@ -1830,20 +1757,214 @@ function updateRepeat() {
1830
1757
  }
1831
1758
  }
1832
1759
  for (let i = prevTo; i < to; i++) {
1833
- this.d[i - from] = compute(
1760
+ this.e[i - from] = compute(
1834
1761
  this.b[i - from] = new Owner(),
1835
1762
  () => this.C(i),
1836
1763
  null
1837
1764
  );
1838
1765
  }
1839
- this.d = this.d.slice(0, newLen);
1766
+ this.e = this.e.slice(0, newLen);
1840
1767
  this.q = from;
1841
1768
  this.i = newLen;
1842
1769
  });
1843
- return this.d;
1770
+ return this.e;
1844
1771
  }
1845
1772
  function compare(key, a, b) {
1846
1773
  return key ? key(a) === key(b) : true;
1847
1774
  }
1848
1775
 
1849
- 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 };
1776
+ // src/boundaries.ts
1777
+ var BoundaryComputation = class extends EagerComputation {
1778
+ I;
1779
+ constructor(compute2, propagationMask) {
1780
+ super(void 0, compute2, { defer: true });
1781
+ this.I = propagationMask;
1782
+ }
1783
+ write(value, flags) {
1784
+ super.write(value, flags & ~this.I);
1785
+ if (this.I & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
1786
+ flags &= ~LOADING_BIT;
1787
+ }
1788
+ this.h.notify(this, this.I, flags);
1789
+ return this.g;
1790
+ }
1791
+ };
1792
+ function createBoundChildren(owner, fn, queue, mask) {
1793
+ const parentQueue = owner.h;
1794
+ parentQueue.addChild(owner.h = queue);
1795
+ onCleanup(() => parentQueue.removeChild(owner.h));
1796
+ return compute(
1797
+ owner,
1798
+ () => {
1799
+ const c = new Computation(void 0, fn);
1800
+ return new BoundaryComputation(() => flatten(c.wait()), mask);
1801
+ },
1802
+ null
1803
+ );
1804
+ }
1805
+ var ConditionalQueue = class extends Queue {
1806
+ n;
1807
+ O = /* @__PURE__ */ new Set();
1808
+ P = /* @__PURE__ */ new Set();
1809
+ constructor(disabled) {
1810
+ super();
1811
+ this.n = disabled;
1812
+ }
1813
+ run(type) {
1814
+ if (!type || this.n.read())
1815
+ return;
1816
+ return super.run(type);
1817
+ }
1818
+ notify(node, type, flags) {
1819
+ if (this.n.read()) {
1820
+ if (type & LOADING_BIT) {
1821
+ if (flags & LOADING_BIT) {
1822
+ this.P.add(node);
1823
+ type &= ~LOADING_BIT;
1824
+ } else if (this.P.delete(node))
1825
+ type &= ~LOADING_BIT;
1826
+ }
1827
+ if (type & ERROR_BIT) {
1828
+ if (flags & ERROR_BIT) {
1829
+ this.O.add(node);
1830
+ type &= ~ERROR_BIT;
1831
+ } else if (this.O.delete(node))
1832
+ type &= ~ERROR_BIT;
1833
+ }
1834
+ }
1835
+ return type ? super.notify(node, type, flags) : true;
1836
+ }
1837
+ };
1838
+ var CollectionQueue = class extends Queue {
1839
+ Q;
1840
+ b = /* @__PURE__ */ new Set();
1841
+ n = new Computation(false, null, { pureWrite: true });
1842
+ constructor(type) {
1843
+ super();
1844
+ this.Q = type;
1845
+ }
1846
+ run(type) {
1847
+ if (!type || this.n.read())
1848
+ return;
1849
+ return super.run(type);
1850
+ }
1851
+ notify(node, type, flags) {
1852
+ if (!(type & this.Q))
1853
+ return super.notify(node, type, flags);
1854
+ if (flags & this.Q) {
1855
+ this.b.add(node);
1856
+ if (this.b.size === 1)
1857
+ this.n.write(true);
1858
+ } else {
1859
+ this.b.delete(node);
1860
+ if (this.b.size === 0)
1861
+ this.n.write(false);
1862
+ }
1863
+ type &= ~this.Q;
1864
+ return type ? super.notify(node, type, flags) : true;
1865
+ }
1866
+ };
1867
+ function createBoundary(fn, condition) {
1868
+ const owner = new Owner();
1869
+ const queue = new ConditionalQueue(
1870
+ new Computation(void 0, () => condition() === "hidden" /* HIDDEN */)
1871
+ );
1872
+ const tree = createBoundChildren(owner, fn, queue, 0);
1873
+ new EagerComputation(void 0, () => {
1874
+ const disabled = queue.n.read();
1875
+ tree.I = disabled ? ERROR_BIT | LOADING_BIT : 0;
1876
+ if (!disabled) {
1877
+ queue.P.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
1878
+ queue.O.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
1879
+ queue.P.clear();
1880
+ queue.O.clear();
1881
+ }
1882
+ });
1883
+ return () => queue.n.read() ? void 0 : tree.read();
1884
+ }
1885
+ function createCollectionBoundary(type, fn, fallback) {
1886
+ const owner = new Owner();
1887
+ const queue = new CollectionQueue(type);
1888
+ const tree = createBoundChildren(owner, fn, queue, type);
1889
+ const decision = new Computation(void 0, () => {
1890
+ if (!queue.n.read()) {
1891
+ const resolved = tree.read();
1892
+ if (!queue.n.read())
1893
+ return resolved;
1894
+ }
1895
+ return fallback(queue);
1896
+ });
1897
+ return decision.read.bind(decision);
1898
+ }
1899
+ function createSuspense(fn, fallback) {
1900
+ return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
1901
+ }
1902
+ function createErrorBoundary(fn, fallback) {
1903
+ return createCollectionBoundary(
1904
+ ERROR_BIT,
1905
+ fn,
1906
+ (queue) => fallback(queue.b.values().next().value.F, () => {
1907
+ incrementClock();
1908
+ for (let node of queue.b) {
1909
+ node.a = STATE_DIRTY;
1910
+ node.h?.enqueue(node.s, node);
1911
+ }
1912
+ })
1913
+ );
1914
+ }
1915
+ function flatten(children, options) {
1916
+ if (typeof children === "function" && !children.length) {
1917
+ if (options?.doNotUnwrap)
1918
+ return children;
1919
+ do {
1920
+ children = children();
1921
+ } while (typeof children === "function" && !children.length);
1922
+ }
1923
+ if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
1924
+ return;
1925
+ if (Array.isArray(children)) {
1926
+ let results = [];
1927
+ if (flattenArray(children, results, options)) {
1928
+ return () => {
1929
+ let nested = [];
1930
+ flattenArray(results, nested, { ...options, doNotUnwrap: false });
1931
+ return nested;
1932
+ };
1933
+ }
1934
+ return results;
1935
+ }
1936
+ return children;
1937
+ }
1938
+ function flattenArray(children, results = [], options) {
1939
+ let notReady = null;
1940
+ let needsUnwrap = false;
1941
+ for (let i = 0; i < children.length; i++) {
1942
+ try {
1943
+ let child = children[i];
1944
+ if (typeof child === "function" && !child.length) {
1945
+ if (options?.doNotUnwrap) {
1946
+ results.push(child);
1947
+ needsUnwrap = true;
1948
+ continue;
1949
+ }
1950
+ do {
1951
+ child = child();
1952
+ } while (typeof child === "function" && !child.length);
1953
+ }
1954
+ if (Array.isArray(child)) {
1955
+ needsUnwrap = flattenArray(child, results, options);
1956
+ } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
1957
+ } else
1958
+ results.push(child);
1959
+ } catch (e) {
1960
+ if (!(e instanceof NotReadyError))
1961
+ throw e;
1962
+ notReady = e;
1963
+ }
1964
+ }
1965
+ if (notReady)
1966
+ throw notReady;
1967
+ return needsUnwrap;
1968
+ }
1969
+
1970
+ export { $PROXY, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createOptimistic, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flush, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, snapshot, transition, tryCatch, untrack };