@solidjs/signals 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/prod.js CHANGED
@@ -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;
@@ -43,40 +37,40 @@ function schedule() {
43
37
  if (scheduled)
44
38
  return;
45
39
  scheduled = true;
46
- if (!globalQueue.J)
47
- queueMicrotask(flushSync);
40
+ if (!globalQueue.K)
41
+ queueMicrotask(flush);
48
42
  }
49
43
  var pureQueue = [];
50
44
  var Queue = class {
51
45
  o = null;
52
- J = false;
53
- K = [[], []];
54
- E = [];
46
+ K = false;
47
+ L = [[], []];
48
+ F = [];
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.L[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
- } else if (this.K[type - 1].length) {
68
- const effects = this.K[type - 1];
69
- this.K[type - 1] = [];
70
- runEffectQueue(effects);
61
+ } else if (this.L[type - 1].length) {
62
+ const effects = this.L[type - 1];
63
+ this.L[type - 1] = [];
64
+ runQueue(effects, type);
71
65
  }
72
- for (let i = 0; i < this.E.length; i++) {
73
- this.E[i].run(type);
66
+ for (let i = 0; i < this.F.length; i++) {
67
+ this.F[i].run(type);
74
68
  }
75
69
  }
76
70
  flush() {
77
- if (this.J)
71
+ if (this.K)
78
72
  return;
79
- this.J = true;
73
+ this.K = true;
80
74
  try {
81
75
  this.run(EFFECT_PURE);
82
76
  incrementClock();
@@ -84,17 +78,17 @@ var Queue = class {
84
78
  this.run(EFFECT_RENDER);
85
79
  this.run(EFFECT_USER);
86
80
  } finally {
87
- this.J = false;
81
+ this.K = false;
88
82
  }
89
83
  }
90
84
  addChild(child) {
91
- this.E.push(child);
85
+ this.F.push(child);
92
86
  child.o = this;
93
87
  }
94
88
  removeChild(child) {
95
- const index = this.E.indexOf(child);
89
+ const index = this.F.indexOf(child);
96
90
  if (index >= 0)
97
- this.E.splice(index, 1);
91
+ this.F.splice(index, 1);
98
92
  }
99
93
  notify(...args) {
100
94
  if (this.o)
@@ -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,27 +155,27 @@ 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
- current.y();
161
+ current.z();
215
162
  next = current.m;
216
163
  current.m = null;
217
164
  current = next;
218
165
  }
219
166
  this.W = 0;
220
167
  if (self)
221
- this.y();
168
+ this.z();
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
- y() {
228
- if (this.s)
229
- this.s.m = null;
174
+ z() {
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,44 +270,47 @@ 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
- F;
321
- z;
275
+ G;
276
+ A;
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
281
  S = 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
287
  T = DEFAULT_FLAGS;
332
- A = -1;
333
- w = false;
288
+ B = -1;
289
+ x = false;
334
290
  constructor(initialValue, compute2, options) {
335
- super(null, compute2 === null);
336
- this.z = compute2;
291
+ super(options?.id, compute2 === null);
292
+ this.A = 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
297
  this.S = options.equals;
298
+ if (options?.pureWrite)
299
+ this._ = true;
342
300
  if (options?.unobserved)
343
301
  this.X = options?.unobserved;
344
302
  }
345
303
  Y() {
346
- if (this.z) {
347
- if (this.f & ERROR_BIT && this.A <= getClock())
304
+ if (this.A) {
305
+ if (this.f & ERROR_BIT && this.B <= getClock())
348
306
  update(this);
349
307
  else
350
- this.x();
308
+ this.y();
351
309
  }
352
310
  track(this);
353
311
  newFlags |= this.f & ~currentMask;
354
312
  if (this.f & ERROR_BIT) {
355
- throw this.F;
313
+ throw this.G;
356
314
  } else {
357
315
  return this.g;
358
316
  }
@@ -372,10 +330,10 @@ var Computation = class extends Owner {
372
330
  * before continuing
373
331
  */
374
332
  wait() {
375
- if (this.z && this.f & ERROR_BIT && this.A <= getClock()) {
333
+ if (this.A && this.f & ERROR_BIT && this.B <= getClock()) {
376
334
  update(this);
377
335
  } else {
378
- this.x();
336
+ this.y();
379
337
  }
380
338
  track(this);
381
339
  if ((notStale || this.f & UNINITIALIZED_BIT) && this.f & LOADING_BIT) {
@@ -389,20 +347,21 @@ 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.S === false || !this.S(this.g, newValue));
393
352
  if (valueChanged) {
394
353
  this.g = newValue;
395
- this.F = void 0;
354
+ this.G = void 0;
396
355
  }
397
356
  const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
398
357
  this.f = flags;
399
- this.A = getClock() + 1;
400
- if (this.e) {
401
- for (let i = 0; i < this.e.length; i++) {
358
+ this.B = getClock() + 1;
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
  }
@@ -412,13 +371,13 @@ var Computation = class extends Owner {
412
371
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
413
372
  */
414
373
  r(state, skipQueue) {
415
- if (this.a >= state && !this.w)
374
+ if (this.a >= state && !this.x)
416
375
  return;
417
- this.w = !!skipQueue;
376
+ this.x = !!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
  }
@@ -443,15 +402,15 @@ 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
  }
452
411
  }
453
- L(error) {
454
- this.F = error;
412
+ M(error) {
413
+ this.G = error;
455
414
  this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
456
415
  }
457
416
  /**
@@ -461,8 +420,8 @@ var Computation = class extends Owner {
461
420
  *
462
421
  * This function will ensure that the value and states we read from the computation are up to date
463
422
  */
464
- x() {
465
- if (!this.z) {
423
+ y() {
424
+ if (!this.A) {
466
425
  return;
467
426
  }
468
427
  if (this.a === STATE_DISPOSED) {
@@ -474,7 +433,7 @@ var Computation = class extends Owner {
474
433
  let observerFlags = 0;
475
434
  if (this.a === STATE_CHECK) {
476
435
  for (let i = 0; i < this.c.length; i++) {
477
- this.c[i].x();
436
+ this.c[i].y();
478
437
  observerFlags |= this.c[i].f;
479
438
  if (this.a === STATE_DIRTY) {
480
439
  break;
@@ -491,12 +450,12 @@ var Computation = class extends Owner {
491
450
  /**
492
451
  * Remove ourselves from the owner graph and the computation graph
493
452
  */
494
- y() {
453
+ z() {
495
454
  if (this.a === STATE_DISPOSED)
496
455
  return;
497
456
  if (this.c)
498
457
  removeSourceObservers(this, 0);
499
- super.y();
458
+ super.z();
500
459
  }
501
460
  };
502
461
  function track(computation) {
@@ -509,7 +468,7 @@ function track(computation) {
509
468
  newSources.push(computation);
510
469
  }
511
470
  if (updateCheck) {
512
- updateCheck.g = computation.A > currentObserver.A;
471
+ updateCheck.g = computation.B > currentObserver.B;
513
472
  }
514
473
  }
515
474
  }
@@ -521,13 +480,13 @@ function update(node) {
521
480
  try {
522
481
  node.dispose(false);
523
482
  node.emptyDisposal();
524
- const result = compute(node, node.z, node);
483
+ const result = compute(node, node.A, node);
525
484
  node.write(result, newFlags, true);
526
485
  } catch (error) {
527
486
  if (error instanceof NotReadyError) {
528
487
  node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
529
488
  } else {
530
- node.L(error);
489
+ node.M(error);
531
490
  }
532
491
  } finally {
533
492
  if (newSources) {
@@ -544,19 +503,20 @@ 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;
559
- node.A = getClock() + 1;
519
+ node.B = getClock() + 1;
560
520
  node.a = STATE_CLEAN;
561
521
  }
562
522
  }
@@ -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
  }
@@ -645,7 +613,7 @@ function runWithObserver(observer, run) {
645
613
  newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
646
614
  );
647
615
  } else {
648
- observer.L(error);
616
+ observer.M(error);
649
617
  }
650
618
  } finally {
651
619
  if (newSources) {
@@ -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;
@@ -685,118 +653,58 @@ 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 {
753
- M;
659
+ U;
754
660
  N;
755
- B;
756
- U = false;
661
+ C;
662
+ V = false;
757
663
  O;
758
- t;
664
+ s;
759
665
  constructor(initialValue, compute2, effect, error, options) {
760
666
  super(initialValue, compute2, options);
761
- this.M = effect;
667
+ this.U = effect;
762
668
  this.N = error;
763
669
  this.O = initialValue;
764
- this.t = options?.render ? EFFECT_RENDER : EFFECT_USER;
765
- if (this.t === EFFECT_RENDER) {
766
- this.z = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
670
+ this.s = options?.render ? EFFECT_RENDER : EFFECT_USER;
671
+ if (this.s === EFFECT_RENDER) {
672
+ this.A = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
767
673
  }
768
- this.x();
769
- !options?.defer && (this.t === EFFECT_USER ? this.h.enqueue(this.t, this) : this.V());
674
+ this.y();
675
+ !options?.defer && (this.s === EFFECT_USER ? this.h.enqueue(this.s, this.u.bind(this)) : this.u(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
  }
779
685
  if (value === UNCHANGED)
780
686
  return this.g;
781
687
  this.g = value;
782
- this.U = true;
688
+ this.V = true;
783
689
  return value;
784
690
  }
785
691
  r(state, skipQueue) {
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.u.bind(this));
790
696
  this.a = state;
791
697
  }
792
- L(error) {
793
- this.F = error;
794
- this.B?.();
698
+ M(error) {
699
+ this.G = error;
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.N ? this.N(error, () => {
705
+ this.C?.();
706
+ this.C = void 0;
707
+ }) : console.error(error);
800
708
  } catch (e) {
801
709
  error = e;
802
710
  }
@@ -804,187 +712,78 @@ var Effect = class extends Computation {
804
712
  if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
805
713
  throw error;
806
714
  }
807
- y() {
715
+ z() {
808
716
  if (this.a === STATE_DISPOSED)
809
717
  return;
810
- this.M = void 0;
718
+ this.U = void 0;
811
719
  this.O = void 0;
812
720
  this.N = void 0;
813
- this.B?.();
814
- this.B = void 0;
815
- super.y();
816
- }
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;
721
+ this.C?.();
722
+ this.C = void 0;
723
+ super.z();
724
+ }
725
+ u(type) {
726
+ if (type) {
727
+ if (this.V && this.a !== STATE_DISPOSED) {
728
+ this.C?.();
729
+ try {
730
+ this.C = this.U(this.g, this.O);
731
+ } catch (e) {
732
+ if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
733
+ throw e;
734
+ } finally {
735
+ this.O = this.g;
736
+ this.V = false;
737
+ }
828
738
  }
829
- }
739
+ } else
740
+ this.a !== STATE_CLEAN && runTop(this);
830
741
  }
831
742
  };
832
743
  var EagerComputation = class extends Computation {
833
744
  constructor(initialValue, compute2, options) {
834
745
  super(initialValue, compute2, options);
835
- !options?.defer && this.x();
746
+ !options?.defer && this.y();
836
747
  }
837
748
  r(state, skipQueue) {
838
- if (this.a >= state && !this.w)
749
+ if (this.a >= state && !this.x)
839
750
  return;
840
- if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.w))
841
- this.h.enqueue(EFFECT_PURE, this);
751
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.x))
752
+ this.h.enqueue(EFFECT_PURE, this.u.bind(this));
842
753
  super.r(state, skipQueue);
843
754
  }
755
+ u() {
756
+ this.a !== STATE_CLEAN && runTop(this);
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
  }
849
764
  r(state, skipQueue) {
850
- if (this.a >= state && !this.w)
765
+ if (this.a >= state && !this.x)
851
766
  return;
852
- if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.w))
853
- this.h.enqueue(EFFECT_PURE, this);
767
+ if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.x))
768
+ this.h.enqueue(EFFECT_PURE, this.u.bind(this));
854
769
  super.r(state, true);
855
- this.w = !!skipQueue;
770
+ this.x = !!skipQueue;
856
771
  }
857
- };
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;
772
+ u() {
773
+ this.a !== STATE_CLEAN && runTop(this);
873
774
  }
874
775
  };
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;
776
+ function runTop(node) {
777
+ const ancestors = [];
778
+ for (let current = node; current !== null; current = current.o) {
779
+ if (current.a !== STATE_CLEAN) {
780
+ ancestors.push(current);
910
781
  }
911
- return super.notify(node, type, flags);
912
- }
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
782
  }
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;
783
+ for (let i = ancestors.length - 1; i >= 0; i--) {
784
+ if (ancestors[i].a !== STATE_DISPOSED)
785
+ ancestors[i].y();
941
786
  }
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
787
  }
989
788
 
990
789
  // src/signals.ts
@@ -1000,7 +799,13 @@ function createSignal(first, second, third) {
1000
799
  });
1001
800
  return [() => memo()[0](), (value) => memo()[1](value)];
1002
801
  }
1003
- const node = new Computation(first, null, second);
802
+ const o = getOwner();
803
+ const needsId = o?.id != null;
804
+ const node = new Computation(
805
+ first,
806
+ null,
807
+ needsId ? { id: o.getNextChildId(), ...second } : second
808
+ );
1004
809
  return [node.read.bind(node), node.write.bind(node)];
1005
810
  }
1006
811
  function createMemo(compute2, value, options) {
@@ -1026,10 +831,12 @@ function createMemo(compute2, value, options) {
1026
831
  };
1027
832
  }
1028
833
  function createAsync(compute2, value, options) {
834
+ let refreshing = false;
1029
835
  const node = new EagerComputation(
1030
836
  value,
1031
837
  (p) => {
1032
- const source = compute2(p);
838
+ const source = compute2(p, refreshing);
839
+ refreshing = false;
1033
840
  const isPromise = source instanceof Promise;
1034
841
  const iterator = source[Symbol.asyncIterator];
1035
842
  if (!isPromise && !iterator) {
@@ -1047,7 +854,7 @@ function createAsync(compute2, value, options) {
1047
854
  (error) => {
1048
855
  if (abort)
1049
856
  return;
1050
- node.L(error);
857
+ node.M(error);
1051
858
  }
1052
859
  );
1053
860
  } else {
@@ -1069,14 +876,20 @@ function createAsync(compute2, value, options) {
1069
876
  },
1070
877
  options
1071
878
  );
1072
- return node.wait.bind(node);
879
+ const read = node.wait.bind(node);
880
+ read.refresh = () => {
881
+ node.a = STATE_DIRTY;
882
+ refreshing = true;
883
+ node.y();
884
+ };
885
+ return read;
1073
886
  }
1074
- function createEffect(compute2, effect, error, value, options) {
887
+ function createEffect(compute2, effect, value, options) {
1075
888
  void new Effect(
1076
889
  value,
1077
890
  compute2,
1078
- effect,
1079
- error,
891
+ effect.effect ? effect.effect : effect,
892
+ effect.error,
1080
893
  options
1081
894
  );
1082
895
  }
@@ -1109,101 +922,97 @@ function resolve(fn) {
1109
922
  });
1110
923
  });
1111
924
  }
925
+ function tryCatch(fn) {
926
+ try {
927
+ const v = fn();
928
+ if (v instanceof Promise) {
929
+ return v.then(
930
+ (v2) => [void 0, v2],
931
+ (e) => {
932
+ if (e instanceof NotReadyError)
933
+ throw e;
934
+ return [e];
935
+ }
936
+ );
937
+ }
938
+ return [void 0, v];
939
+ } catch (e) {
940
+ if (e instanceof NotReadyError)
941
+ throw e;
942
+ return [e];
943
+ }
944
+ }
945
+ function transition(fn) {
946
+ }
947
+ function createOptimistic(initial, compute2, options) {
948
+ return [];
949
+ }
1112
950
 
1113
951
  // src/store/projection.ts
1114
952
  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);
953
+ let wrappedStore;
954
+ const node = new FirewallComputation(() => {
955
+ storeSetter(wrappedStore, fn);
1121
956
  });
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");
957
+ const wrappedMap = /* @__PURE__ */ new WeakMap();
958
+ const traps = {
959
+ ...storeTraps,
960
+ get(target, property, receiver) {
961
+ const o = getOwner();
962
+ (!o || o !== node) && node.wait();
963
+ return storeTraps.get(target, property, receiver);
1139
964
  }
1140
- });
1141
- wrapped.set(source, wrap3);
1142
- return wrap3;
965
+ };
966
+ function wrapProjection(source) {
967
+ if (wrappedMap.has(source))
968
+ return wrappedMap.get(source);
969
+ if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
970
+ return source;
971
+ const wrapped = createStoreProxy(source, traps, {
972
+ [STORE_WRAP]: wrapProjection,
973
+ [STORE_LOOKUP]: wrappedMap
974
+ });
975
+ wrappedMap.set(source, wrapped);
976
+ return wrapped;
977
+ }
978
+ return wrappedStore = wrapProjection(initialValue);
1143
979
  }
1144
980
 
1145
981
  // src/store/store.ts
1146
- var $RAW = Symbol(0);
1147
982
  var $TRACK = Symbol(0);
1148
983
  var $DEEP = Symbol(0);
1149
984
  var $TARGET = Symbol(0);
1150
985
  var $PROXY = Symbol(0);
986
+ var $DELETED = Symbol(0);
1151
987
  var PARENTS = /* @__PURE__ */ new WeakMap();
1152
988
  var STORE_VALUE = "v";
989
+ var STORE_OVERRIDE = "o";
1153
990
  var STORE_NODE = "n";
1154
991
  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
- }
992
+ var STORE_WRAP = "w";
993
+ var STORE_LOOKUP = "l";
994
+ function createStoreProxy(value, traps = storeTraps, extend) {
995
+ let newTarget;
996
+ if (Array.isArray(value)) {
997
+ newTarget = [];
998
+ newTarget.v = value;
999
+ } else
1000
+ newTarget = { v: value };
1001
+ extend && Object.assign(newTarget, extend);
1002
+ return newTarget[$PROXY] = new Proxy(newTarget, traps);
1003
+ }
1004
+ var storeLookup = /* @__PURE__ */ new WeakMap();
1005
+ function wrap(value, target) {
1006
+ if (target?.[STORE_WRAP])
1007
+ return target[STORE_WRAP](value, target);
1008
+ let p = value[$PROXY] || storeLookup.get(value);
1009
+ if (!p)
1010
+ storeLookup.set(value, p = createStoreProxy(value));
1169
1011
  return p;
1170
1012
  }
