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