@solidjs/signals 0.0.1 → 0.0.3

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
@@ -46,30 +46,30 @@ var Owner = class {
46
46
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
47
47
  // However, the children are actually added in reverse creation order
48
48
  // See comment at the top of the file for an example of the _nextSibling traversal
49
- q = null;
50
- l = null;
49
+ r = null;
50
+ m = null;
51
51
  o = null;
52
52
  a = STATE_CLEAN;
53
- g = null;
54
- m = defaultContext;
55
53
  h = null;
54
+ n = defaultContext;
55
+ i = null;
56
56
  e = null;
57
57
  constructor(signal = false) {
58
58
  if (currentOwner && !signal)
59
59
  currentOwner.append(this);
60
60
  }
61
61
  append(child) {
62
- child.q = this;
62
+ child.r = this;
63
63
  child.o = this;
64
- if (this.l)
65
- this.l.o = child;
66
- child.l = this.l;
67
- this.l = child;
68
- if (child.m !== this.m) {
69
- child.m = { ...this.m, ...child.m };
64
+ if (this.m)
65
+ this.m.o = child;
66
+ child.m = this.m;
67
+ this.m = child;
68
+ if (child.n !== this.n) {
69
+ child.n = { ...this.n, ...child.n };
70
70
  }
71
- if (this.h) {
72
- child.h = !child.h ? this.h : [...child.h, ...this.h];
71
+ if (this.i) {
72
+ child.i = !child.i ? this.i : [...child.i, ...this.i];
73
73
  }
74
74
  if (this.e)
75
75
  child.e = this.e;
@@ -77,51 +77,51 @@ var Owner = class {
77
77
  dispose(self = true) {
78
78
  if (this.a === STATE_DISPOSED)
79
79
  return;
80
- let head = self ? this.o || this.q : this, current = this.l, next = null;
81
- while (current && current.q === this) {
80
+ let head = self ? this.o || this.r : this, current = this.m, next = null;
81
+ while (current && current.r === this) {
82
82
  current.dispose(true);
83
- current.w();
84
- next = current.l;
85
- current.l = null;
83
+ current.x();
84
+ next = current.m;
85
+ current.m = null;
86
86
  current = next;
87
87
  }
88
88
  if (self)
89
- this.w();
89
+ this.x();
90
90
  if (current)
91
91
  current.o = !self ? this : this.o;
92
92
  if (head)
93
- head.l = current;
93
+ head.m = current;
94
94
  }
95
- w() {
95
+ x() {
96
96
  if (this.o)
97
- this.o.l = null;
98
- this.q = null;
97
+ this.o.m = null;
98
+ this.r = null;
99
99
  this.o = null;
100
- this.m = defaultContext;
101
- this.h = null;
100
+ this.n = defaultContext;
101
+ this.i = null;
102
102
  this.a = STATE_DISPOSED;
103
103
  this.emptyDisposal();
104
104
  }
105
105
  emptyDisposal() {
106
- if (!this.g)
106
+ if (!this.h)
107
107
  return;
108
- if (Array.isArray(this.g)) {
109
- for (let i = 0; i < this.g.length; i++) {
110
- const callable = this.g[i];
108
+ if (Array.isArray(this.h)) {
109
+ for (let i = 0; i < this.h.length; i++) {
110
+ const callable = this.h[i];
111
111
  callable.call(callable);
112
112
  }
113
113
  } else {
114
- this.g.call(this.g);
114
+ this.h.call(this.h);
115
115
  }
116
- this.g = null;
116
+ this.h = null;
117
117
  }
118
118
  handleError(error) {
119
- if (!this.h)
119
+ if (!this.i)
120
120
  throw error;
121
- let i = 0, len = this.h.length;
121
+ let i = 0, len = this.i.length;
122
122
  for (i = 0; i < len; i++) {
123
123
  try {
124
- this.h[i](error);
124
+ this.i[i](error);
125
125
  break;
126
126
  } catch (e) {
127
127
  error = e;
@@ -138,7 +138,7 @@ function getContext(context, owner = currentOwner) {
138
138
  if (!owner) {
139
139
  throw new NoOwnerError();
140
140
  }
141
- const value = hasContext(context, owner) ? owner.m[context.id] : context.defaultValue;
141
+ const value = hasContext(context, owner) ? owner.n[context.id] : context.defaultValue;
142
142
  if (isUndefined(value)) {
143
143
  throw new ContextNotFoundError();
144
144
  }
@@ -148,24 +148,24 @@ function setContext(context, value, owner = currentOwner) {
148
148
  if (!owner) {
149
149
  throw new NoOwnerError();
150
150
  }
151
- owner.m = {
152
- ...owner.m,
151
+ owner.n = {
152
+ ...owner.n,
153
153
  [context.id]: isUndefined(value) ? context.defaultValue : value
154
154
  };
155
155
  }
156
156
  function hasContext(context, owner = currentOwner) {
157
- return !isUndefined(owner?.m[context.id]);
157
+ return !isUndefined(owner?.n[context.id]);
158
158
  }
159
159
  function onCleanup(disposable) {
160
160
  if (!currentOwner)
161
161
  return;
162
162
  const node = currentOwner;
163
- if (!node.g) {
164
- node.g = disposable;
165
- } else if (Array.isArray(node.g)) {
166
- node.g.push(disposable);
163
+ if (!node.h) {
164
+ node.h = disposable;
165
+ } else if (Array.isArray(node.h)) {
166
+ node.h.push(disposable);
167
167
  } else {
168
- node.g = [node.g, disposable];
168
+ node.h = [node.h, disposable];
169
169
  }
170
170
  }
171
171
 
@@ -196,37 +196,37 @@ var Computation = class extends Owner {
196
196
  b = null;
197
197
  c = null;
198
198
  d;
199
- C;
199
+ D;
200
200
  // Used in __DEV__ mode, hopefully removed in production
201
- U;
201
+ V;
202
202
  // Using false is an optimization as an alternative to _equals: () => false
203
203
  // which could enable more efficient DIRTY notification
204
- D = isEqual;
204
+ E = isEqual;
205
205
  N;
206
206
  /** Whether the computation is an error or has ancestors that are unresolved */
207
- i = 0;
207
+ j = 0;
208
208
  /** Which flags raised by sources are handled, vs. being passed through. */
209
209
  A = DEFAULT_FLAGS;
210
- E = null;
211
210
  F = null;
212
- G = -1;
211
+ G = null;
212
+ H = -1;
213
213
  constructor(initialValue, compute2, options) {
214
214
  super(compute2 === null);
215
- this.C = compute2;
215
+ this.D = compute2;
216
216
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
217
217
  this.d = initialValue;
218
218
  if (options?.equals !== void 0)
219
- this.D = options.equals;
219
+ this.E = options.equals;
220
220
  if (options?.unobserved)
221
221
  this.N = options?.unobserved;
222
222
  }
223
223
  O() {
224
- if (this.C)
225
- this.r();
224
+ if (this.D)
225
+ this.s();
226
226
  if (!this.b || this.b.length)
227
227
  track(this);
228
- newFlags |= this.i & ~currentMask;
229
- if (this.i & ERROR_BIT) {
228
+ newFlags |= this.j & ~currentMask;
229
+ if (this.j & ERROR_BIT) {
230
230
  throw this.d;
231
231
  } else {
232
232
  return this.d;
@@ -260,34 +260,34 @@ var Computation = class extends Owner {
260
260
  * loading state changes
261
261
  */
262
262
  loading() {
263
- if (this.F === null) {
264
- this.F = loadingState(this);
263
+ if (this.G === null) {
264
+ this.G = loadingState(this);
265
265
  }
266
- return this.F.read();
266
+ return this.G.read();
267
267
  }
268
268
  /**
269
269
  * Return true if the computation is the computation threw an error
270
270
  * Triggers re-execution of the computation when the error state changes
271
271
  */
272
272
  error() {
273
- if (this.E === null) {
274
- this.E = errorState(this);
273
+ if (this.F === null) {
274
+ this.F = errorState(this);
275
275
  }
276
- return this.E.read();
276
+ return this.F.read();
277
277
  }
278
278
  /** Update the computation with a new value. */
279
279
  write(value, flags = 0, raw = false) {
280
280
  const newValue = !raw && typeof value === "function" ? value(this.d) : value;
281
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.D === false || !this.D(this.d, newValue));
281
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.E === false || !this.E(this.d, newValue));
282
282
  if (valueChanged)
283
283
  this.d = newValue;
284
- const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
285
- this.i = flags;
286
- this.G = clock + 1;
284
+ const changedFlagsMask = this.j ^ flags, changedFlags = changedFlagsMask & flags;
285
+ this.j = flags;
286
+ this.H = clock + 1;
287
287
  if (this.c) {
288
288
  for (let i = 0; i < this.c.length; i++) {
289
289
  if (valueChanged) {
290
- this.c[i].s(STATE_DIRTY);
290
+ this.c[i].t(STATE_DIRTY);
291
291
  } else if (changedFlagsMask) {
292
292
  this.c[i].P(changedFlagsMask, changedFlags);
293
293
  }
@@ -298,13 +298,13 @@ var Computation = class extends Owner {
298
298
  /**
299
299
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
300
300
  */
301
- s(state) {
301
+ t(state) {
302
302
  if (this.a >= state)
303
303
  return;
304
304
  this.a = state;
305
305
  if (this.c) {
306
306
  for (let i = 0; i < this.c.length; i++) {
307
- this.c[i].s(STATE_CHECK);
307
+ this.c[i].t(STATE_CHECK);
308
308
  }
309
309
  }
310
310
  }
@@ -318,17 +318,17 @@ var Computation = class extends Owner {
318
318
  if (this.a >= STATE_DIRTY)
319
319
  return;
320
320
  if (mask & this.A) {
321
- this.s(STATE_DIRTY);
321
+ this.t(STATE_DIRTY);
322
322
  return;
323
323
  }
324
324
  if (this.a >= STATE_CHECK)
325
325
  return;
326
- const prevFlags = this.i & mask;
326
+ const prevFlags = this.j & mask;
327
327
  const deltaFlags = prevFlags ^ newFlags2;
328
328
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
329
- this.s(STATE_CHECK);
329
+ this.t(STATE_CHECK);
330
330
  } else {
331
- this.i ^= deltaFlags;
331
+ this.j ^= deltaFlags;
332
332
  if (this.c) {
333
333
  for (let i = 0; i < this.c.length; i++) {
334
334
  this.c[i].P(mask, newFlags2);
@@ -337,7 +337,7 @@ var Computation = class extends Owner {
337
337
  }
338
338
  }
339
339
  Q(error) {
340
- this.write(error, this.i | ERROR_BIT);
340
+ this.write(error, this.j | ERROR_BIT);
341
341
  }
342
342
  /**
343
343
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -346,7 +346,7 @@ var Computation = class extends Owner {
346
346
  *
347
347
  * This function will ensure that the value and states we read from the computation are up to date
348
348
  */
349
- r() {
349
+ s() {
350
350
  if (this.a === STATE_DISPOSED) {
351
351
  throw new Error("Tried to read a disposed computation");
352
352
  }
@@ -356,8 +356,8 @@ var Computation = class extends Owner {
356
356
  let observerFlags = 0;
357
357
  if (this.a === STATE_CHECK) {
358
358
  for (let i = 0; i < this.b.length; i++) {
359
- this.b[i].r();
360
- observerFlags |= this.b[i].i;
359
+ this.b[i].s();
360
+ observerFlags |= this.b[i].j;
361
361
  if (this.a === STATE_DIRTY) {
362
362
  break;
363
363
  }
@@ -373,23 +373,23 @@ var Computation = class extends Owner {
373
373
  /**
374
374
  * Remove ourselves from the owner graph and the computation graph
375
375
  */
376
- w() {
376
+ x() {
377
377
  if (this.a === STATE_DISPOSED)
378
378
  return;
379
379
  if (this.b)
380
380
  removeSourceObservers(this, 0);
381
- super.w();
381
+ super.x();
382
382
  }
383
383
  };
384
384
  function loadingState(node) {
385
- const prevOwner = setOwner(node.q);
385
+ const prevOwner = setOwner(node.r);
386
386
  const options = void 0;
387
387
  const computation = new Computation(
388
388
  void 0,
389
389
  () => {
390
390
  track(node);
391
- node.r();
392
- return !!(node.i & LOADING_BIT);
391
+ node.s();
392
+ return !!(node.j & LOADING_BIT);
393
393
  },
394
394
  options
395
395
  );
@@ -398,14 +398,14 @@ function loadingState(node) {
398
398
  return computation;
399
399
  }
400
400
  function errorState(node) {
401
- const prevOwner = setOwner(node.q);
401
+ const prevOwner = setOwner(node.r);
402
402
  const options = void 0;
403
403
  const computation = new Computation(
404
404
  void 0,
405
405
  () => {
406
406
  track(node);
407
- node.r();
408
- return !!(node.i & ERROR_BIT);
407
+ node.s();
408
+ return !!(node.j & ERROR_BIT);
409
409
  },
410
410
  options
411
411
  );
@@ -423,7 +423,7 @@ function track(computation) {
423
423
  newSources.push(computation);
424
424
  }
425
425
  if (updateCheck) {
426
- updateCheck.d = computation.G > currentObserver.G;
426
+ updateCheck.d = computation.H > currentObserver.H;
427
427
  }
428
428
  }
429
429
  }
@@ -435,7 +435,7 @@ function update(node) {
435
435
  try {
436
436
  node.dispose(false);
437
437
  node.emptyDisposal();
438
- const result = compute(node, node.C, node);
438
+ const result = compute(node, node.D, node);
439
439
  node.write(result, newFlags, true);
440
440
  } catch (error) {
441
441
  if (error instanceof NotReadyError) {
@@ -546,50 +546,50 @@ function schedule() {
546
546
  queueMicrotask(flushSync);
547
547
  }
548
548
  var Queue = class {
549
- H = false;
550
- t = [[], [], []];
551
- y = [];
549
+ I = false;
550
+ u = [[], [], []];
551
+ z = [];
552
552
  enqueue(type, node) {
553
- this.t[0].push(node);
553
+ this.u[0].push(node);
554
554
  if (type)
555
- this.t[type].push(node);
555
+ this.u[type].push(node);
556
556
  schedule();
557
557
  }
558
558
  run(type) {
559
- if (this.t[type].length) {
559
+ if (this.u[type].length) {
560
560
  if (type === EFFECT_PURE) {
561
- runPureQueue(this.t[type]);
562
- this.t[type] = [];
561
+ runPureQueue(this.u[type]);
562
+ this.u[type] = [];
563
563
  } else {
564
- const effects = this.t[type];
565
- this.t[type] = [];
564
+ const effects = this.u[type];
565
+ this.u[type] = [];
566
566
  runEffectQueue(effects);
567
567
  }
568
568
  }
569
- for (let i = 0; i < this.y.length; i++) {
570
- this.y[i].run(type);
569
+ for (let i = 0; i < this.z.length; i++) {
570
+ this.z[i].run(type);
571
571
  }
572
572
  }
573
573
  flush() {
574
- if (this.H)
574
+ if (this.I)
575
575
  return;
576
- this.H = true;
576
+ this.I = true;
577
577
  try {
578
578
  this.run(EFFECT_PURE);
579
579
  incrementClock();
580
580
  this.run(EFFECT_RENDER);
581
581
  this.run(EFFECT_USER);
582
582
  } finally {
583
- this.H = false;
583
+ this.I = false;
584
584
  }
585
585
  }
586
586
  addChild(child) {
587
- this.y.push(child);
587
+ this.z.push(child);
588
588
  }
589
589
  removeChild(child) {
590
- const index = this.y.indexOf(child);
590
+ const index = this.z.indexOf(child);
591
591
  if (index >= 0)
592
- this.y.splice(index, 1);
592
+ this.z.splice(index, 1);
593
593
  }
594
594
  };
595
595
  var globalQueue = new Queue();
@@ -606,14 +606,14 @@ function createBoundary(fn, queue) {
606
606
  }
607
607
  function runTop(node) {
608
608
  const ancestors = [];
609
- for (let current = node; current !== null; current = current.q) {
609
+ for (let current = node; current !== null; current = current.r) {
610
610
  if (current.a !== STATE_CLEAN) {
611
611
  ancestors.push(current);
612
612
  }
613
613
  }
614
614
  for (let i = ancestors.length - 1; i >= 0; i--) {
615
615
  if (ancestors[i].a !== STATE_DISPOSED)
616
- ancestors[i].r();
616
+ ancestors[i].s();
617
617
  }
618
618
  }
619
619
  function runPureQueue(queue) {
@@ -623,57 +623,59 @@ function runPureQueue(queue) {
623
623
  }
624
624
  }
625
625
  function runEffectQueue(queue) {
626
- for (let i = 0; i < queue.length; i++) {
627
- if (queue[i].I && queue[i].a !== STATE_DISPOSED) {
628
- queue[i].J(queue[i].d, queue[i].B);
629
- queue[i].I = false;
630
- queue[i].B = queue[i].d;
631
- }
632
- }
626
+ for (let i = 0; i < queue.length; i++)
627
+ queue[i].R();
633
628
  }
634
629
 
635
630
  // src/core/effect.ts
636
631
  var Effect = class extends Computation {
637
632
  J;
638
- I = false;
633
+ K = false;
639
634
  B;
640
- K;
635
+ C;
641
636
  e;
642
637
  constructor(initialValue, compute2, effect, options) {
643
638
  super(initialValue, compute2, options);
644
639
  this.J = effect;
645
640
  this.B = initialValue;
646
- this.K = options?.render ? EFFECT_RENDER : EFFECT_USER;
641
+ this.C = options?.render ? EFFECT_RENDER : EFFECT_USER;
647
642
  this.e = getOwner()?.e || globalQueue;
648
- this.e.enqueue(this.K, this);
649
- this.r();
643
+ this.s();
644
+ this.C === EFFECT_USER ? this.e.enqueue(this.C, this) : this.R();
650
645
  }
651
646
  write(value, flags = 0) {
652
- const currentFlags = this.i;
653
- this.i = flags;
647
+ const currentFlags = this.j;
648
+ this.j = flags;
654
649
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
655
- this.e.S?.(this);
650
+ this.e.T?.(this);
656
651
  }
657
652
  if (value === UNCHANGED)
658
653
  return this.d;
659
654
  this.d = value;
660
- this.I = true;
655
+ this.K = true;
661
656
  return value;
662
657
  }
663
- s(state) {
658
+ t(state) {
664
659
  if (this.a >= state)
665
660
  return;
666
661
  if (this.a === STATE_CLEAN)
667
- this.e.enqueue(this.K, this);
662
+ this.e.enqueue(this.C, this);
668
663
  this.a = state;
669
664
  }
670
665
  Q(error) {
671
666
  this.handleError(error);
672
667
  }
673
- w() {
668
+ x() {
674
669
  this.J = void 0;
675
670
  this.B = void 0;
676
- super.w();
671
+ super.x();
672
+ }
673
+ R() {
674
+ if (this.K && this.a !== STATE_DISPOSED) {
675
+ this.J(this.d, this.B);
676
+ this.B = this.d;
677
+ this.K = false;
678
+ }
677
679
  }
678
680
  };
679
681
  var EagerComputation = class extends Computation {
@@ -681,38 +683,38 @@ var EagerComputation = class extends Computation {
681
683
  constructor(initialValue, compute2, options) {
682
684
  super(initialValue, compute2, options);
683
685
  this.e = getOwner()?.e || globalQueue;
684
- this.r();
686
+ this.s();
685
687
  }
686
- s(state) {
688
+ t(state) {
687
689
  if (this.a >= state)
688
690
  return;
689
691
  if (this.a === STATE_CLEAN)
690
692
  this.e.enqueue(EFFECT_PURE, this);
691
- super.s(state);
693
+ super.t(state);
692
694
  }
693
695
  };
694
696
 
695
697
  // src/core/suspense.ts
696
698
  var SuspenseQueue = class extends Queue {
697
- k = /* @__PURE__ */ new Set();
698
- z = false;
699
+ f = /* @__PURE__ */ new Set();
700
+ p = false;
699
701
  L = new Computation(false, null);
700
702
  run(type) {
701
- if (type && this.z)
703
+ if (type && this.p)
702
704
  return;
703
705
  super.run(type);
704
706
  }
705
- S(node) {
706
- if (node.i & LOADING_BIT) {
707
- this.k.add(node);
708
- if (!this.z) {
709
- this.z = true;
707
+ T(node) {
708
+ if (node.j & LOADING_BIT) {
709
+ this.f.add(node);
710
+ if (!this.p) {
711
+ this.p = true;
710
712
  queueMicrotask(() => this.L.write(true));
711
713
  }
712
714
  } else {
713
- this.k.delete(node);
714
- if (this.k.size === 0) {
715
- this.z = false;
715
+ this.f.delete(node);
716
+ if (this.f.size === 0) {
717
+ this.p = false;
716
718
  queueMicrotask(() => this.L.write(false));
717
719
  }
718
720
  }
@@ -721,7 +723,7 @@ var SuspenseQueue = class extends Queue {
721
723
  function createSuspense(fn, fallbackFn) {
722
724
  const queue = new SuspenseQueue();
723
725
  const tree = createBoundary(fn, queue);
724
- const equality = new Computation(null, () => queue.L.read() || queue.z);
726
+ const equality = new Computation(null, () => queue.L.read() || queue.p);
725
727
  const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
726
728
  return comp.read.bind(comp);
727
729
  }
@@ -831,7 +833,7 @@ function runWithOwner(owner, run) {
831
833
  }
832
834
  function catchError(fn, handler) {
833
835
  const owner = new Owner();
834
- owner.h = owner.h ? [handler, ...owner.h] : [handler];
836
+ owner.i = owner.i ? [handler, ...owner.i] : [handler];
835
837
  try {
836
838
  compute(owner, fn, null);
837
839
  } catch (error) {
@@ -849,15 +851,22 @@ var STORE_NODE = "n";
849
851
  var STORE_HAS = "h";
850
852
  function wrap(value) {
851
853
  let p = value[$PROXY];
852
- if (!p)
854
+ if (!p) {
855
+ let target;
856
+ if (Array.isArray(value)) {
857
+ target = [];
858
+ target.v = value;
859
+ } else
860
+ target = { v: value };
853
861
  Object.defineProperty(value, $PROXY, {
854
- value: p = new Proxy({ v: value }, proxyTraps),
862
+ value: p = new Proxy(target, proxyTraps),
855
863
  writable: true
856
864
  });
865
+ }
857
866
  return p;
858
867
  }
859
868
  function isWrappable(obj) {
860
- return obj != null && typeof obj === "object";
869
+ return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
861
870
  }
862
871
  function unwrap(item, deep = true, set) {
863
872
  let result, unwrapped, v, prop;
@@ -909,8 +918,10 @@ function getNode(nodes, property, value, equals = isEqual) {
909
918
  });
910
919
  }
911
920
  function proxyDescriptor(target, property) {
921
+ if (property === $PROXY)
922
+ return { value: target[$PROXY], writable: true, configurable: true };
912
923
  const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
913
- if (!desc || desc.get || !desc.configurable || property === $PROXY)
924
+ if (!desc || desc.get || !desc.configurable)
914
925
  return desc;
915
926
  delete desc.value;
916
927
  delete desc.writable;
@@ -976,7 +987,10 @@ var proxyTraps = {
976
987
  return true;
977
988
  },
978
989
  ownKeys,
979
- getOwnPropertyDescriptor: proxyDescriptor
990
+ getOwnPropertyDescriptor: proxyDescriptor,
991
+ getPrototypeOf(target) {
992
+ return Object.getPrototypeOf(target[STORE_VALUE]);
993
+ }
980
994
  };
981
995
  function setProperty(state, property, value, deleting = false) {
982
996
  const prev = state[property];
@@ -1130,6 +1144,7 @@ function reconcile(value, key) {
1130
1144
  if (keyFn(value) !== keyFn(state))
1131
1145
  throw new Error("Cannot reconcile states with different identity");
1132
1146
  applyState(value, state, keyFn);
1147
+ return state;
1133
1148
  };
1134
1149
  }
1135
1150
 
@@ -1170,7 +1185,7 @@ function resolveSource(s) {
1170
1185
  }
1171
1186
  var $SOURCES = Symbol(0);
1172
1187
  function merge(...sources) {
1173
- if (sources.length === 1)
1188
+ if (sources.length === 1 && typeof sources[0] !== "function")
1174
1189
  return sources[0];
1175
1190
  let proxy = false;
1176
1191
  const flattened = [];
@@ -1284,120 +1299,120 @@ function omit(props, ...keys) {
1284
1299
  // src/map.ts
1285
1300
  function mapArray(list, map, options) {
1286
1301
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1287
- return Computation.prototype.read.bind(
1288
- new Computation(
1289
- [],
1290
- updateKeyedMap.bind({
1291
- R: new Owner(),
1292
- u: 0,
1293
- T: list,
1294
- p: [],
1295
- M: map,
1296
- n: [],
1297
- k: [],
1298
- x: keyFn,
1299
- f: keyFn || options?.keyed === false ? [] : void 0,
1300
- j: map.length > 1 ? [] : void 0
1301
- }),
1302
- options
1303
- )
1304
- );
1302
+ return updateKeyedMap.bind({
1303
+ S: new Owner(),
1304
+ w: 0,
1305
+ U: list,
1306
+ q: [],
1307
+ M: map,
1308
+ k: [],
1309
+ f: [],
1310
+ y: keyFn,
1311
+ g: keyFn || options?.keyed === false ? [] : void 0,
1312
+ l: map.length > 1 ? [] : void 0,
1313
+ p: options?.fallback
1314
+ });
1305
1315
  }
1306
1316
  function updateKeyedMap() {
1307
- const newItems = this.T() || [], newLen = newItems.length;
1317
+ const newItems = this.U() || [], newLen = newItems.length;
1308
1318
  newItems[$TRACK];
1309
- runWithOwner(this.R, () => {
1310
- let i, j, mapper = this.f ? () => {
1311
- this.f[j] = new Computation(newItems[j], null);
1312
- this.j[j] = new Computation(j, null);
1319
+ runWithOwner(this.S, () => {
1320
+ let i, j, mapper = this.g ? () => {
1321
+ this.g[j] = new Computation(newItems[j], null);
1322
+ this.l[j] = new Computation(j, null);
1313
1323
  return this.M(
1314
- Computation.prototype.read.bind(this.f[j]),
1315
- Computation.prototype.read.bind(this.j[j])
1324
+ Computation.prototype.read.bind(this.g[j]),
1325
+ Computation.prototype.read.bind(this.l[j])
1316
1326
  );
1317
- } : this.j ? () => {
1327
+ } : this.l ? () => {
1318
1328
  const item = newItems[j];
1319
- this.j[j] = new Computation(j, null);
1320
- return this.M(() => item, Computation.prototype.read.bind(this.j[j]));
1329
+ this.l[j] = new Computation(j, null);
1330
+ return this.M(() => item, Computation.prototype.read.bind(this.l[j]));
1321
1331
  } : () => {
1322
1332
  const item = newItems[j];
1323
1333
  return this.M(() => item);
1324
1334
  };
1325
1335
  if (newLen === 0) {
1326
- if (this.u !== 0) {
1327
- this.R.dispose(false);
1336
+ if (this.w !== 0) {
1337
+ this.S.dispose(false);
1338
+ this.f = [];
1339
+ this.q = [];
1328
1340
  this.k = [];
1329
- this.p = [];
1330
- this.n = [];
1331
- this.u = 0;
1332
- this.f && (this.f = []);
1333
- this.j && (this.j = []);
1341
+ this.w = 0;
1342
+ this.g && (this.g = []);
1343
+ this.l && (this.l = []);
1344
+ }
1345
+ if (this.p && !this.k[0]) {
1346
+ this.k[0] = compute(this.f[0] = new Owner(), this.p, null);
1334
1347
  }
1335
- } else if (this.u === 0) {
1336
- this.n = new Array(newLen);
1348
+ } else if (this.w === 0) {
1349
+ if (this.f[0])
1350
+ this.f[0].dispose();
1351
+ this.k = new Array(newLen);
1337
1352
  for (j = 0; j < newLen; j++) {
1338
- this.p[j] = newItems[j];
1339
- this.n[j] = compute(this.k[j] = new Owner(), mapper, null);
1353
+ this.q[j] = newItems[j];
1354
+ this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
1340
1355
  }
1341
- this.u = newLen;
1356
+ this.w = newLen;
1342
1357
  } else {
1343
- let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.f ? new Array(newLen) : void 0, tempIndexes = this.j ? new Array(newLen) : void 0;
1344
- for (start = 0, end = Math.min(this.u, newLen); start < end && (this.p[start] === newItems[start] || this.f && compare(this.x, this.p[start], newItems[start])); start++) {
1345
- if (this.f)
1346
- this.f[start].write(newItems[start]);
1358
+ let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.g ? new Array(newLen) : void 0, tempIndexes = this.l ? new Array(newLen) : void 0;
1359
+ for (start = 0, end = Math.min(this.w, newLen); start < end && (this.q[start] === newItems[start] || this.g && compare(this.y, this.q[start], newItems[start])); start++) {
1360
+ if (this.g)
1361
+ this.g[start].write(newItems[start]);
1347
1362
  }
1348
- for (end = this.u - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.p[end] === newItems[newEnd] || this.f && compare(this.x, this.p[end], newItems[newEnd])); end--, newEnd--) {
1349
- temp[newEnd] = this.n[end];
1350
- tempNodes[newEnd] = this.k[end];
1351
- tempRows && (tempRows[newEnd] = this.f[end]);
1352
- tempIndexes && (tempIndexes[newEnd] = this.j[end]);
1363
+ for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.q[end] === newItems[newEnd] || this.g && compare(this.y, this.q[end], newItems[newEnd])); end--, newEnd--) {
1364
+ temp[newEnd] = this.k[end];
1365
+ tempNodes[newEnd] = this.f[end];
1366
+ tempRows && (tempRows[newEnd] = this.g[end]);
1367
+ tempIndexes && (tempIndexes[newEnd] = this.l[end]);
1353
1368
  }
1354
1369
  newIndices = /* @__PURE__ */ new Map();
1355
1370
  newIndicesNext = new Array(newEnd + 1);
1356
1371
  for (j = newEnd; j >= start; j--) {
1357
1372
  item = newItems[j];
1358
- key = this.x ? this.x(item) : item;
1373
+ key = this.y ? this.y(item) : item;
1359
1374
  i = newIndices.get(key);
1360
1375
  newIndicesNext[j] = i === void 0 ? -1 : i;
1361
1376
  newIndices.set(key, j);
1362
1377
  }
1363
1378
  for (i = start; i <= end; i++) {
1364
- item = this.p[i];
1365
- key = this.x ? this.x(item) : item;
1379
+ item = this.q[i];
1380
+ key = this.y ? this.y(item) : item;
1366
1381
  j = newIndices.get(key);
1367
1382
  if (j !== void 0 && j !== -1) {
1368
- temp[j] = this.n[i];
1369
- tempNodes[j] = this.k[i];
1370
- tempRows && (tempRows[j] = this.f[i]);
1371
- tempIndexes && (tempIndexes[j] = this.j[i]);
1383
+ temp[j] = this.k[i];
1384
+ tempNodes[j] = this.f[i];
1385
+ tempRows && (tempRows[j] = this.g[i]);
1386
+ tempIndexes && (tempIndexes[j] = this.l[i]);
1372
1387
  j = newIndicesNext[j];
1373
1388
  newIndices.set(key, j);
1374
1389
  } else
1375
- this.k[i].dispose();
1390
+ this.f[i].dispose();
1376
1391
  }
1377
1392
  for (j = start; j < newLen; j++) {
1378
1393
  if (j in temp) {
1379
- this.n[j] = temp[j];
1380
- this.k[j] = tempNodes[j];
1394
+ this.k[j] = temp[j];
1395
+ this.f[j] = tempNodes[j];
1381
1396
  if (tempRows) {
1382
- this.f[j] = tempRows[j];
1383
- this.f[j].write(newItems[j]);
1397
+ this.g[j] = tempRows[j];
1398
+ this.g[j].write(newItems[j]);
1384
1399
  }
1385
1400
  if (tempIndexes) {
1386
- this.j[j] = tempIndexes[j];
1387
- this.j[j].write(j);
1401
+ this.l[j] = tempIndexes[j];
1402
+ this.l[j].write(j);
1388
1403
  }
1389
1404
  } else {
1390
- this.n[j] = compute(this.k[j] = new Owner(), mapper, null);
1405
+ this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
1391
1406
  }
1392
1407
  }
1393
- this.n = this.n.slice(0, this.u = newLen);
1394
- this.p = newItems.slice(0);
1408
+ this.k = this.k.slice(0, this.w = newLen);
1409
+ this.q = newItems.slice(0);
1395
1410
  }
1396
1411
  });
1397
- return this.n;
1412
+ return this.k;
1398
1413
  }
1399
1414
  function compare(key, a, b) {
1400
1415
  return key ? key(a) === key(b) : true;
1401
1416
  }
1402
1417
 
1403
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
1418
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };