@solidjs/signals 0.0.2 → 0.0.4

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
@@ -25,7 +25,8 @@ function isUndefined(value) {
25
25
  var STATE_CLEAN = 0;
26
26
  var STATE_CHECK = 1;
27
27
  var STATE_DIRTY = 2;
28
- var STATE_DISPOSED = 3;
28
+ var STATE_UNINITIALIZED = 3;
29
+ var STATE_DISPOSED = 4;
29
30
  var EFFECT_PURE = 0;
30
31
  var EFFECT_RENDER = 1;
31
32
  var EFFECT_USER = 2;
@@ -46,30 +47,30 @@ var Owner = class {
46
47
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
47
48
  // However, the children are actually added in reverse creation order
48
49
  // See comment at the top of the file for an example of the _nextSibling traversal
49
- q = null;
50
- l = null;
51
50
  o = null;
51
+ m = null;
52
+ p = null;
52
53
  a = STATE_CLEAN;
53
- g = null;
54
- m = defaultContext;
55
54
  h = null;
55
+ n = defaultContext;
56
+ i = null;
56
57
  e = null;
57
58
  constructor(signal = false) {
58
59
  if (currentOwner && !signal)
59
60
  currentOwner.append(this);
60
61
  }
61
62
  append(child) {
62
- child.q = 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
+ child.p = this;
65
+ if (this.m)
66
+ this.m.p = child;
67
+ child.m = this.m;
68
+ this.m = child;
69
+ if (child.n !== this.n) {
70
+ child.n = { ...this.n, ...child.n };
70
71
  }
71
- if (this.h) {
72
- child.h = !child.h ? this.h : [...child.h, ...this.h];
72
+ if (this.i) {
73
+ child.i = !child.i ? this.i : [...child.i, ...this.i];
73
74
  }
74
75
  if (this.e)
75
76
  child.e = this.e;
@@ -77,51 +78,51 @@ var Owner = class {
77
78
  dispose(self = true) {
78
79
  if (this.a === STATE_DISPOSED)
79
80
  return;
80
- let head = self ? this.o || this.q : this, current = this.l, next = null;
81
- while (current && current.q === this) {
81
+ let head = self ? this.p || this.o : this, current = this.m, next = null;
82
+ while (current && current.o === this) {
82
83
  current.dispose(true);
83
- current.w();
84
- next = current.l;
85
- current.l = null;
84
+ current.x();
85
+ next = current.m;
86
+ current.m = null;
86
87
  current = next;
87
88
  }
88
89
  if (self)
89
- this.w();
90
+ this.x();
90
91
  if (current)
91
- current.o = !self ? this : this.o;
92
+ current.p = !self ? this : this.p;
92
93
  if (head)
93
- head.l = current;
94
+ head.m = current;
94
95
  }
95
- w() {
96
- if (this.o)
97
- this.o.l = null;
98
- this.q = null;
96
+ x() {
97
+ if (this.p)
98
+ this.p.m = null;
99
99
  this.o = null;
100
- this.m = defaultContext;
101
- this.h = null;
100
+ this.p = null;
101
+ this.n = defaultContext;
102
+ this.i = null;
102
103
  this.a = STATE_DISPOSED;
103
104
  this.emptyDisposal();
104
105
  }
105
106
  emptyDisposal() {
106
- if (!this.g)
107
+ if (!this.h)
107
108
  return;
108
- if (Array.isArray(this.g)) {
109
- for (let i = 0; i < this.g.length; i++) {
110
- const callable = this.g[i];
109
+ if (Array.isArray(this.h)) {
110
+ for (let i = 0; i < this.h.length; i++) {
111
+ const callable = this.h[i];
111
112
  callable.call(callable);
112
113
  }
113
114
  } else {
114
- this.g.call(this.g);
115
+ this.h.call(this.h);
115
116
  }
116
- this.g = null;
117
+ this.h = null;
117
118
  }
118
119
  handleError(error) {
119
- if (!this.h)
120
+ if (!this.i)
120
121
  throw error;
121
- let i = 0, len = this.h.length;
122
+ let i = 0, len = this.i.length;
122
123
  for (i = 0; i < len; i++) {
123
124
  try {
124
- this.h[i](error);
125
+ this.i[i](error);
125
126
  break;
126
127
  } catch (e) {
127
128
  error = e;
@@ -138,7 +139,7 @@ function getContext(context, owner = currentOwner) {
138
139
  if (!owner) {
139
140
  throw new NoOwnerError();
140
141
  }
141
- const value = hasContext(context, owner) ? owner.m[context.id] : context.defaultValue;
142
+ const value = hasContext(context, owner) ? owner.n[context.id] : context.defaultValue;
142
143
  if (isUndefined(value)) {
143
144
  throw new ContextNotFoundError();
144
145
  }
@@ -148,25 +149,26 @@ function setContext(context, value, owner = currentOwner) {
148
149
  if (!owner) {
149
150
  throw new NoOwnerError();
150
151
  }
151
- owner.m = {
152
- ...owner.m,
152
+ owner.n = {
153
+ ...owner.n,
153
154
  [context.id]: isUndefined(value) ? context.defaultValue : value
154
155
  };
155
156
  }
156
157
  function hasContext(context, owner = currentOwner) {
157
- return !isUndefined(owner?.m[context.id]);
158
+ return !isUndefined(owner?.n[context.id]);
158
159
  }
159
- function onCleanup(disposable) {
160
+ function onCleanup(fn) {
160
161
  if (!currentOwner)
161
- return;
162
+ return fn;
162
163
  const node = currentOwner;
163
- if (!node.g) {
164
- node.g = disposable;
165
- } else if (Array.isArray(node.g)) {
166
- node.g.push(disposable);
164
+ if (!node.h) {
165
+ node.h = fn;
166
+ } else if (Array.isArray(node.h)) {
167
+ node.h.push(fn);
167
168
  } else {
168
- node.g = [node.g, disposable];
169
+ node.h = [node.h, fn];
169
170
  }
171
+ return fn;
170
172
  }
171
173
 
172
174
  // src/core/flags.ts
@@ -196,37 +198,37 @@ var Computation = class extends Owner {
196
198
  b = null;
197
199
  c = null;
198
200
  d;
199
- D;
201
+ E;
200
202
  // Used in __DEV__ mode, hopefully removed in production
201
203
  V;
202
204
  // Using false is an optimization as an alternative to _equals: () => false
203
205
  // which could enable more efficient DIRTY notification
204
- E = isEqual;
206
+ F = isEqual;
205
207
  N;
206
208
  /** Whether the computation is an error or has ancestors that are unresolved */
207
- i = 0;
209
+ j = 0;
208
210
  /** Which flags raised by sources are handled, vs. being passed through. */
209
211
  A = DEFAULT_FLAGS;
210
- F = null;
211
212
  G = null;
212
- H = -1;
213
+ H = null;
214
+ I = -1;
213
215
  constructor(initialValue, compute2, options) {
214
216
  super(compute2 === null);
215
- this.D = compute2;
216
- this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
217
+ this.E = compute2;
218
+ this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
217
219
  this.d = initialValue;
218
220
  if (options?.equals !== void 0)
219
- this.E = options.equals;
221
+ this.F = options.equals;
220
222
  if (options?.unobserved)
221
223
  this.N = options?.unobserved;
222
224
  }
223
225
  O() {
224
- if (this.D)
225
- this.r();
226
+ if (this.E)
227
+ this.s();
226
228
  if (!this.b || this.b.length)
227
229
  track(this);
228
- newFlags |= this.i & ~currentMask;
229
- if (this.i & ERROR_BIT) {
230
+ newFlags |= this.j & ~currentMask;
231
+ if (this.j & ERROR_BIT) {
230
232
  throw this.d;
231
233
  } else {
232
234
  return this.d;
@@ -260,34 +262,34 @@ var Computation = class extends Owner {
260
262
  * loading state changes
261
263
  */
262
264
  loading() {
263
- if (this.G === null) {
264
- this.G = loadingState(this);
265
+ if (this.H === null) {
266
+ this.H = loadingState(this);
265
267
  }
266
- return this.G.read();
268
+ return this.H.read();
267
269
  }
268
270
  /**
269
271
  * Return true if the computation is the computation threw an error
270
272
  * Triggers re-execution of the computation when the error state changes
271
273
  */
272
274
  error() {
273
- if (this.F === null) {
274
- this.F = errorState(this);
275
+ if (this.G === null) {
276
+ this.G = errorState(this);
275
277
  }
276
- return this.F.read();
278
+ return this.G.read();
277
279
  }
278
280
  /** Update the computation with a new value. */
279
281
  write(value, flags = 0, raw = false) {
280
282
  const newValue = !raw && typeof value === "function" ? value(this.d) : value;
281
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.E === false || !this.E(this.d, newValue));
283
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.F === false || !this.F(this.d, newValue));
282
284
  if (valueChanged)
283
285
  this.d = newValue;
284
- const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
285
- this.i = flags;
286
- this.H = clock + 1;
286
+ const changedFlagsMask = this.j ^ flags, changedFlags = changedFlagsMask & flags;
287
+ this.j = flags;
288
+ this.I = clock + 1;
287
289
  if (this.c) {
288
290
  for (let i = 0; i < this.c.length; i++) {
289
291
  if (valueChanged) {
290
- this.c[i].s(STATE_DIRTY);
292
+ this.c[i].t(STATE_DIRTY);
291
293
  } else if (changedFlagsMask) {
292
294
  this.c[i].P(changedFlagsMask, changedFlags);
293
295
  }
@@ -298,13 +300,13 @@ var Computation = class extends Owner {
298
300
  /**
299
301
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
300
302
  */
301
- s(state) {
303
+ t(state) {
302
304
  if (this.a >= state)
303
305
  return;
304
306
  this.a = state;
305
307
  if (this.c) {
306
308
  for (let i = 0; i < this.c.length; i++) {
307
- this.c[i].s(STATE_CHECK);
309
+ this.c[i].t(STATE_CHECK);
308
310
  }
309
311
  }
310
312
  }
@@ -318,17 +320,17 @@ var Computation = class extends Owner {
318
320
  if (this.a >= STATE_DIRTY)
319
321
  return;
320
322
  if (mask & this.A) {
321
- this.s(STATE_DIRTY);
323
+ this.t(STATE_DIRTY);
322
324
  return;
323
325
  }
324
326
  if (this.a >= STATE_CHECK)
325
327
  return;
326
- const prevFlags = this.i & mask;
328
+ const prevFlags = this.j & mask;
327
329
  const deltaFlags = prevFlags ^ newFlags2;
328
330
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
329
- this.s(STATE_CHECK);
331
+ this.t(STATE_CHECK);
330
332
  } else {
331
- this.i ^= deltaFlags;
333
+ this.j ^= deltaFlags;
332
334
  if (this.c) {
333
335
  for (let i = 0; i < this.c.length; i++) {
334
336
  this.c[i].P(mask, newFlags2);
@@ -337,7 +339,7 @@ var Computation = class extends Owner {
337
339
  }
338
340
  }
339
341
  Q(error) {
340
- this.write(error, this.i | ERROR_BIT);
342
+ this.write(error, this.j | ERROR_BIT);
341
343
  }
342
344
  /**
343
345
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -346,7 +348,7 @@ var Computation = class extends Owner {
346
348
  *
347
349
  * This function will ensure that the value and states we read from the computation are up to date
348
350
  */
349
- r() {
351
+ s() {
350
352
  if (this.a === STATE_DISPOSED) {
351
353
  throw new Error("Tried to read a disposed computation");
352
354
  }
@@ -356,14 +358,14 @@ var Computation = class extends Owner {
356
358
  let observerFlags = 0;
357
359
  if (this.a === STATE_CHECK) {
358
360
  for (let i = 0; i < this.b.length; i++) {
359
- this.b[i].r();
360
- observerFlags |= this.b[i].i;
361
+ this.b[i].s();
362
+ observerFlags |= this.b[i].j;
361
363
  if (this.a === STATE_DIRTY) {
362
364
  break;
363
365
  }
364
366
  }
365
367
  }
366
- if (this.a === STATE_DIRTY) {
368
+ if (this.a === STATE_DIRTY || this.a === STATE_UNINITIALIZED) {
367
369
  update(this);
368
370
  } else {
369
371
  this.write(UNCHANGED, observerFlags);
@@ -373,23 +375,23 @@ var Computation = class extends Owner {
373
375
  /**
374
376
  * Remove ourselves from the owner graph and the computation graph
375
377
  */
376
- w() {
378
+ x() {
377
379
  if (this.a === STATE_DISPOSED)
378
380
  return;
379
381
  if (this.b)
380
382
  removeSourceObservers(this, 0);
381
- super.w();
383
+ super.x();
382
384
  }
383
385
  };
384
386
  function loadingState(node) {
385
- const prevOwner = setOwner(node.q);
387
+ const prevOwner = setOwner(node.o);
386
388
  const options = void 0;
387
389
  const computation = new Computation(
388
390
  void 0,
389
391
  () => {
390
392
  track(node);
391
- node.r();
392
- return !!(node.i & LOADING_BIT);
393
+ node.s();
394
+ return !!(node.j & LOADING_BIT);
393
395
  },
394
396
  options
395
397
  );
@@ -398,14 +400,14 @@ function loadingState(node) {
398
400
  return computation;
399
401
  }
400
402
  function errorState(node) {
401
- const prevOwner = setOwner(node.q);
403
+ const prevOwner = setOwner(node.o);
402
404
  const options = void 0;
403
405
  const computation = new Computation(
404
406
  void 0,
405
407
  () => {
406
408
  track(node);
407
- node.r();
408
- return !!(node.i & ERROR_BIT);
409
+ node.s();
410
+ return !!(node.j & ERROR_BIT);
409
411
  },
410
412
  options
411
413
  );
@@ -423,7 +425,7 @@ function track(computation) {
423
425
  newSources.push(computation);
424
426
  }
425
427
  if (updateCheck) {
426
- updateCheck.d = computation.H > currentObserver.H;
428
+ updateCheck.d = computation.I > currentObserver.I;
427
429
  }
428
430
  }
429
431
  }
@@ -435,7 +437,7 @@ function update(node) {
435
437
  try {
436
438
  node.dispose(false);
437
439
  node.emptyDisposal();
438
- const result = compute(node, node.D, node);
440
+ const result = compute(node, node.E, node);
439
441
  node.write(result, newFlags, true);
440
442
  } catch (error) {
441
443
  if (error instanceof NotReadyError) {
@@ -543,59 +545,62 @@ function schedule() {
543
545
  if (scheduled)
544
546
  return;
545
547
  scheduled = true;
546
- queueMicrotask(flushSync);
548
+ if (!globalQueue.B)
549
+ queueMicrotask(flushSync);
547
550
  }
548
551
  var Queue = class {
549
- I = false;
550
- t = [[], [], []];
551
- y = [];
552
+ B = false;
553
+ u = [[], [], []];
554
+ z = [];
552
555
  enqueue(type, node) {
553
- this.t[0].push(node);
556
+ this.u[0].push(node);
554
557
  if (type)
555
- this.t[type].push(node);
558
+ this.u[type].push(node);
556
559
  schedule();
557
560
  }
558
561
  run(type) {
559
- if (this.t[type].length) {
562
+ if (this.u[type].length) {
560
563
  if (type === EFFECT_PURE) {
561
- runPureQueue(this.t[type]);
562
- this.t[type] = [];
564
+ runPureQueue(this.u[type]);
565
+ this.u[type] = [];
563
566
  } else {
564
- const effects = this.t[type];
565
- this.t[type] = [];
567
+ const effects = this.u[type];
568
+ this.u[type] = [];
566
569
  runEffectQueue(effects);
567
570
  }
568
571
  }
569
- for (let i = 0; i < this.y.length; i++) {
570
- this.y[i].run(type);
572
+ for (let i = 0; i < this.z.length; i++) {
573
+ this.z[i].run(type);
571
574
  }
572
575
  }
573
576
  flush() {
574
- if (this.I)
577
+ if (this.B)
575
578
  return;
576
- this.I = true;
579
+ this.B = true;
577
580
  try {
578
581
  this.run(EFFECT_PURE);
579
582
  incrementClock();
583
+ scheduled = false;
580
584
  this.run(EFFECT_RENDER);
581
585
  this.run(EFFECT_USER);
582
586
  } finally {
583
- this.I = false;
587
+ this.B = false;
584
588
  }
585
589
  }
586
590
  addChild(child) {
587
- this.y.push(child);
591
+ this.z.push(child);
588
592
  }
589
593
  removeChild(child) {
590
- const index = this.y.indexOf(child);
594
+ const index = this.z.indexOf(child);
591
595
  if (index >= 0)
592
- this.y.splice(index, 1);
596
+ this.z.splice(index, 1);
593
597
  }
594
598
  };
595
599
  var globalQueue = new Queue();
596
600
  function flushSync() {
597
- globalQueue.flush();
598
- scheduled = false;
601
+ while (scheduled) {
602
+ globalQueue.flush();
603
+ }
599
604
  }
600
605
  function createBoundary(fn, queue) {
601
606
  const owner = new Owner();
@@ -606,14 +611,14 @@ function createBoundary(fn, queue) {
606
611
  }
607
612
  function runTop(node) {
608
613
  const ancestors = [];
609
- for (let current = node; current !== null; current = current.q) {
614
+ for (let current = node; current !== null; current = current.o) {
610
615
  if (current.a !== STATE_CLEAN) {
611
616
  ancestors.push(current);
612
617
  }
613
618
  }
614
619
  for (let i = ancestors.length - 1; i >= 0; i--) {
615
620
  if (ancestors[i].a !== STATE_DISPOSED)
616
- ancestors[i].r();
621
+ ancestors[i].s();
617
622
  }
618
623
  }
619
624
  function runPureQueue(queue) {
@@ -631,21 +636,21 @@ function runEffectQueue(queue) {
631
636
  var Effect = class extends Computation {
632
637
  J;
633
638
  K = false;
634
- B;
635
639
  C;
640
+ D;
636
641
  e;
637
642
  constructor(initialValue, compute2, effect, options) {
638
643
  super(initialValue, compute2, options);
639
644
  this.J = effect;
640
- this.B = initialValue;
641
- this.C = options?.render ? EFFECT_RENDER : EFFECT_USER;
645
+ this.C = initialValue;
646
+ this.D = options?.render ? EFFECT_RENDER : EFFECT_USER;
642
647
  this.e = getOwner()?.e || globalQueue;
643
- this.r();
644
- this.C === EFFECT_USER ? this.e.enqueue(this.C, this) : this.R();
648
+ this.s();
649
+ this.D === EFFECT_USER ? this.e.enqueue(this.D, this) : this.R();
645
650
  }
646
651
  write(value, flags = 0) {
647
- const currentFlags = this.i;
648
- this.i = flags;
652
+ const currentFlags = this.j;
653
+ this.j = flags;
649
654
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
650
655
  this.e.T?.(this);
651
656
  }
@@ -655,25 +660,25 @@ var Effect = class extends Computation {
655
660
  this.K = true;
656
661
  return value;
657
662
  }
658
- s(state) {
663
+ t(state) {
659
664
  if (this.a >= state)
660
665
  return;
661
666
  if (this.a === STATE_CLEAN)
662
- this.e.enqueue(this.C, this);
667
+ this.e.enqueue(this.D, this);
663
668
  this.a = state;
664
669
  }
665
670
  Q(error) {
666
671
  this.handleError(error);
667
672
  }
668
- w() {
673
+ x() {
669
674
  this.J = void 0;
670
- this.B = void 0;
671
- super.w();
675
+ this.C = void 0;
676
+ super.x();
672
677
  }
673
678
  R() {
674
679
  if (this.K && this.a !== STATE_DISPOSED) {
675
- this.J(this.d, this.B);
676
- this.B = this.d;
680
+ this.J(this.d, this.C);
681
+ this.C = this.d;
677
682
  this.K = false;
678
683
  }
679
684
  }
@@ -683,38 +688,38 @@ var EagerComputation = class extends Computation {
683
688
  constructor(initialValue, compute2, options) {
684
689
  super(initialValue, compute2, options);
685
690
  this.e = getOwner()?.e || globalQueue;
686
- this.r();
691
+ this.s();
687
692
  }
688
- s(state) {
693
+ t(state) {
689
694
  if (this.a >= state)
690
695
  return;
691
696
  if (this.a === STATE_CLEAN)
692
697
  this.e.enqueue(EFFECT_PURE, this);
693
- super.s(state);
698
+ super.t(state);
694
699
  }
695
700
  };
696
701
 
697
702
  // src/core/suspense.ts
698
703
  var SuspenseQueue = class extends Queue {
699
- k = /* @__PURE__ */ new Set();
700
- z = false;
704
+ f = /* @__PURE__ */ new Set();
705
+ q = false;
701
706
  L = new Computation(false, null);
702
707
  run(type) {
703
- if (type && this.z)
708
+ if (type && this.q)
704
709
  return;
705
710
  super.run(type);
706
711
  }
707
712
  T(node) {
708
- if (node.i & LOADING_BIT) {
709
- this.k.add(node);
710
- if (!this.z) {
711
- this.z = true;
713
+ if (node.j & LOADING_BIT) {
714
+ this.f.add(node);
715
+ if (!this.q) {
716
+ this.q = true;
712
717
  queueMicrotask(() => this.L.write(true));
713
718
  }
714
719
  } else {
715
- this.k.delete(node);
716
- if (this.k.size === 0) {
717
- this.z = false;
720
+ this.f.delete(node);
721
+ if (this.f.size === 0) {
722
+ this.q = false;
718
723
  queueMicrotask(() => this.L.write(false));
719
724
  }
720
725
  }
@@ -723,7 +728,7 @@ var SuspenseQueue = class extends Queue {
723
728
  function createSuspense(fn, fallbackFn) {
724
729
  const queue = new SuspenseQueue();
725
730
  const tree = createBoundary(fn, queue);
726
- const equality = new Computation(null, () => queue.L.read() || queue.z);
731
+ const equality = new Computation(null, () => queue.L.read() || queue.q);
727
732
  const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
728
733
  return comp.read.bind(comp);
729
734
  }
@@ -744,14 +749,35 @@ function createSignal(first, second, third) {
744
749
  const node = new Computation(first, null, second);
745
750
  return [node.read.bind(node), node.write.bind(node)];
746
751
  }
747
- function createAsync(fn, initial, options) {
752
+ function createMemo(compute2, value, options) {
753
+ let node = new Computation(
754
+ value,
755
+ compute2,
756
+ options
757
+ );
758
+ let resolvedValue;
759
+ return () => {
760
+ if (node) {
761
+ resolvedValue = node.wait();
762
+ if (!node.b?.length) {
763
+ node.dispose();
764
+ node = void 0;
765
+ } else if (!node.o && !node.c?.length) {
766
+ node.dispose();
767
+ node.a = STATE_UNINITIALIZED;
768
+ }
769
+ }
770
+ return resolvedValue;
771
+ };
772
+ }
773
+ function createAsync(compute2, value, options) {
748
774
  const lhs = new EagerComputation(
749
775
  {
750
- d: initial
776
+ d: value
751
777
  },
752
778
  (p) => {
753
- const value = p?.d;
754
- const source = fn(value);
779
+ const value2 = p?.d;
780
+ const source = compute2(value2);
755
781
  const isPromise = source instanceof Promise;
756
782
  const iterator = source[Symbol.asyncIterator];
757
783
  if (!isPromise && !iterator) {
@@ -762,12 +788,12 @@ function createAsync(fn, initial, options) {
762
788
  d: source
763
789
  };
764
790
  }
765
- const signal = new Computation(value, null, options);
791
+ const signal = new Computation(value2, null, options);
766
792
  signal.write(UNCHANGED, LOADING_BIT);
767
793
  if (isPromise) {
768
794
  source.then(
769
- (value2) => {
770
- signal.write(value2, 0);
795
+ (value3) => {
796
+ signal.write(value3, 0);
771
797
  },
772
798
  (error) => {
773
799
  signal.write(error, ERROR_BIT);
@@ -778,10 +804,10 @@ function createAsync(fn, initial, options) {
778
804
  onCleanup(() => abort = true);
779
805
  (async () => {
780
806
  try {
781
- for await (let value2 of source) {
807
+ for await (let value3 of source) {
782
808
  if (abort)
783
809
  return;
784
- signal.write(value2, 0);
810
+ signal.write(value3, 0);
785
811
  }
786
812
  } catch (error) {
787
813
  signal.write(error, ERROR_BIT);
@@ -793,28 +819,16 @@ function createAsync(fn, initial, options) {
793
819
  );
794
820
  return () => lhs.wait().wait();
795
821
  }
796
- function createMemo(compute2, initialValue, options) {
797
- let node = new Computation(initialValue, compute2, options);
798
- let value;
799
- return () => {
800
- if (node) {
801
- value = node.wait();
802
- if (!node.b?.length)
803
- node = void 0;
804
- }
805
- return value;
806
- };
807
- }
808
- function createEffect(compute2, effect, initialValue, options) {
822
+ function createEffect(compute2, effect, value, options) {
809
823
  void new Effect(
810
- initialValue,
824
+ value,
811
825
  compute2,
812
826
  effect,
813
827
  void 0
814
828
  );
815
829
  }
816
- function createRenderEffect(compute2, effect, initialValue, options) {
817
- void new Effect(initialValue, compute2, effect, {
830
+ function createRenderEffect(compute2, effect, value, options) {
831
+ void new Effect(value, compute2, effect, {
818
832
  render: true,
819
833
  ...void 0
820
834
  });
@@ -833,7 +847,7 @@ function runWithOwner(owner, run) {
833
847
  }
834
848
  function catchError(fn, handler) {
835
849
  const owner = new Owner();
836
- owner.h = owner.h ? [handler, ...owner.h] : [handler];
850
+ owner.i = owner.i ? [handler, ...owner.i] : [handler];
837
851
  try {
838
852
  compute(owner, fn, null);
839
853
  } catch (error) {
@@ -851,15 +865,22 @@ var STORE_NODE = "n";
851
865
  var STORE_HAS = "h";
852
866
  function wrap(value) {
853
867
  let p = value[$PROXY];
854
- if (!p)
868
+ if (!p) {
869
+ let target;
870
+ if (Array.isArray(value)) {
871
+ target = [];
872
+ target.v = value;
873
+ } else
874
+ target = { v: value };
855
875
  Object.defineProperty(value, $PROXY, {
856
- value: p = new Proxy({ v: value }, proxyTraps),
876
+ value: p = new Proxy(target, proxyTraps),
857
877
  writable: true
858
878
  });
879
+ }
859
880
  return p;
860
881
  }
861
882
  function isWrappable(obj) {
862
- return obj != null && typeof obj === "object";
883
+ return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
863
884
  }
864
885
  function unwrap(item, deep = true, set) {
865
886
  let result, unwrapped, v, prop;
@@ -911,8 +932,10 @@ function getNode(nodes, property, value, equals = isEqual) {
911
932
  });
912
933
  }
913
934
  function proxyDescriptor(target, property) {
935
+ if (property === $PROXY)
936
+ return { value: target[$PROXY], writable: true, configurable: true };
914
937
  const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
915
- if (!desc || desc.get || !desc.configurable || property === $PROXY)
938
+ if (!desc || desc.get || !desc.configurable)
916
939
  return desc;
917
940
  delete desc.value;
918
941
  delete desc.writable;
@@ -978,7 +1001,10 @@ var proxyTraps = {
978
1001
  return true;
979
1002
  },
980
1003
  ownKeys,
981
- getOwnPropertyDescriptor: proxyDescriptor
1004
+ getOwnPropertyDescriptor: proxyDescriptor,
1005
+ getPrototypeOf(target) {
1006
+ return Object.getPrototypeOf(target[STORE_VALUE]);
1007
+ }
982
1008
  };
983
1009
  function setProperty(state, property, value, deleting = false) {
984
1010
  const prev = state[property];
@@ -1132,6 +1158,7 @@ function reconcile(value, key) {
1132
1158
  if (keyFn(value) !== keyFn(state))
1133
1159
  throw new Error("Cannot reconcile states with different identity");
1134
1160
  applyState(value, state, keyFn);
1161
+ return state;
1135
1162
  };
1136
1163
  }
1137
1164
 
@@ -1286,120 +1313,124 @@ function omit(props, ...keys) {
1286
1313
  // src/map.ts
1287
1314
  function mapArray(list, map, options) {
1288
1315
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1289
- return Computation.prototype.read.bind(
1290
- new Computation(
1291
- [],
1292
- updateKeyedMap.bind({
1293
- S: new Owner(),
1294
- u: 0,
1295
- U: list,
1296
- p: [],
1297
- M: map,
1298
- n: [],
1299
- k: [],
1300
- x: keyFn,
1301
- f: keyFn || options?.keyed === false ? [] : void 0,
1302
- j: map.length > 1 ? [] : void 0
1303
- }),
1304
- options
1305
- )
1306
- );
1316
+ return updateKeyedMap.bind({
1317
+ S: new Owner(),
1318
+ w: 0,
1319
+ U: list,
1320
+ r: [],
1321
+ M: map,
1322
+ k: [],
1323
+ f: [],
1324
+ y: keyFn,
1325
+ g: keyFn || options?.keyed === false ? [] : void 0,
1326
+ l: map.length > 1 ? [] : void 0,
1327
+ q: options?.fallback
1328
+ });
1307
1329
  }
1308
1330
  function updateKeyedMap() {
1309
1331
  const newItems = this.U() || [], newLen = newItems.length;
1310
1332
  newItems[$TRACK];
1311
1333
  runWithOwner(this.S, () => {
1312
- let i, j, mapper = this.f ? () => {
1313
- this.f[j] = new Computation(newItems[j], null);
1314
- this.j[j] = new Computation(j, null);
1334
+ let i, j, mapper = this.g ? () => {
1335
+ this.g[j] = new Computation(newItems[j], null);
1336
+ this.l[j] = new Computation(j, null);
1315
1337
  return this.M(
1316
- Computation.prototype.read.bind(this.f[j]),
1317
- Computation.prototype.read.bind(this.j[j])
1338
+ Computation.prototype.read.bind(this.g[j]),
1339
+ Computation.prototype.read.bind(this.l[j])
1318
1340
  );
1319
- } : this.j ? () => {
1341
+ } : this.l ? () => {
1320
1342
  const item = newItems[j];
1321
- this.j[j] = new Computation(j, null);
1322
- return this.M(() => item, Computation.prototype.read.bind(this.j[j]));
1343
+ this.l[j] = new Computation(j, null);
1344
+ return this.M(() => item, Computation.prototype.read.bind(this.l[j]));
1323
1345
  } : () => {
1324
1346
  const item = newItems[j];
1325
1347
  return this.M(() => item);
1326
1348
  };
1327
1349
  if (newLen === 0) {
1328
- if (this.u !== 0) {
1350
+ if (this.w !== 0) {
1329
1351
  this.S.dispose(false);
1352
+ this.f = [];
1353
+ this.r = [];
1330
1354
  this.k = [];
1331
- this.p = [];
1332
- this.n = [];
1333
- this.u = 0;
1334
- this.f && (this.f = []);
1335
- this.j && (this.j = []);
1355
+ this.w = 0;
1356
+ this.g && (this.g = []);
1357
+ this.l && (this.l = []);
1358
+ }
1359
+ if (this.q && !this.k[0]) {
1360
+ this.k[0] = compute(
1361
+ this.f[0] = new Owner(),
1362
+ this.q,
1363
+ null
1364
+ );
1336
1365
  }
1337
- } else if (this.u === 0) {
1338
- this.n = new Array(newLen);
1366
+ } else if (this.w === 0) {
1367
+ if (this.f[0])
1368
+ this.f[0].dispose();
1369
+ this.k = new Array(newLen);
1339
1370
  for (j = 0; j < newLen; j++) {
1340
- this.p[j] = newItems[j];
1341
- this.n[j] = compute(this.k[j] = new Owner(), mapper, null);
1371
+ this.r[j] = newItems[j];
1372
+ this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
1342
1373
  }
1343
- this.u = newLen;
1374
+ this.w = newLen;
1344
1375
  } else {
1345
- 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;
1346
- 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++) {
1347
- if (this.f)
1348
- this.f[start].write(newItems[start]);
1376
+ 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;
1377
+ for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.g && compare(this.y, this.r[start], newItems[start])); start++) {
1378
+ if (this.g)
1379
+ this.g[start].write(newItems[start]);
1349
1380
  }
1350
- 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--) {
1351
- temp[newEnd] = this.n[end];
1352
- tempNodes[newEnd] = this.k[end];
1353
- tempRows && (tempRows[newEnd] = this.f[end]);
1354
- tempIndexes && (tempIndexes[newEnd] = this.j[end]);
1381
+ for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.g && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
1382
+ temp[newEnd] = this.k[end];
1383
+ tempNodes[newEnd] = this.f[end];
1384
+ tempRows && (tempRows[newEnd] = this.g[end]);
1385
+ tempIndexes && (tempIndexes[newEnd] = this.l[end]);
1355
1386
  }
1356
1387
  newIndices = /* @__PURE__ */ new Map();
1357
1388
  newIndicesNext = new Array(newEnd + 1);
1358
1389
  for (j = newEnd; j >= start; j--) {
1359
1390
  item = newItems[j];
1360
- key = this.x ? this.x(item) : item;
1391
+ key = this.y ? this.y(item) : item;
1361
1392
  i = newIndices.get(key);
1362
1393
  newIndicesNext[j] = i === void 0 ? -1 : i;
1363
1394
  newIndices.set(key, j);
1364
1395
  }
1365
1396
  for (i = start; i <= end; i++) {
1366
- item = this.p[i];
1367
- key = this.x ? this.x(item) : item;
1397
+ item = this.r[i];
1398
+ key = this.y ? this.y(item) : item;
1368
1399
  j = newIndices.get(key);
1369
1400
  if (j !== void 0 && j !== -1) {
1370
- temp[j] = this.n[i];
1371
- tempNodes[j] = this.k[i];
1372
- tempRows && (tempRows[j] = this.f[i]);
1373
- tempIndexes && (tempIndexes[j] = this.j[i]);
1401
+ temp[j] = this.k[i];
1402
+ tempNodes[j] = this.f[i];
1403
+ tempRows && (tempRows[j] = this.g[i]);
1404
+ tempIndexes && (tempIndexes[j] = this.l[i]);
1374
1405
  j = newIndicesNext[j];
1375
1406
  newIndices.set(key, j);
1376
1407
  } else
1377
- this.k[i].dispose();
1408
+ this.f[i].dispose();
1378
1409
  }
1379
1410
  for (j = start; j < newLen; j++) {
1380
1411
  if (j in temp) {
1381
- this.n[j] = temp[j];
1382
- this.k[j] = tempNodes[j];
1412
+ this.k[j] = temp[j];
1413
+ this.f[j] = tempNodes[j];
1383
1414
  if (tempRows) {
1384
- this.f[j] = tempRows[j];
1385
- this.f[j].write(newItems[j]);
1415
+ this.g[j] = tempRows[j];
1416
+ this.g[j].write(newItems[j]);
1386
1417
  }
1387
1418
  if (tempIndexes) {
1388
- this.j[j] = tempIndexes[j];
1389
- this.j[j].write(j);
1419
+ this.l[j] = tempIndexes[j];
1420
+ this.l[j].write(j);
1390
1421
  }
1391
1422
  } else {
1392
- this.n[j] = compute(this.k[j] = new Owner(), mapper, null);
1423
+ this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
1393
1424
  }
1394
1425
  }
1395
- this.n = this.n.slice(0, this.u = newLen);
1396
- this.p = newItems.slice(0);
1426
+ this.k = this.k.slice(0, this.w = newLen);
1427
+ this.r = newItems.slice(0);
1397
1428
  }
1398
1429
  });
1399
- return this.n;
1430
+ return this.k;
1400
1431
  }
1401
1432
  function compare(key, a, b) {
1402
1433
  return key ? key(a) === key(b) : true;
1403
1434
  }
1404
1435
 
1405
- 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 };
1436
+ 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 };