1171
1013
  function isWrappable(obj) {
1172
1014
  return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
1173
1015
  }
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
1016
  function getNodes(target, type) {
1208
1017
  let nodes = target[type];
1209
1018
  if (!nodes)
@@ -1220,31 +1029,38 @@ function getNode(nodes, property, value, equals = isEqual) {
1220
1029
  }
1221
1030
  });
1222
1031
  }
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
1032
  function trackSelf(target, symbol = $TRACK) {
1235
1033
  getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
1236
1034
  }
1237
- function ownKeys(target) {
1238
- trackSelf(target);
1239
- return Reflect.ownKeys(target[STORE_VALUE]);
1035
+ function getKeys(source, override, enumerable = true) {
1036
+ const baseKeys = untrack(() => enumerable ? Object.keys(source) : Reflect.ownKeys(source));
1037
+ if (!override)
1038
+ return baseKeys;
1039
+ const keys = new Set(baseKeys);
1040
+ const overrides = Reflect.ownKeys(override);
1041
+ for (const key of overrides) {
1042
+ if (override[key] !== $DELETED)
1043
+ keys.add(key);
1044
+ else
1045
+ keys.delete(key);
1046
+ }
1047
+ return Array.from(keys);
1048
+ }
1049
+ function getPropertyDescriptor(source, override, property) {
1050
+ let value = source;
1051
+ if (override && property in override) {
1052
+ if (value[property] === $DELETED)
1053
+ return void 0;
1054
+ if (!(property in value))
1055
+ value = override;
1056
+ }
1057
+ return Reflect.getOwnPropertyDescriptor(value, property);
1240
1058
  }
1241
1059
  var Writing = null;
1242
- var proxyTraps = {
1060
+ var storeTraps = {
1243
1061
  get(target, property, receiver) {
1244
1062
  if (property === $TARGET)
1245
1063
  return target;
1246
- if (property === $RAW)
1247
- return target[STORE_VALUE];
1248
1064
  if (property === $PROXY)
1249
1065
  return receiver;
1250
1066
  if (property === $TRACK || property === $DEEP) {
@@ -1252,92 +1068,156 @@ var proxyTraps = {
1252
1068
  return receiver;
1253
1069
  }
1254
1070
  const nodes = getNodes(target, STORE_NODE);
1255
- const storeValue = target[STORE_VALUE];
1256
1071
  const tracked = nodes[property];
1072
+ const overridden = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE];
1073
+ const proxySource = !!target[STORE_VALUE][$TARGET];
1074
+ const storeValue = overridden ? target[STORE_OVERRIDE] : target[STORE_VALUE];
1257
1075
  if (!tracked) {
1258
1076
  const desc = Object.getOwnPropertyDescriptor(storeValue, property);
1259
1077
  if (desc && desc.get)
1260
1078
  return desc.get.call(receiver);
1261
1079
  }
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];
1080
+ if (Writing?.has(receiver)) {
1081
+ let value2 = tracked && (overridden || !proxySource) ? tracked.g : storeValue[property];
1082
+ value2 === $DELETED && (value2 = void 0);
1083
+ if (!isWrappable(value2))
1084
+ return value2;
1085
+ const wrapped = wrap(value2, target);
1086
+ Writing.add(wrapped);
1087
+ return wrapped;
1088
+ }
1089
+ let value = tracked ? overridden || !proxySource ? nodes[property].read() : (nodes[property].read(), storeValue[property]) : storeValue[property];
1090
+ value === $DELETED && (value = void 0);
1267
1091
  if (!tracked) {
1268
- if (typeof value === "function" && !storeValue.hasOwnProperty(property)) {
1092
+ if (!overridden && typeof value === "function" && !storeValue.hasOwnProperty(property)) {
1269
1093
  let proto;
1270
- return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
1094
+ return !Array.isArray(target[STORE_VALUE]) && (proto = Object.getPrototypeOf(target[STORE_VALUE])) && proto !== Object.prototype ? value.bind(storeValue) : value;
1271
1095
  } else if (getObserver()) {
1272
- return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
1096
+ return getNode(nodes, property, isWrappable(value) ? wrap(value, target) : value).read();
1273
1097
  }
1274
1098
  }
1275
- return isWrappable(value) ? wrap2(value) : value;
1099
+ return isWrappable(value) ? wrap(value, target) : value;
1276
1100
  },
1277
1101
  has(target, property) {
1278
- if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
1102
+ if (property === $PROXY || property === $TRACK || property === "__proto__")
1279
1103
  return true;
1280
- const has = property in target[STORE_VALUE];
1104
+ const has = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] !== $DELETED : property in target[STORE_VALUE];
1281
1105
  getObserver() && getNode(getNodes(target, STORE_HAS), property, has).read();
1282
1106
  return has;
1283
1107
  },
1284
- set(target, property, value) {
1285
- Writing?.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, unwrap(value, false));
1108
+ set(target, property, rawValue) {
1109
+ const store = target[$PROXY];
1110
+ if (Writing?.has(target[$PROXY])) {
1111
+ untrack(() => {
1112
+ const state = target[STORE_VALUE];
1113
+ const base = state[property];
1114
+ const prev = target[STORE_OVERRIDE]?.[property] || base;
1115
+ const value = rawValue?.[$TARGET]?.[STORE_VALUE] ?? rawValue;
1116
+ if (prev === value)
1117
+ return true;
1118
+ const len = target[STORE_OVERRIDE]?.length || state.length;
1119
+ if (value !== void 0 && value === base)
1120
+ delete target[STORE_OVERRIDE][property];
1121
+ else
1122
+ (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = value;
1123
+ const wrappable = isWrappable(value);
1124
+ if (isWrappable(prev)) {
1125
+ const parents = PARENTS.get(prev);
1126
+ parents && (parents instanceof Set ? parents.delete(store) : PARENTS.delete(prev));
1127
+ }
1128
+ if (recursivelyNotify(store, storeLookup) && wrappable)
1129
+ recursivelyAddParent(value, store);
1130
+ target[STORE_HAS]?.[property]?.write(true);
1131
+ const nodes = getNodes(target, STORE_NODE);
1132
+ nodes[property]?.write(wrappable ? wrap(value, target) : value);
1133
+ if (Array.isArray(state)) {
1134
+ const index = parseInt(property) + 1;
1135
+ if (index > len)
1136
+ nodes.length?.write(index);
1137
+ }
1138
+ nodes[$TRACK]?.write(void 0);
1139
+ });
1140
+ }
1286
1141
  return true;
1287
1142
  },
1288
1143
  deleteProperty(target, property) {
1289
- Writing?.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, void 0, true);
1144
+ if (Writing?.has(target[$PROXY]) && target[STORE_OVERRIDE]?.[property] !== $DELETED) {
1145
+ untrack(() => {
1146
+ const prev = target[STORE_OVERRIDE]?.[property] || target[STORE_VALUE][property];
1147
+ if (property in target[STORE_VALUE]) {
1148
+ (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
1149
+ } else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
1150
+ delete target[STORE_OVERRIDE][property];
1151
+ } else
1152
+ return true;
1153
+ if (isWrappable(prev)) {
1154
+ const parents = PARENTS.get(prev);
1155
+ parents && (parents instanceof Set ? parents.delete(target) : PARENTS.delete(prev));
1156
+ }
1157
+ target[STORE_HAS]?.[property]?.write(false);
1158
+ const nodes = getNodes(target, STORE_NODE);
1159
+ nodes[property]?.write(void 0);
1160
+ nodes[$TRACK]?.write(void 0);
1161
+ });
1162
+ }
1290
1163
  return true;
1291
1164
  },
1292
- ownKeys,
1293
- getOwnPropertyDescriptor: proxyDescriptor,
1165
+ ownKeys(target) {
1166
+ trackSelf(target);
1167
+ return getKeys(target[STORE_VALUE], target[STORE_OVERRIDE], false);
1168
+ },
1169
+ getOwnPropertyDescriptor(target, property) {
1170
+ if (property === $PROXY)
1171
+ return { value: target[$PROXY], writable: true, configurable: true };
1172
+ return getPropertyDescriptor(target[STORE_VALUE], target[STORE_OVERRIDE], property);
1173
+ },
1294
1174
  getPrototypeOf(target) {
1295
1175
  return Object.getPrototypeOf(target[STORE_VALUE]);
1296
1176
  }
1297
1177
  };
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];
1178
+ function storeSetter(store, fn) {
1179
+ const prevWriting = Writing;
1180
+ Writing = /* @__PURE__ */ new Set();
1181
+ Writing.add(store);
1182
+ try {
1183
+ fn(store);
1184
+ } finally {
1185
+ Writing.clear();
1186
+ Writing = prevWriting;
1187
+ }
1188
+ }
1189
+ function createStore(first, second) {
1190
+ const derived = typeof first === "function", wrappedStore = derived ? createProjection(first, second) : wrap(first);
1191
+ return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
1192
+ }
1193
+ function recursivelyNotify(state, lookup) {
1194
+ let target = state[$TARGET] || lookup?.get(state)?.[$TARGET];
1328
1195
  let notified = false;
1329
- target && (getNodes(target, STORE_NODE)[$DEEP]?.write(void 0), notified = true);
1330
- const parents = PARENTS.get(state);
1196
+ if (target) {
1197
+ const deep2 = getNodes(target, STORE_NODE)[$DEEP];
1198
+ if (deep2) {
1199
+ deep2.write(void 0);
1200
+ notified = true;
1201
+ }
1202
+ lookup = target[STORE_LOOKUP] || lookup;
1203
+ }
1204
+ const parents = PARENTS.get(target?.[STORE_VALUE] || state);
1331
1205
  if (!parents)
1332
1206
  return notified;
1333
1207
  if (parents instanceof Set) {
1334
1208
  for (let parent of parents)
1335
- notified = recursivelyNotify(parent) || notified;
1209
+ notified = recursivelyNotify(parent, lookup) || notified;
1336
1210
  } else
1337
- notified = recursivelyNotify(parents) || notified;
1211
+ notified = recursivelyNotify(parents, lookup) || notified;
1338
1212
  return notified;
1339
1213
  }
1340
1214
  function recursivelyAddParent(state, parent) {
1215
+ let override;
1216
+ const target = state[$TARGET];
1217
+ if (target) {
1218
+ override = target[STORE_OVERRIDE];
1219
+ state = target[STORE_VALUE];
1220
+ }
1341
1221
  if (parent) {
1342
1222
  let parents = PARENTS.get(state);
1343
1223
  if (!parents)
@@ -1352,80 +1232,73 @@ function recursivelyAddParent(state, parent) {
1352
1232
  return;
1353
1233
  }
1354
1234
  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);
1235
+ const len = override?.length || state.length;
1236
+ for (let i = 0; i < len; i++) {
1237
+ const item = override && i in override ? override[i] : state[i];
1238
+ isWrappable(item) && recursivelyAddParent(item, state);
1358
1239
  }
1359
1240
  } else {
1360
- const keys = Object.keys(state);
1241
+ const keys = getKeys(state, override);
1361
1242
  for (let i = 0; i < keys.length; i++) {
1362
- const item = state[keys[i]];
1363
- isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
1243
+ const key = keys[i];
1244
+ const item = override && key in override ? override[key] : state[key];
1245
+ isWrappable(item) && recursivelyAddParent(item, state);
1364
1246
  }
1365
1247
  }
1366
1248
  }
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
1249
  function deep(store) {
1387
- recursivelyAddParent(store[$RAW] || store);
1250
+ recursivelyAddParent(store);
1388
1251
  return store[$DEEP];
1389
1252
  }
1390
1253
 
1391
1254
  // src/store/reconcile.ts
1392
- function applyState(next, state, keyFn) {
1255
+ function unwrap(value) {
1256
+ return value?.[$TARGET]?.[STORE_NODE] ?? value;
1257
+ }
1258
+ function getOverrideValue(value, override, key) {
1259
+ return override && key in override ? override[key] : value[key];
1260
+ }
1261
+ function getAllKeys(value, override, next) {
1262
+ const keys = getKeys(value, override);
1263
+ const nextKeys = Object.keys(next);
1264
+ return Array.from(/* @__PURE__ */ new Set([...keys, ...nextKeys]));
1265
+ }
1266
+ function applyState(next, state, keyFn, all) {
1393
1267
  const target = state?.[$TARGET];
1394
1268
  if (!target)
1395
1269
  return;
1396
1270
  const previous = target[STORE_VALUE];
1397
- if (next === previous)
1271
+ const override = target[STORE_OVERRIDE];
1272
+ if (next === previous && !override)
1398
1273
  return;
1399
- Object.defineProperty(next, $PROXY, {
1400
- value: previous[$PROXY],
1401
- writable: true
1402
- });
1403
- previous[$PROXY] = null;
1274
+ (target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
1404
1275
  target[STORE_VALUE] = next;
1276
+ target[STORE_OVERRIDE] = void 0;
1405
1277
  if (Array.isArray(previous)) {
1406
1278
  let changed = false;
1407
- if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
1279
+ const prevLength = getOverrideValue(previous, override, "length");
1280
+ if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
1408
1281
  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);
1282
+ 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++) {
1283
+ applyState(next[start], wrap(item, target), keyFn, all);
1411
1284
  }
1412
1285
  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];
1286
+ 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--) {
1287
+ temp[newEnd] = item;
1415
1288
  }
1416
1289
  if (start > newEnd || start > end) {
1417
1290
  for (j = start; j <= newEnd; j++) {
1418
1291
  changed = true;
1419
- target[STORE_NODE][j]?.write(wrap2(next[j]));
1292
+ target[STORE_NODE][j]?.write(wrap(next[j], target));
1420
1293
  }
1421
1294
  for (; j < next.length; j++) {
1422
1295
  changed = true;
1423
- const wrapped = wrap2(temp[j]);
1296
+ const wrapped = wrap(temp[j], target);
1424
1297
  target[STORE_NODE][j]?.write(wrapped);
1425
- applyState(next[j], wrapped, keyFn);
1298
+ applyState(next[j], wrapped, keyFn, all);
1426
1299
  }
1427
1300
  changed && target[STORE_NODE][$TRACK]?.write(void 0);
1428
- previous.length !== next.length && target[STORE_NODE].length?.write(next.length);
1301
+ prevLength !== next.length && target[STORE_NODE].length?.write(next.length);
1429
1302
  return;
1430
1303
  }
1431
1304
  newIndicesNext = new Array(newEnd + 1);
@@ -1437,31 +1310,32 @@ function applyState(next, state, keyFn) {
1437
1310
  newIndices.set(keyVal, j);
1438
1311
  }
1439
1312
  for (i = start; i <= end; i++) {
1440
- item = previous[i];
1313
+ item = getOverrideValue(previous, override, i);
1441
1314
  keyVal = item ? keyFn(item) : item;
1442
1315
  j = newIndices.get(keyVal);
1443
1316
  if (j !== void 0 && j !== -1) {
1444
- temp[j] = previous[i];
1317
+ temp[j] = item;
1445
1318
  j = newIndicesNext[j];
1446
1319
  newIndices.set(keyVal, j);
1447
1320
  }
1448
1321
  }
1449
1322
  for (j = start; j < next.length; j++) {
1450
1323
  if (j in temp) {
1451
- const wrapped = wrap2(temp[j]);
1324
+ const wrapped = wrap(temp[j], target);
1452
1325
  target[STORE_NODE][j]?.write(wrapped);
1453
- applyState(next[j], wrapped, keyFn);
1326
+ applyState(next[j], wrapped, keyFn, all);
1454
1327
  } else
1455
- target[STORE_NODE][j]?.write(wrap2(next[j]));
1328
+ target[STORE_NODE][j]?.write(wrap(next[j], target));
1456
1329
  }
1457
1330
  if (start < next.length)
1458
1331
  changed = true;
1459
- } else if (previous.length && next.length) {
1332
+ } else if (prevLength && next.length) {
1460
1333
  for (let i = 0, len = next.length; i < len; i++) {
1461
- isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
1334
+ const item = getOverrideValue(previous, override, i);
1335
+ isWrappable(item) && applyState(next[i], wrap(item, target), keyFn, all);
1462
1336
  }
1463
1337
  }
1464
- if (previous.length !== next.length) {
1338
+ if (prevLength !== next.length) {
1465
1339
  changed = true;
1466
1340
  target[STORE_NODE].length?.write(next.length);
1467
1341
  }
@@ -1470,17 +1344,20 @@ function applyState(next, state, keyFn) {
1470
1344
  }
1471
1345
  let nodes = target[STORE_NODE];
1472
1346
  if (nodes) {
1473
- const keys = Object.keys(nodes);
1347
+ const tracked = nodes[$TRACK];
1348
+ const keys = tracked || all ? getAllKeys(previous, override, next) : Object.keys(nodes);
1474
1349
  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);
1350
+ const key = keys[i];
1351
+ const node = nodes[key];
1352
+ const previousValue = unwrap(getOverrideValue(previous, override, key));
1353
+ let nextValue = unwrap(next[key]);
1478
1354
  if (previousValue === nextValue)
1479
1355
  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);
1356
+ if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue)) {
1357
+ tracked?.write(void 0);
1358
+ node?.write(isWrappable(nextValue) ? wrap(nextValue, target) : nextValue);
1359
+ } else
1360
+ applyState(nextValue, wrap(previousValue, target), keyFn, all);
1484
1361
  }
1485
1362
  }
1486
1363
  if (nodes = target[STORE_HAS]) {
@@ -1490,17 +1367,69 @@ function applyState(next, state, keyFn) {
1490
1367
  }
1491
1368
  }
1492
1369
  }
1493
- function reconcile(value, key) {
1370
+ function reconcile(value, key, all = false) {
1494
1371
  return (state) => {
1495
1372
  const keyFn = typeof key === "string" ? (item) => item[key] : key;
1496
- if (keyFn(value) !== keyFn(state))
1373
+ const eq = keyFn(state);
1374
+ if (eq !== void 0 && keyFn(value) !== keyFn(state))
1497
1375
  throw new Error("Cannot reconcile states with different identity");
1498
- applyState(value, state, keyFn);
1499
- return state;
1376
+ applyState(value, state, keyFn, all);
1500
1377
  };
1501
1378
  }
1502
1379
 
1503
1380
  // src/store/utils.ts
1381
+ function snapshot(item, map, lookup) {
1382
+ let target, isArray, override, result, unwrapped, v;
1383
+ if (!isWrappable(item))
1384
+ return item;
1385
+ if (map && map.has(item))
1386
+ return map.get(item);
1387
+ if (!map)
1388
+ map = /* @__PURE__ */ new Map();
1389
+ if (target = item[$TARGET] || lookup?.get(item)?.[$TARGET]) {
1390
+ override = target[STORE_OVERRIDE];
1391
+ isArray = Array.isArray(target[STORE_VALUE]);
1392
+ map.set(
1393
+ item,
1394
+ override ? result = isArray ? [] : Object.create(Object.getPrototypeOf(target[STORE_VALUE])) : target[STORE_VALUE]
1395
+ );
1396
+ item = target[STORE_VALUE];
1397
+ lookup = storeLookup;
1398
+ } else {
1399
+ isArray = Array.isArray(item);
1400
+ map.set(item, item);
1401
+ }
1402
+ if (isArray) {
1403
+ const len = override?.length || item.length;
1404
+ for (let i = 0; i < len; i++) {
1405
+ v = override && i in override ? override[i] : item[i];
1406
+ if (v === $DELETED)
1407
+ continue;
1408
+ if ((unwrapped = snapshot(v, map, lookup)) !== v || result) {
1409
+ if (!result)
1410
+ map.set(item, result = [...item]);
1411
+ result[i] = unwrapped;
1412
+ }
1413
+ }
1414
+ } else {
1415
+ const keys = getKeys(item, override);
1416
+ for (let i = 0, l = keys.length; i < l; i++) {
1417
+ let prop = keys[i];
1418
+ const desc = getPropertyDescriptor(item, override, prop);
1419
+ if (desc.get)
1420
+ continue;
1421
+ v = override && prop in override ? override[prop] : item[prop];
1422
+ if ((unwrapped = snapshot(v, map, lookup)) !== item[prop] || result) {
1423
+ if (!result) {
1424
+ result = Object.create(Object.getPrototypeOf(item));
1425
+ Object.assign(result, item);
1426
+ }
1427
+ result[prop] = unwrapped;
1428
+ }
1429
+ }
1430
+ }
1431
+ return result || item;
1432
+ }
1504
1433
  function trueFn() {
1505
1434
  return true;
1506
1435
  }
@@ -1654,48 +1583,49 @@ function mapArray(list, map, options) {
1654
1583
  return updateKeyedMap.bind({
1655
1584
  H: new Owner(),
1656
1585
  i: 0,
1657
- _: list,
1658
- u: [],
1659
- C: map,
1660
- d: [],
1586
+ $: list,
1587
+ w: [],
1588
+ D: map,
1589
+ e: [],
1661
1590
  b: [],
1662
- D: keyFn,
1591
+ E: keyFn,
1663
1592
  j: keyFn || options?.keyed === false ? [] : void 0,
1664
1593
  k: map.length > 1 ? [] : void 0,
1665
1594
  I: options?.fallback
1666
1595
  });
1667
1596
  }
1597
+ var pureOptions = { pureWrite: true };
1668
1598
  function updateKeyedMap() {
1669
- const newItems = this._() || [], newLen = newItems.length;
1599
+ const newItems = this.$() || [], newLen = newItems.length;
1670
1600
  newItems[$TRACK];
1671
1601
  runWithOwner(this.H, () => {
1672
1602
  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));
1675
- return this.C(
1603
+ this.j[j] = new Computation(newItems[j], null, pureOptions);
1604
+ this.k && (this.k[j] = new Computation(j, null, pureOptions));
1605
+ return this.D(
1676
1606
  Computation.prototype.read.bind(this.j[j]),
1677
1607
  this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
1678
1608
  );
1679
1609
  } : this.k ? () => {
1680
1610
  const item = newItems[j];
1681
- this.k[j] = new Computation(j, null);
1682
- return this.C(() => item, Computation.prototype.read.bind(this.k[j]));
1611
+ this.k[j] = new Computation(j, null, pureOptions);
1612
+ return this.D(() => item, Computation.prototype.read.bind(this.k[j]));
1683
1613
  } : () => {
1684
1614
  const item = newItems[j];
1685
- return this.C(() => item);
1615
+ return this.D(() => item);
1686
1616
  };
1687
1617
  if (newLen === 0) {
1688
1618
  if (this.i !== 0) {
1689
1619
  this.H.dispose(false);
1690
1620
  this.b = [];
1691
- this.u = [];
1692
- this.d = [];
1621
+ this.w = [];
1622
+ this.e = [];
1693
1623
  this.i = 0;
1694
1624
  this.j && (this.j = []);
1695
1625
  this.k && (this.k = []);
1696
1626
  }
1697
- if (this.I && !this.d[0]) {
1698
- this.d[0] = compute(
1627
+ if (this.I && !this.e[0]) {
1628
+ this.e[0] = compute(
1699
1629
  this.b[0] = new Owner(),
1700
1630
  this.I,
1701
1631
  null
@@ -1704,20 +1634,20 @@ function updateKeyedMap() {
1704
1634
  } else if (this.i === 0) {
1705
1635
  if (this.b[0])
1706
1636
  this.b[0].dispose();
1707
- this.d = new Array(newLen);
1637
+ this.e = new Array(newLen);
1708
1638
  for (j = 0; j < newLen; j++) {
1709
- this.u[j] = newItems[j];
1710
- this.d[j] = compute(this.b[j] = new Owner(), mapper, null);
1639
+ this.w[j] = newItems[j];
1640
+ this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1711
1641
  }
1712
1642
  this.i = newLen;
1713
1643
  } else {
1714
1644
  let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
1715
- for (start = 0, end = Math.min(this.i, newLen); start < end && (this.u[start] === newItems[start] || this.j && compare(this.D, this.u[start], newItems[start])); start++) {
1645
+ for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.E, this.w[start], newItems[start])); start++) {
1716
1646
  if (this.j)
1717
1647
  this.j[start].write(newItems[start]);
1718
1648
  }
1719
- 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];
1649
+ 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--) {
1650
+ temp[newEnd] = this.e[end];
1721
1651
  tempNodes[newEnd] = this.b[end];
1722
1652
  tempRows && (tempRows[newEnd] = this.j[end]);
1723
1653
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
@@ -1726,17 +1656,17 @@ function updateKeyedMap() {
1726
1656
  newIndicesNext = new Array(newEnd + 1);
1727
1657
  for (j = newEnd; j >= start; j--) {
1728
1658
  item = newItems[j];
1729
- key = this.D ? this.D(item) : item;
1659
+ key = this.E ? this.E(item) : item;
1730
1660
  i = newIndices.get(key);
1731
1661
  newIndicesNext[j] = i === void 0 ? -1 : i;
1732
1662
  newIndices.set(key, j);
1733
1663
  }
1734
1664
  for (i = start; i <= end; i++) {
1735
- item = this.u[i];
1736
- key = this.D ? this.D(item) : item;
1665
+ item = this.w[i];
1666
+ key = this.E ? this.E(item) : item;
1737
1667
  j = newIndices.get(key);
1738
1668
  if (j !== void 0 && j !== -1) {
1739
- temp[j] = this.d[i];
1669
+ temp[j] = this.e[i];
1740
1670
  tempNodes[j] = this.b[i];
1741
1671
  tempRows && (tempRows[j] = this.j[i]);
1742
1672
  tempIndexes && (tempIndexes[j] = this.k[i]);
@@ -1747,7 +1677,7 @@ function updateKeyedMap() {
1747
1677
  }
1748
1678
  for (j = start; j < newLen; j++) {
1749
1679
  if (j in temp) {
1750
- this.d[j] = temp[j];
1680
+ this.e[j] = temp[j];
1751
1681
  this.b[j] = tempNodes[j];
1752
1682
  if (tempRows) {
1753
1683
  this.j[j] = tempRows[j];
@@ -1758,41 +1688,41 @@ function updateKeyedMap() {
1758
1688
  this.k[j].write(j);
1759
1689
  }
1760
1690
  } else {
1761
- this.d[j] = compute(this.b[j] = new Owner(), mapper, null);
1691
+ this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1762
1692
  }
1763
1693
  }
1764
- this.d = this.d.slice(0, this.i = newLen);
1765
- this.u = newItems.slice(0);
1694
+ this.e = this.e.slice(0, this.i = newLen);
1695
+ this.w = newItems.slice(0);
1766
1696
  }
1767
1697
  });
1768
- return this.d;
1698
+ return this.e;
1769
1699
  }
1770
1700
  function repeat(count, map, options) {
1771
1701
  return updateRepeat.bind({
1772
1702
  H: new Owner(),
1773
1703
  i: 0,
1774
1704
  q: 0,
1775
- $: count,
1776
- C: map,
1705
+ aa: count,
1706
+ D: map,
1777
1707
  b: [],
1778
- d: [],
1779
- aa: options?.from,
1708
+ e: [],
1709
+ ba: options?.from,
1780
1710
  I: options?.fallback
1781
1711
  });
1782
1712
  }
1783
1713
  function updateRepeat() {
1784
- const newLen = this.$();
1785
- const from = this.aa?.() || 0;
1714
+ const newLen = this.aa();
1715
+ const from = this.ba?.() || 0;
1786
1716
  runWithOwner(this.H, () => {
1787
1717
  if (newLen === 0) {
1788
1718
  if (this.i !== 0) {
1789
1719
  this.H.dispose(false);
1790
1720
  this.b = [];
1791
- this.d = [];
1721
+ this.e = [];
1792
1722
  this.i = 0;
1793
1723
  }
1794
- if (this.I && !this.d[0]) {
1795
- this.d[0] = compute(
1724
+ if (this.I && !this.e[0]) {
1725
+ this.e[0] = compute(
1796
1726
  this.b[0] = new Owner(),
1797
1727
  this.I,
1798
1728
  null
@@ -1811,39 +1741,233 @@ function updateRepeat() {
1811
1741
  while (i < from && i < this.i)
1812
1742
  this.b[i++].dispose();
1813
1743
  this.b.splice(0, from - this.q);
1814
- this.d.splice(0, from - this.q);
1744
+ this.e.splice(0, from - this.q);
1815
1745
  } else if (this.q > from) {
1816
1746
  let i = prevTo - this.q - 1;
1817
1747
  let difference = this.q - from;
1818
- this.b.length = this.d.length = newLen;
1748
+ this.b.length = this.e.length = newLen;
1819
1749
  while (i >= difference) {
1820
1750
  this.b[i] = this.b[i - difference];
1821
- this.d[i] = this.d[i - difference];
1751
+ this.e[i] = this.e[i - difference];
1822
1752
  i--;
1823
1753
  }
1824
1754
  for (let i2 = 0; i2 < difference; i2++) {
1825
- this.d[i2] = compute(
1755
+ this.e[i2] = compute(
1826
1756
  this.b[i2] = new Owner(),
1827
- () => this.C(i2 + from),
1757
+ () => this.D(i2 + from),
1828
1758
  null
1829
1759
  );
1830
1760
  }
1831
1761
  }
1832
1762
  for (let i = prevTo; i < to; i++) {
1833
- this.d[i - from] = compute(
1763
+ this.e[i - from] = compute(
1834
1764
  this.b[i - from] = new Owner(),
1835
- () => this.C(i),
1765
+ () => this.D(i),
1836
1766
  null
1837
1767
  );
1838
1768
  }
1839
- this.d = this.d.slice(0, newLen);
1769
+ this.e = this.e.slice(0, newLen);
1840
1770
  this.q = from;
1841
1771
  this.i = newLen;
1842
1772
  });
1843
- return this.d;
1773
+ return this.e;
1844
1774
  }
1845
1775
  function compare(key, a, b) {
1846
1776
  return key ? key(a) === key(b) : true;
1847
1777
  }
1848
1778
 
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 };
1779
+ // src/boundaries.ts
1780
+ var BoundaryComputation = class extends EagerComputation {
1781
+ J;
1782
+ constructor(compute2, propagationMask) {
1783
+ super(void 0, compute2, { defer: true });
1784
+ this.J = propagationMask;
1785
+ }
1786
+ write(value, flags) {
1787
+ super.write(value, flags & ~this.J);
1788
+ if (this.J & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
1789
+ flags &= ~LOADING_BIT;
1790
+ }
1791
+ this.h.notify(this, this.J, flags);
1792
+ return this.g;
1793
+ }
1794
+ };
1795
+ function createBoundChildren(owner, fn, queue, mask) {
1796
+ const parentQueue = owner.h;
1797
+ parentQueue.addChild(owner.h = queue);
1798
+ onCleanup(() => parentQueue.removeChild(owner.h));
1799
+ return compute(
1800
+ owner,
1801
+ () => {
1802
+ const c = new Computation(void 0, fn);
1803
+ return new BoundaryComputation(() => flatten(c.wait()), mask);
1804
+ },
1805
+ null
1806
+ );
1807
+ }
1808
+ var ConditionalQueue = class extends Queue {
1809
+ n;
1810
+ P = /* @__PURE__ */ new Set();
1811
+ Q = /* @__PURE__ */ new Set();
1812
+ constructor(disabled) {
1813
+ super();
1814
+ this.n = disabled;
1815
+ }
1816
+ run(type) {
1817
+ if (!type || this.n.read())
1818
+ return;
1819
+ return super.run(type);
1820
+ }
1821
+ notify(node, type, flags) {
1822
+ if (this.n.read()) {
1823
+ if (type & LOADING_BIT) {
1824
+ if (flags & LOADING_BIT) {
1825
+ this.Q.add(node);
1826
+ type &= ~LOADING_BIT;
1827
+ } else if (this.Q.delete(node))
1828
+ type &= ~LOADING_BIT;
1829
+ }
1830
+ if (type & ERROR_BIT) {
1831
+ if (flags & ERROR_BIT) {
1832
+ this.P.add(node);
1833
+ type &= ~ERROR_BIT;
1834
+ } else if (this.P.delete(node))
1835
+ type &= ~ERROR_BIT;
1836
+ }
1837
+ }
1838
+ return type ? super.notify(node, type, flags) : true;
1839
+ }
1840
+ };
1841
+ var CollectionQueue = class extends Queue {
1842
+ R;
1843
+ b = /* @__PURE__ */ new Set();
1844
+ n = new Computation(false, null, { pureWrite: true });
1845
+ constructor(type) {
1846
+ super();
1847
+ this.R = type;
1848
+ }
1849
+ run(type) {
1850
+ if (!type || this.n.read())
1851
+ return;
1852
+ return super.run(type);
1853
+ }
1854
+ notify(node, type, flags) {
1855
+ if (!(type & this.R))
1856
+ return super.notify(node, type, flags);
1857
+ if (flags & this.R) {
1858
+ this.b.add(node);
1859
+ if (this.b.size === 1)
1860
+ this.n.write(true);
1861
+ } else {
1862
+ this.b.delete(node);
1863
+ if (this.b.size === 0)
1864
+ this.n.write(false);
1865
+ }
1866
+ type &= ~this.R;
1867
+ return type ? super.notify(node, type, flags) : true;
1868
+ }
1869
+ };
1870
+ function createBoundary(fn, condition) {
1871
+ const owner = new Owner();
1872
+ const queue = new ConditionalQueue(
1873
+ new Computation(void 0, () => condition() === "hidden" /* HIDDEN */)
1874
+ );
1875
+ const tree = createBoundChildren(owner, fn, queue, 0);
1876
+ new EagerComputation(void 0, () => {
1877
+ const disabled = queue.n.read();
1878
+ tree.J = disabled ? ERROR_BIT | LOADING_BIT : 0;
1879
+ if (!disabled) {
1880
+ queue.Q.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
1881
+ queue.P.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
1882
+ queue.Q.clear();
1883
+ queue.P.clear();
1884
+ }
1885
+ });
1886
+ return () => queue.n.read() ? void 0 : tree.read();
1887
+ }
1888
+ function createCollectionBoundary(type, fn, fallback) {
1889
+ const owner = new Owner();
1890
+ const queue = new CollectionQueue(type);
1891
+ const tree = createBoundChildren(owner, fn, queue, type);
1892
+ const decision = new Computation(void 0, () => {
1893
+ if (!queue.n.read()) {
1894
+ const resolved = tree.read();
1895
+ if (!queue.n.read())
1896
+ return resolved;
1897
+ }
1898
+ return fallback(queue);
1899
+ });
1900
+ return decision.read.bind(decision);
1901
+ }
1902
+ function createSuspense(fn, fallback) {
1903
+ return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
1904
+ }
1905
+ function createErrorBoundary(fn, fallback) {
1906
+ return createCollectionBoundary(
1907
+ ERROR_BIT,
1908
+ fn,
1909
+ (queue) => fallback(queue.b.values().next().value.G, () => {
1910
+ incrementClock();
1911
+ for (let node of queue.b) {
1912
+ node.a = STATE_DIRTY;
1913
+ node.h?.enqueue(node.s, node.u.bind(node));
1914
+ }
1915
+ })
1916
+ );
1917
+ }
1918
+ function flatten(children, options) {
1919
+ if (typeof children === "function" && !children.length) {
1920
+ if (options?.doNotUnwrap)
1921
+ return children;
1922
+ do {
1923
+ children = children();
1924
+ } while (typeof children === "function" && !children.length);
1925
+ }
1926
+ if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
1927
+ return;
1928
+ if (Array.isArray(children)) {
1929
+ let results = [];
1930
+ if (flattenArray(children, results, options)) {
1931
+ return () => {
1932
+ let nested = [];
1933
+ flattenArray(results, nested, { ...options, doNotUnwrap: false });
1934
+ return nested;
1935
+ };
1936
+ }
1937
+ return results;
1938
+ }
1939
+ return children;
1940
+ }
1941
+ function flattenArray(children, results = [], options) {
1942
+ let notReady = null;
1943
+ let needsUnwrap = false;
1944
+ for (let i = 0; i < children.length; i++) {
1945
+ try {
1946
+ let child = children[i];
1947
+ if (typeof child === "function" && !child.length) {
1948
+ if (options?.doNotUnwrap) {
1949
+ results.push(child);
1950
+ needsUnwrap = true;
1951
+ continue;
1952
+ }
1953
+ do {
1954
+ child = child();
1955
+ } while (typeof child === "function" && !child.length);
1956
+ }
1957
+ if (Array.isArray(child)) {
1958
+ needsUnwrap = flattenArray(child, results, options);
1959
+ } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
1960
+ } else
1961
+ results.push(child);
1962
+ } catch (e) {
1963
+ if (!(e instanceof NotReadyError))
1964
+ throw e;
1965
+ notReady = e;
1966
+ }
1967
+ }
1968
+ if (notReady)
1969
+ throw notReady;
1970
+ return needsUnwrap;
1971
+ }
1972
+
1973
+ 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 };