@solidjs/signals 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/prod.js CHANGED
@@ -13,6 +13,12 @@ var ContextNotFoundError = class extends Error {
13
13
  );
14
14
  }
15
15
  };
16
+ var EffectError = class extends Error {
17
+ constructor(effect, cause) {
18
+ super("");
19
+ this.cause = cause;
20
+ }
21
+ };
16
22
 
17
23
  // src/core/constants.ts
18
24
  var STATE_CLEAN = 0;
@@ -99,82 +105,82 @@ var Owner = class {
99
105
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
100
106
  // However, the children are actually added in reverse creation order
101
107
  // See comment at the top of the file for an example of the _nextSibling traversal
102
- o = null;
103
- m = null;
104
- p = null;
108
+ r = null;
109
+ n = null;
110
+ s = null;
105
111
  a = STATE_CLEAN;
106
- j = null;
107
- n = defaultContext;
108
- k = null;
109
- e = null;
112
+ l = null;
113
+ p = defaultContext;
114
+ m = null;
115
+ g = null;
110
116
  constructor(signal = false) {
111
117
  if (currentOwner && !signal)
112
118
  currentOwner.append(this);
113
119
  }
114
120
  append(child) {
115
- child.o = this;
116
- child.p = this;
117
- if (this.m)
118
- this.m.p = child;
119
- child.m = this.m;
120
- this.m = child;
121
- if (child.n !== this.n) {
122
- child.n = { ...this.n, ...child.n };
121
+ child.r = this;
122
+ child.s = this;
123
+ if (this.n)
124
+ this.n.s = child;
125
+ child.n = this.n;
126
+ this.n = child;
127
+ if (child.p !== this.p) {
128
+ child.p = { ...this.p, ...child.p };
123
129
  }
124
- if (this.k) {
125
- child.k = !child.k ? this.k : [...child.k, ...this.k];
130
+ if (this.m) {
131
+ child.m = !child.m ? this.m : [...child.m, ...this.m];
126
132
  }
127
- if (this.e)
128
- child.e = this.e;
133
+ if (this.g)
134
+ child.g = this.g;
129
135
  }
130
136
  dispose(self = true) {
131
137
  if (this.a === STATE_DISPOSED)
132
138
  return;
133
- let head = self ? this.p || this.o : this, current = this.m, next = null;
134
- while (current && current.o === this) {
139
+ let head = self ? this.s || this.r : this, current = this.n, next = null;
140
+ while (current && current.r === this) {
135
141
  current.dispose(true);
136
- current.x();
137
- next = current.m;
138
- current.m = null;
142
+ current.y();
143
+ next = current.n;
144
+ current.n = null;
139
145
  current = next;
140
146
  }
141
147
  if (self)
142
- this.x();
148
+ this.y();
143
149
  if (current)
144
- current.p = !self ? this : this.p;
150
+ current.s = !self ? this : this.s;
145
151
  if (head)
146
- head.m = current;
147
- }
148
- x() {
149
- if (this.p)
150
- this.p.m = null;
151
- this.o = null;
152
- this.p = null;
153
- this.n = defaultContext;
154
- this.k = null;
152
+ head.n = current;
153
+ }
154
+ y() {
155
+ if (this.s)
156
+ this.s.n = null;
157
+ this.r = null;
158
+ this.s = null;
159
+ this.p = defaultContext;
160
+ this.m = null;
155
161
  this.a = STATE_DISPOSED;
156
162
  this.emptyDisposal();
157
163
  }
158
164
  emptyDisposal() {
159
- if (!this.j)
165
+ if (!this.l)
160
166
  return;
161
- if (Array.isArray(this.j)) {
162
- for (let i = 0; i < this.j.length; i++) {
163
- const callable = this.j[i];
167
+ if (Array.isArray(this.l)) {
168
+ for (let i = 0; i < this.l.length; i++) {
169
+ const callable = this.l[i];
164
170
  callable.call(callable);
165
171
  }
166
172
  } else {
167
- this.j.call(this.j);
173
+ this.l.call(this.l);
168
174
  }
169
- this.j = null;
175
+ this.l = null;
170
176
  }
171
177
  handleError(error) {
172
- if (!this.k)
178
+ if (!this.m)
173
179
  throw error;
174
- let i = 0, len = this.k.length;
180
+ let i = 0, len = this.m.length;
175
181
  for (i = 0; i < len; i++) {
176
182
  try {
177
- this.k[i](error);
183
+ this.m[i](error);
178
184
  break;
179
185
  } catch (e) {
180
186
  error = e;
@@ -191,7 +197,7 @@ function getContext(context, owner = currentOwner) {
191
197
  if (!owner) {
192
198
  throw new NoOwnerError();
193
199
  }
194
- const value = hasContext(context, owner) ? owner.n[context.id] : context.defaultValue;
200
+ const value = hasContext(context, owner) ? owner.p[context.id] : context.defaultValue;
195
201
  if (isUndefined(value)) {
196
202
  throw new ContextNotFoundError();
197
203
  }
@@ -201,24 +207,24 @@ function setContext(context, value, owner = currentOwner) {
201
207
  if (!owner) {
202
208
  throw new NoOwnerError();
203
209
  }
204
- owner.n = {
205
- ...owner.n,
210
+ owner.p = {
211
+ ...owner.p,
206
212
  [context.id]: isUndefined(value) ? context.defaultValue : value
207
213
  };
208
214
  }
209
215
  function hasContext(context, owner = currentOwner) {
210
- return !isUndefined(owner?.n[context.id]);
216
+ return !isUndefined(owner?.p[context.id]);
211
217
  }
212
218
  function onCleanup(fn) {
213
219
  if (!currentOwner)
214
220
  return fn;
215
221
  const node = currentOwner;
216
- if (!node.j) {
217
- node.j = fn;
218
- } else if (Array.isArray(node.j)) {
219
- node.j.push(fn);
222
+ if (!node.l) {
223
+ node.l = fn;
224
+ } else if (Array.isArray(node.l)) {
225
+ node.l.push(fn);
220
226
  } else {
221
- node.j = [node.j, fn];
227
+ node.l = [node.l, fn];
222
228
  }
223
229
  return fn;
224
230
  }
@@ -242,48 +248,51 @@ var updateCheck = null;
242
248
  function getObserver() {
243
249
  return currentObserver;
244
250
  }
251
+ function getClock() {
252
+ return clock;
253
+ }
245
254
  function incrementClock() {
246
255
  clock++;
247
256
  }
248
257
  var UNCHANGED = Symbol(0);
249
258
  var Computation = class extends Owner {
250
- c = null;
259
+ d = null;
251
260
  b = null;
252
- d;
253
- C;
261
+ e;
262
+ w;
254
263
  // Used in __DEV__ mode, hopefully removed in production
255
- V;
264
+ Y;
256
265
  // Using false is an optimization as an alternative to _equals: () => false
257
266
  // which could enable more efficient DIRTY notification
258
- G = isEqual;
259
- O;
267
+ L = isEqual;
268
+ S;
260
269
  /** Whether the computation is an error or has ancestors that are unresolved */
261
- f = 0;
270
+ h = 0;
262
271
  /** Which flags raised by sources are handled, vs. being passed through. */
263
- D = DEFAULT_FLAGS;
264
- z = null;
265
- H = null;
266
- I = -1;
272
+ M = DEFAULT_FLAGS;
273
+ N = null;
274
+ z = -1;
275
+ H = false;
267
276
  constructor(initialValue, compute2, options) {
268
277
  super(compute2 === null);
269
- this.C = compute2;
278
+ this.w = compute2;
270
279
  this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
271
- this.d = initialValue;
280
+ this.e = initialValue;
272
281
  if (options?.equals !== void 0)
273
- this.G = options.equals;
282
+ this.L = options.equals;
274
283
  if (options?.unobserved)
275
- this.O = options?.unobserved;
284
+ this.S = options?.unobserved;
276
285
  }
277
- P() {
278
- if (this.C)
279
- this.t();
280
- if (!this.C || this.c?.length)
286
+ T() {
287
+ if (this.w)
288
+ this.x();
289
+ if (!this.w || this.d?.length)
281
290
  track(this);
282
- newFlags |= this.f & ~currentMask;
283
- if (this.f & ERROR_BIT) {
284
- throw this.d;
291
+ newFlags |= this.h & ~currentMask;
292
+ if (this.h & ERROR_BIT) {
293
+ throw this.e;
285
294
  } else {
286
- return this.d;
295
+ return this.e;
287
296
  }
288
297
  }
289
298
  /**
@@ -291,7 +300,7 @@ var Computation = class extends Owner {
291
300
  * Automatically re-executes the surrounding computation when the value changes
292
301
  */
293
302
  read() {
294
- return this.P();
303
+ return this.T();
295
304
  }
296
305
  /**
297
306
  * Return the current value of this computation
@@ -301,10 +310,13 @@ var Computation = class extends Owner {
301
310
  * before continuing
302
311
  */
303
312
  wait() {
313
+ if (this.w && this.h & ERROR_BIT && this.z <= clock) {
314
+ update(this);
315
+ }
304
316
  if (!syncResolve && this.loading()) {
305
317
  throw new NotReadyError();
306
318
  }
307
- return this.P();
319
+ return this.T();
308
320
  }
309
321
  /**
310
322
  * Return true if the computation is the value is dependent on an unresolved promise
@@ -314,51 +326,42 @@ var Computation = class extends Owner {
314
326
  * loading state changes
315
327
  */
316
328
  loading() {
317
- if (this.H === null) {
318
- this.H = loadingState(this);
319
- }
320
- return this.H.read();
321
- }
322
- /**
323
- * Return true if the computation is the computation threw an error
324
- * Triggers re-execution of the computation when the error state changes
325
- */
326
- error() {
327
- if (this.z === null) {
328
- this.z = errorState(this);
329
+ if (this.N === null) {
330
+ this.N = loadingState(this);
329
331
  }
330
- return this.z.read();
332
+ return this.N.read();
331
333
  }
332
334
  /** Update the computation with a new value. */
333
335
  write(value, flags = 0, raw = false) {
334
- const newValue = !raw && typeof value === "function" ? value(this.d) : value;
335
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.G === false || !this.G(this.d, newValue));
336
+ const newValue = !raw && typeof value === "function" ? value(this.e) : value;
337
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.L === false || !this.L(this.e, newValue));
336
338
  if (valueChanged)
337
- this.d = newValue;
338
- const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
339
- this.f = flags;
340
- this.I = clock + 1;
339
+ this.e = newValue;
340
+ const changedFlagsMask = this.h ^ flags, changedFlags = changedFlagsMask & flags;
341
+ this.h = flags;
342
+ this.z = clock + 1;
341
343
  if (this.b) {
342
344
  for (let i = 0; i < this.b.length; i++) {
343
345
  if (valueChanged) {
344
- this.b[i].u(STATE_DIRTY);
346
+ this.b[i].q(STATE_DIRTY);
345
347
  } else if (changedFlagsMask) {
346
- this.b[i].Q(changedFlagsMask, changedFlags);
348
+ this.b[i].U(changedFlagsMask, changedFlags);
347
349
  }
348
350
  }
349
351
  }
350
- return this.d;
352
+ return this.e;
351
353
  }
352
354
  /**
353
355
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
354
356
  */
355
- u(state) {
356
- if (this.a >= state)
357
+ q(state, skipQueue) {
358
+ if (this.a >= state && !this.H)
357
359
  return;
360
+ this.H = !!skipQueue;
358
361
  this.a = state;
359
362
  if (this.b) {
360
363
  for (let i = 0; i < this.b.length; i++) {
361
- this.b[i].u(STATE_CHECK);
364
+ this.b[i].q(STATE_CHECK, skipQueue);
362
365
  }
363
366
  }
364
367
  }
@@ -368,30 +371,30 @@ var Computation = class extends Owner {
368
371
  * @param mask A bitmask for which flag(s) were changed.
369
372
  * @param newFlags The source's new flags, masked to just the changed ones.
370
373
  */
371
- Q(mask, newFlags2) {
374
+ U(mask, newFlags2) {
372
375
  if (this.a >= STATE_DIRTY)
373
376
  return;
374
- if (mask & this.D) {
375
- this.u(STATE_DIRTY);
377
+ if (mask & this.M) {
378
+ this.q(STATE_DIRTY);
376
379
  return;
377
380
  }
378
381
  if (this.a >= STATE_CHECK)
379
382
  return;
380
- const prevFlags = this.f & mask;
383
+ const prevFlags = this.h & mask;
381
384
  const deltaFlags = prevFlags ^ newFlags2;
382
385
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
383
- this.u(STATE_CHECK);
386
+ this.q(STATE_CHECK);
384
387
  } else {
385
- this.f ^= deltaFlags;
388
+ this.h ^= deltaFlags;
386
389
  if (this.b) {
387
390
  for (let i = 0; i < this.b.length; i++) {
388
- this.b[i].Q(mask, newFlags2);
391
+ this.b[i].U(mask, newFlags2);
389
392
  }
390
393
  }
391
394
  }
392
395
  }
393
- J(error) {
394
- this.write(error, this.f | ERROR_BIT);
396
+ O(error) {
397
+ this.write(error, this.h & ~LOADING_BIT | ERROR_BIT);
395
398
  }
396
399
  /**
397
400
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -400,7 +403,7 @@ var Computation = class extends Owner {
400
403
  *
401
404
  * This function will ensure that the value and states we read from the computation are up to date
402
405
  */
403
- t() {
406
+ x() {
404
407
  if (this.a === STATE_DISPOSED) {
405
408
  throw new Error("Tried to read a disposed computation");
406
409
  }
@@ -409,9 +412,9 @@ var Computation = class extends Owner {
409
412
  }
410
413
  let observerFlags = 0;
411
414
  if (this.a === STATE_CHECK) {
412
- for (let i = 0; i < this.c.length; i++) {
413
- this.c[i].t();
414
- observerFlags |= this.c[i].f;
415
+ for (let i = 0; i < this.d.length; i++) {
416
+ this.d[i].x();
417
+ observerFlags |= this.d[i].h;
415
418
  if (this.a === STATE_DIRTY) {
416
419
  break;
417
420
  }
@@ -427,49 +430,33 @@ var Computation = class extends Owner {
427
430
  /**
428
431
  * Remove ourselves from the owner graph and the computation graph
429
432
  */
430
- x() {
433
+ y() {
431
434
  if (this.a === STATE_DISPOSED)
432
435
  return;
433
- if (this.c)
436
+ if (this.d)
434
437
  removeSourceObservers(this, 0);
435
- super.x();
438
+ super.y();
436
439
  }
437
440
  };
438
441
  function loadingState(node) {
439
- const prevOwner = setOwner(node.o);
442
+ const prevOwner = setOwner(node.r);
440
443
  const options = void 0;
441
444
  const computation = new Computation(
442
445
  void 0,
443
446
  () => {
444
447
  track(node);
445
- node.t();
446
- return !!(node.f & LOADING_BIT);
448
+ node.x();
449
+ return !!(node.h & LOADING_BIT);
447
450
  },
448
451
  options
449
452
  );
450
- computation.D = ERROR_BIT | LOADING_BIT;
451
- setOwner(prevOwner);
452
- return computation;
453
- }
454
- function errorState(node) {
455
- const prevOwner = setOwner(node.o);
456
- const options = void 0;
457
- const computation = new Computation(
458
- void 0,
459
- () => {
460
- track(node);
461
- node.t();
462
- return !!(node.f & ERROR_BIT);
463
- },
464
- options
465
- );
466
- computation.D = ERROR_BIT;
453
+ computation.M = ERROR_BIT | LOADING_BIT;
467
454
  setOwner(prevOwner);
468
455
  return computation;
469
456
  }
470
457
  function track(computation) {
471
458
  if (currentObserver) {
472
- if (!newSources && currentObserver.c && currentObserver.c[newSourcesIndex] === computation) {
459
+ if (!newSources && currentObserver.d && currentObserver.d[newSourcesIndex] === computation) {
473
460
  newSourcesIndex++;
474
461
  } else if (!newSources)
475
462
  newSources = [computation];
@@ -477,7 +464,7 @@ function track(computation) {
477
464
  newSources.push(computation);
478
465
  }
479
466
  if (updateCheck) {
480
- updateCheck.d = computation.I > currentObserver.I;
467
+ updateCheck.e = computation.z > currentObserver.z;
481
468
  }
482
469
  }
483
470
  }
@@ -489,55 +476,56 @@ function update(node) {
489
476
  try {
490
477
  node.dispose(false);
491
478
  node.emptyDisposal();
492
- const result = compute(node, node.C, node);
479
+ const result = compute(node, node.w, node);
493
480
  node.write(result, newFlags, true);
494
481
  } catch (error) {
495
482
  if (error instanceof NotReadyError) {
496
483
  node.write(UNCHANGED, newFlags | LOADING_BIT);
497
484
  } else {
498
- node.J(error);
485
+ node.O(error);
499
486
  }
500
487
  } finally {
501
488
  if (newSources) {
502
- if (node.c)
489
+ if (node.d)
503
490
  removeSourceObservers(node, newSourcesIndex);
504
- if (node.c && newSourcesIndex > 0) {
505
- node.c.length = newSourcesIndex + newSources.length;
491
+ if (node.d && newSourcesIndex > 0) {
492
+ node.d.length = newSourcesIndex + newSources.length;
506
493
  for (let i = 0; i < newSources.length; i++) {
507
- node.c[newSourcesIndex + i] = newSources[i];
494
+ node.d[newSourcesIndex + i] = newSources[i];
508
495
  }
509
496
  } else {
510
- node.c = newSources;
497
+ node.d = newSources;
511
498
  }
512
499
  let source;
513
- for (let i = newSourcesIndex; i < node.c.length; i++) {
514
- source = node.c[i];
500
+ for (let i = newSourcesIndex; i < node.d.length; i++) {
501
+ source = node.d[i];
515
502
  if (!source.b)
516
503
  source.b = [node];
517
504
  else
518
505
  source.b.push(node);
519
506
  }
520
- } else if (node.c && newSourcesIndex < node.c.length) {
507
+ } else if (node.d && newSourcesIndex < node.d.length) {
521
508
  removeSourceObservers(node, newSourcesIndex);
522
- node.c.length = newSourcesIndex;
509
+ node.d.length = newSourcesIndex;
523
510
  }
524
511
  newSources = prevSources;
525
512
  newSourcesIndex = prevSourcesIndex;
526
513
  newFlags = prevFlags;
514
+ node.z = clock + 1;
527
515
  node.a = STATE_CLEAN;
528
516
  }
529
517
  }
530
518
  function removeSourceObservers(node, index) {
531
519
  let source;
532
520
  let swap;
533
- for (let i = index; i < node.c.length; i++) {
534
- source = node.c[i];
521
+ for (let i = index; i < node.d.length; i++) {
522
+ source = node.d[i];
535
523
  if (source.b) {
536
524
  swap = source.b.indexOf(node);
537
525
  source.b[swap] = source.b[source.b.length - 1];
538
526
  source.b.pop();
539
527
  if (!source.b.length)
540
- source.O?.();
528
+ source.S?.();
541
529
  }
542
530
  }
543
531
  }
@@ -551,10 +539,10 @@ function untrack(fn) {
551
539
  }
552
540
  function hasUpdated(fn) {
553
541
  const current = updateCheck;
554
- updateCheck = { d: false };
542
+ updateCheck = { e: false };
555
543
  try {
556
544
  fn();
557
- return updateCheck.d;
545
+ return updateCheck.e;
558
546
  } finally {
559
547
  updateCheck = current;
560
548
  }
@@ -567,7 +555,7 @@ function isPending(fn) {
567
555
  return e instanceof NotReadyError;
568
556
  }
569
557
  }
570
- function latest(fn) {
558
+ function resolveSync(fn) {
571
559
  const prevFlags = newFlags;
572
560
  syncResolve = true;
573
561
  try {
@@ -578,12 +566,21 @@ function latest(fn) {
578
566
  syncResolve = false;
579
567
  }
580
568
  }
569
+ function catchError(fn) {
570
+ try {
571
+ fn();
572
+ } catch (e) {
573
+ if (e instanceof NotReadyError)
574
+ throw e;
575
+ return e;
576
+ }
577
+ }
581
578
  function compute(owner, compute2, observer) {
582
579
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
583
580
  currentObserver = observer;
584
- currentMask = observer?.D ?? DEFAULT_FLAGS;
581
+ currentMask = observer?.M ?? DEFAULT_FLAGS;
585
582
  try {
586
- return compute2(observer ? observer.d : void 0);
583
+ return compute2(observer ? observer.e : void 0);
587
584
  } finally {
588
585
  setOwner(prevOwner);
589
586
  currentObserver = prevObserver;
@@ -597,93 +594,84 @@ function schedule() {
597
594
  if (scheduled)
598
595
  return;
599
596
  scheduled = true;
600
- if (!globalQueue.E)
597
+ if (!globalQueue.I)
601
598
  queueMicrotask(flushSync);
602
599
  }
603
600
  var Queue = class {
604
- E = false;
605
- q = [[], [], []];
606
- A = [];
601
+ I = false;
602
+ t = [[], [], []];
603
+ E = [];
607
604
  enqueue(type, node) {
608
- this.q[0].push(node);
605
+ this.t[0].push(node);
609
606
  if (type)
610
- this.q[type].push(node);
607
+ this.t[type].push(node);
611
608
  schedule();
612
609
  }
613
610
  run(type) {
614
- if (this.q[type].length) {
611
+ if (this.t[type].length) {
615
612
  if (type === EFFECT_PURE) {
616
- runPureQueue(this.q[type]);
617
- this.q[type] = [];
613
+ runPureQueue(this.t[type]);
614
+ this.t[type] = [];
618
615
  } else {
619
- const effects = this.q[type];
620
- this.q[type] = [];
616
+ const effects = this.t[type];
617
+ this.t[type] = [];
621
618
  runEffectQueue(effects);
622
619
  }
623
620
  }
624
621
  let rerun = false;
625
- for (let i = 0; i < this.A.length; i++) {
626
- rerun = this.A[i].run(type) || rerun;
622
+ for (let i = 0; i < this.E.length; i++) {
623
+ rerun = this.E[i].run(type) || rerun;
627
624
  }
628
- if (type === EFFECT_PURE && this.q[type].length)
625
+ if (type === EFFECT_PURE && this.t[type].length)
629
626
  return true;
630
627
  }
631
628
  flush() {
632
- if (this.E)
629
+ if (this.I)
633
630
  return;
634
- this.E = true;
631
+ this.I = true;
635
632
  try {
636
633
  while (this.run(EFFECT_PURE)) {
637
634
  }
638
- ;
639
635
  incrementClock();
640
636
  scheduled = false;
641
637
  this.run(EFFECT_RENDER);
642
638
  this.run(EFFECT_USER);
643
639
  } finally {
644
- this.E = false;
640
+ this.I = false;
645
641
  }
646
642
  }
647
643
  addChild(child) {
648
- this.A.push(child);
644
+ this.E.push(child);
649
645
  }
650
646
  removeChild(child) {
651
- const index = this.A.indexOf(child);
647
+ const index = this.E.indexOf(child);
652
648
  if (index >= 0)
653
- this.A.splice(index, 1);
649
+ this.E.splice(index, 1);
654
650
  }
655
651
  };
656
652
  var globalQueue = new Queue();
657
- var globalTasks = [];
658
653
  function flushSync() {
659
654
  while (scheduled) {
660
655
  globalQueue.flush();
661
- for (let i = 0; i < globalTasks.length; i++)
662
- globalTasks[i]();
663
- globalTasks.length = 0;
664
656
  }
665
657
  }
666
- function queueTask(fn) {
667
- globalTasks.push(fn);
668
- schedule();
669
- }
670
658
  function createBoundary(fn, queue) {
671
659
  const owner = new Owner();
672
- const parentQueue = owner.e || globalQueue;
673
- parentQueue.addChild(owner.e = queue);
674
- onCleanup(() => parentQueue.removeChild(owner.e));
660
+ const parentQueue = owner.g || globalQueue;
661
+ parentQueue.addChild(owner.g = queue);
662
+ onCleanup(() => parentQueue.removeChild(owner.g));
675
663
  return compute(owner, fn, null);
676
664
  }
677
665
  function runTop(node) {
678
666
  const ancestors = [];
679
- for (let current = node; current !== null; current = current.o) {
667
+ for (let current = node; current !== null; current = current.r) {
680
668
  if (current.a !== STATE_CLEAN) {
681
669
  ancestors.push(current);
682
670
  }
683
671
  }
684
672
  for (let i = ancestors.length - 1; i >= 0; i--) {
685
673
  if (ancestors[i].a !== STATE_DISPOSED)
686
- ancestors[i].t();
674
+ ancestors[i].x();
687
675
  }
688
676
  }
689
677
  function runPureQueue(queue) {
@@ -694,110 +682,138 @@ function runPureQueue(queue) {
694
682
  }
695
683
  function runEffectQueue(queue) {
696
684
  for (let i = 0; i < queue.length; i++)
697
- queue[i].R();
685
+ queue[i].V();
698
686
  }
699
687
 
700
688
  // src/core/effect.ts
701
689
  var Effect = class extends Computation {
702
- K;
703
- L = false;
704
- F;
690
+ J;
691
+ A;
705
692
  B;
706
- e;
707
- constructor(initialValue, compute2, effect, options) {
693
+ P = false;
694
+ K;
695
+ C;
696
+ g;
697
+ constructor(initialValue, compute2, effect, error, options) {
708
698
  super(initialValue, compute2, options);
709
- this.K = effect;
710
- this.F = initialValue;
711
- this.B = options?.render ? EFFECT_RENDER : EFFECT_USER;
712
- this.e = getOwner()?.e || globalQueue;
713
- this.t();
714
- this.B === EFFECT_USER ? this.e.enqueue(this.B, this) : this.R();
699
+ this.J = effect;
700
+ this.A = error;
701
+ this.K = initialValue;
702
+ this.C = options?.render ? EFFECT_RENDER : EFFECT_USER;
703
+ this.g = getOwner()?.g || globalQueue;
704
+ if (!options?.defer) {
705
+ this.x();
706
+ this.C === EFFECT_USER ? this.g.enqueue(this.C, this) : this.V();
707
+ }
715
708
  }
716
709
  write(value, flags = 0) {
717
- const currentFlags = this.f;
718
- this.f = flags;
719
- if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
720
- this.e.S?.(this);
710
+ const currentFlags = this.h;
711
+ this.h = flags;
712
+ if (this.C === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
713
+ this.g.Q?.(this);
721
714
  }
722
715
  if (value === UNCHANGED)
723
- return this.d;
724
- this.d = value;
725
- this.L = true;
716
+ return this.e;
717
+ this.e = value;
718
+ this.P = true;
726
719
  return value;
727
720
  }
728
- u(state) {
729
- if (this.a >= state)
721
+ q(state, skipQueue) {
722
+ if (this.a >= state || skipQueue)
730
723
  return;
731
724
  if (this.a === STATE_CLEAN)
732
- this.e.enqueue(this.B, this);
725
+ this.g.enqueue(this.C, this);
733
726
  this.a = state;
734
727
  }
735
- J(error) {
728
+ O(error) {
729
+ this.B?.();
730
+ if (this.h & LOADING_BIT) {
731
+ this.h = 0;
732
+ this.g.Q?.(this);
733
+ }
734
+ if (this.C === EFFECT_USER) {
735
+ try {
736
+ return this.A ? this.B = this.A(error) : console.error(new EffectError(this.J, error));
737
+ } catch (e) {
738
+ error = e;
739
+ }
740
+ }
736
741
  this.handleError(error);
737
742
  }
738
- x() {
743
+ y() {
744
+ if (this.a === STATE_DISPOSED)
745
+ return;
746
+ this.J = void 0;
739
747
  this.K = void 0;
740
- this.F = void 0;
741
- super.x();
742
- }
743
- R() {
744
- if (this.L && this.a !== STATE_DISPOSED) {
745
- this.K(this.d, this.F);
746
- this.F = this.d;
747
- this.L = false;
748
+ this.A = void 0;
749
+ this.B?.();
750
+ this.B = void 0;
751
+ super.y();
752
+ }
753
+ V() {
754
+ if (this.P && this.a !== STATE_DISPOSED) {
755
+ this.B?.();
756
+ try {
757
+ this.B = this.J(this.e, this.K);
758
+ } catch (e) {
759
+ this.handleError(e);
760
+ } finally {
761
+ this.K = this.e;
762
+ this.P = false;
763
+ }
748
764
  }
749
765
  }
750
766
  };
751
767
  var EagerComputation = class extends Computation {
752
- e;
768
+ g;
753
769
  constructor(initialValue, compute2, options) {
754
770
  super(initialValue, compute2, options);
755
- this.e = getOwner()?.e || globalQueue;
756
- this.t();
771
+ this.g = getOwner()?.g || globalQueue;
772
+ this.x();
757
773
  }
758
- u(state) {
759
- if (this.a >= state)
774
+ q(state, skipQueue) {
775
+ if (this.a >= state && !this.H)
760
776
  return;
761
- if (this.a === STATE_CLEAN)
762
- this.e.enqueue(EFFECT_PURE, this);
763
- super.u(state);
777
+ if (this.a === STATE_CLEAN && !skipQueue)
778
+ this.g.enqueue(EFFECT_PURE, this);
779
+ super.q(state, skipQueue);
764
780
  }
765
781
  };
766
782
 
767
783
  // src/core/suspense.ts
768
784
  var SuspenseQueue = class extends Queue {
769
- g = /* @__PURE__ */ new Set();
770
- r = false;
771
- M = new Computation(false, null);
785
+ c = /* @__PURE__ */ new Set();
786
+ o = false;
787
+ R = new Computation(false, null);
772
788
  run(type) {
773
- if (type && this.r)
789
+ if (type && this.o)
774
790
  return;
775
791
  return super.run(type);
776
792
  }
777
- S(node) {
778
- if (node.f & LOADING_BIT) {
779
- this.g.add(node);
780
- if (!this.r) {
781
- this.r = true;
782
- queueTask(() => this.M.write(true));
793
+ Q(node) {
794
+ if (node.h & LOADING_BIT) {
795
+ this.c.add(node);
796
+ if (!this.o) {
797
+ this.o = true;
798
+ this.R.write(true);
783
799
  }
784
800
  } else {
785
- this.g.delete(node);
786
- if (this.g.size === 0) {
787
- this.r = false;
788
- queueTask(() => this.M.write(false));
801
+ this.c.delete(node);
802
+ if (this.c.size === 0) {
803
+ this.o = false;
804
+ this.R.write(false);
789
805
  }
790
806
  }
791
807
  }
792
808
  };
793
809
  var LiveComputation = class extends EagerComputation {
794
810
  write(value, flags = 0) {
795
- const currentFlags = this.f;
811
+ const currentFlags = this.h;
796
812
  super.write(value, flags);
797
813
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
798
- this.e.S?.(this);
814
+ this.g.Q?.(this);
799
815
  }
800
- return this.d;
816
+ return this.e;
801
817
  }
802
818
  };
803
819
  function createSuspense(fn, fallback) {
@@ -806,7 +822,7 @@ function createSuspense(fn, fallback) {
806
822
  const child = new Computation(null, fn);
807
823
  return new LiveComputation(null, () => flatten(child.wait()));
808
824
  }, queue);
809
- const equality = new Computation(null, () => queue.M.read() || queue.r);
825
+ const equality = new Computation(null, () => queue.R.read() || queue.o);
810
826
  const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
811
827
  return comp.read.bind(comp);
812
828
  }
@@ -837,10 +853,10 @@ function createMemo(compute2, value, options) {
837
853
  return () => {
838
854
  if (node) {
839
855
  resolvedValue = node.wait();
840
- if (!node.c?.length && node.m?.o !== node) {
856
+ if (!node.d?.length && node.n?.r !== node) {
841
857
  node.dispose();
842
858
  node = void 0;
843
- } else if (!node.o && !node.b?.length) {
859
+ } else if (!node.r && !node.b?.length) {
844
860
  node.dispose();
845
861
  node.a = STATE_UNINITIALIZED;
846
862
  }
@@ -851,10 +867,10 @@ function createMemo(compute2, value, options) {
851
867
  function createAsync(compute2, value, options) {
852
868
  const lhs = new EagerComputation(
853
869
  {
854
- d: value
870
+ e: value
855
871
  },
856
872
  (p) => {
857
- const value2 = p?.d;
873
+ const value2 = p?.e;
858
874
  const source = compute2(value2);
859
875
  const isPromise = source instanceof Promise;
860
876
  const iterator = source[Symbol.asyncIterator];
@@ -863,10 +879,18 @@ function createAsync(compute2, value, options) {
863
879
  wait() {
864
880
  return source;
865
881
  },
866
- d: source
882
+ e: source
867
883
  };
868
884
  }
869
885
  const signal = new Computation(value2, null, options);
886
+ const w = signal.wait;
887
+ signal.wait = function() {
888
+ if (signal.h & ERROR_BIT && signal.z <= getClock()) {
889
+ lhs.q(STATE_DIRTY);
890
+ throw new NotReadyError();
891
+ }
892
+ return w.call(this);
893
+ };
870
894
  signal.write(UNCHANGED, LOADING_BIT);
871
895
  if (isPromise) {
872
896
  source.then(
@@ -897,16 +921,17 @@ function createAsync(compute2, value, options) {
897
921
  );
898
922
  return () => lhs.wait().wait();
899
923
  }
900
- function createEffect(compute2, effect, value, options) {
924
+ function createEffect(compute2, effect, error, value, options) {
901
925
  void new Effect(
902
926
  value,
903
927
  compute2,
904
928
  effect,
929
+ error,
905
930
  void 0
906
931
  );
907
932
  }
908
933
  function createRenderEffect(compute2, effect, value, options) {
909
- void new Effect(value, compute2, effect, {
934
+ void new Effect(value, compute2, effect, void 0, {
910
935
  render: true,
911
936
  ...void 0
912
937
  });
@@ -927,14 +952,14 @@ function createErrorBoundary(fn, fallback) {
927
952
  const owner = new Owner();
928
953
  const error = new Computation(null, null);
929
954
  const reset = new Computation(null, null, { equals: false });
930
- const handler = (err) => error.write({ z: err });
931
- owner.k = owner.k ? [handler, ...owner.k] : [handler];
955
+ const handler = (err) => error.write({ A: err });
956
+ owner.m = owner.m ? [handler, ...owner.m] : [handler];
932
957
  const guarded = compute(
933
958
  owner,
934
959
  () => {
935
960
  const c = new Computation(null, () => (reset.read(), fn()));
936
961
  const f = new Computation(null, () => flatten(c.read()));
937
- f.J = function(error2) {
962
+ f.O = function(error2) {
938
963
  this.handleError(error2);
939
964
  };
940
965
  return f;
@@ -947,13 +972,78 @@ function createErrorBoundary(fn, fallback) {
947
972
  if (!error.read())
948
973
  return resolved;
949
974
  }
950
- return fallback(error.read().z, () => {
975
+ return fallback(error.read().A, () => {
951
976
  error.write(null);
952
977
  reset.write(null);
953
978
  });
954
979
  });
955
980
  return decision.read.bind(decision);
956
981
  }
982
+ function resolve(fn) {
983
+ return new Promise((res, rej) => {
984
+ let node = new EagerComputation(void 0, () => {
985
+ try {
986
+ res(fn());
987
+ } catch (err) {
988
+ if (err instanceof NotReadyError)
989
+ throw err;
990
+ rej(err);
991
+ }
992
+ node.dispose(true);
993
+ });
994
+ });
995
+ }
996
+ function createReaction(effect, error, options) {
997
+ const node = new Effect(void 0, () => {
998
+ }, effect, error, {
999
+ defer: true,
1000
+ ...void 0
1001
+ });
1002
+ return (tracking) => {
1003
+ node.w = tracking;
1004
+ node.a = STATE_DIRTY;
1005
+ node.x();
1006
+ node.w = null;
1007
+ };
1008
+ }
1009
+
1010
+ // src/store/projection.ts
1011
+ var ProjectionComputation = class extends EagerComputation {
1012
+ q(state, skipQueue) {
1013
+ if (this.a >= state && !this.H)
1014
+ return;
1015
+ if (this.a === STATE_CLEAN && !skipQueue)
1016
+ this.g.enqueue(EFFECT_PURE, this);
1017
+ super.q(state, true);
1018
+ }
1019
+ };
1020
+ function createProjection(fn, initialValue = {}) {
1021
+ const [store, setStore] = createStore(initialValue);
1022
+ const node = new ProjectionComputation(void 0, () => {
1023
+ setStore(fn);
1024
+ });
1025
+ const wrapped = /* @__PURE__ */ new WeakMap();
1026
+ return wrap(store, node, wrapped);
1027
+ }
1028
+ function wrap(source, node, wrapped) {
1029
+ if (wrapped.has(source))
1030
+ return wrapped.get(source);
1031
+ const wrap3 = new Proxy(source, {
1032
+ get(target, property) {
1033
+ node.read();
1034
+ const v = target[property];
1035
+ return isWrappable(v) ? wrap3(v, node, wrapped) : v;
1036
+ },
1037
+ set() {
1038
+ throw new Error("Projections are readonly");
1039
+ },
1040
+ deleteProperty() {
1041
+ throw new Error("Projections are readonly");
1042
+ }
1043
+ });
1044
+ wrapped.set(source, wrap3);
1045
+ return wrap3;
1046
+ }
957
1047
 
958
1048
  // src/store/store.ts
959
1049
  var $RAW = Symbol(0);
@@ -963,7 +1053,7 @@ var $PROXY = Symbol(0);
963
1053
  var STORE_VALUE = "v";
964
1054
  var STORE_NODE = "n";
965
1055
  var STORE_HAS = "h";
966
- function wrap(value) {
1056
+ function wrap2(value) {
967
1057
  let p = value[$PROXY];
968
1058
  if (!p) {
969
1059
  let target;
@@ -1071,8 +1161,8 @@ var proxyTraps = {
1071
1161
  return desc.get.call(receiver);
1072
1162
  }
1073
1163
  if (Writing.has(storeValue)) {
1074
- const value2 = tracked ? tracked.d : storeValue[property];
1075
- return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap(value2)) : value2;
1164
+ const value2 = tracked ? tracked.e : storeValue[property];
1165
+ return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
1076
1166
  }
1077
1167
  let value = tracked ? nodes[property].read() : storeValue[property];
1078
1168
  if (!tracked) {
@@ -1080,10 +1170,10 @@ var proxyTraps = {
1080
1170
  let proto;
1081
1171
  return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
1082
1172
  } else if (getObserver()) {
1083
- value = getNode(nodes, property, isWrappable(value) ? wrap(value) : value).read();
1173
+ value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
1084
1174
  }
1085
1175
  }
1086
- return isWrappable(value) ? wrap(value) : value;
1176
+ return isWrappable(value) ? wrap2(value) : value;
1087
1177
  },
1088
1178
  has(target, property) {
1089
1179
  if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
@@ -1125,13 +1215,16 @@ function setProperty(state, property, value, deleting = false) {
1125
1215
  const nodes = getNodes(target, STORE_NODE);
1126
1216
  let node;
1127
1217
  if (node = nodes[property])
1128
- node.write(isWrappable(value) ? wrap(value) : value);
1218
+ node.write(isWrappable(value) ? wrap2(value) : value);
1129
1219
  Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
1130
1220
  (node = nodes[$TRACK]) && node.write(void 0);
1131
1221
  }
1132
1222
  function createStore(first, second) {
1133
- const derived = typeof first === "function", store = derived ? second : first, unwrappedStore = unwrap(store, false);
1134
- const wrappedStore = wrap(unwrappedStore);
1223
+ const derived = typeof first === "function", store = derived ? second : first;
1224
+ if (derived)
1225
+ return createProjection(first, store);
1226
+ const unwrappedStore = unwrap(store, false);
1227
+ const wrappedStore = wrap2(unwrappedStore);
1135
1228
  const setStore = (fn) => {
1136
1229
  try {
1137
1230
  Writing.add(unwrappedStore);
@@ -1140,15 +1233,8 @@ function createStore(first, second) {
1140
1233
  Writing.clear();
1141
1234
  }
1142
1235
  };
1143
- if (derived) {
1144
- new EagerComputation(void 0, () => setStore(first));
1145
- }
1146
1236
  return [wrappedStore, setStore];
1147
1237
  }
1148
- function createProjection(fn, initialValue = {}) {
1149
- const [store] = createStore(fn, initialValue);
1150
- return store;
1151
- }
1152
1238
 
1153
1239
  // src/store/reconcile.ts
1154
1240
  function applyState(next, state, keyFn) {
@@ -1169,7 +1255,7 @@ function applyState(next, state, keyFn) {
1169
1255
  if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
1170
1256
  let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1171
1257
  for (start = 0, end = Math.min(previous.length, next.length); start < end && (previous[start] === next[start] || previous[start] && next[start] && keyFn(previous[start]) === keyFn(next[start])); start++) {
1172
- applyState(next[start], wrap(previous[start]), keyFn);
1258
+ applyState(next[start], wrap2(previous[start]), keyFn);
1173
1259
  }
1174
1260
  const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1175
1261
  for (end = previous.length - 1, newEnd = next.length - 1; end >= start && newEnd >= start && (previous[end] === next[newEnd] || previous[end] && next[newEnd] && keyFn(previous[end]) === keyFn(next[newEnd])); end--, newEnd--) {
@@ -1178,11 +1264,11 @@ function applyState(next, state, keyFn) {
1178
1264
  if (start > newEnd || start > end) {
1179
1265
  for (j = start; j <= newEnd; j++) {
1180
1266
  changed = true;
1181
- target[STORE_NODE][j]?.write(wrap(next[j]));
1267
+ target[STORE_NODE][j]?.write(wrap2(next[j]));
1182
1268
  }
1183
1269
  for (; j < next.length; j++) {
1184
1270
  changed = true;
1185
- const wrapped = wrap(temp[j]);
1271
+ const wrapped = wrap2(temp[j]);
1186
1272
  target[STORE_NODE][j]?.write(wrapped);
1187
1273
  applyState(next[j], wrapped, keyFn);
1188
1274
  }
@@ -1210,17 +1296,17 @@ function applyState(next, state, keyFn) {
1210
1296
  }
1211
1297
  for (j = start; j < next.length; j++) {
1212
1298
  if (j in temp) {
1213
- const wrapped = wrap(temp[j]);
1299
+ const wrapped = wrap2(temp[j]);
1214
1300
  target[STORE_NODE][j]?.write(wrapped);
1215
1301
  applyState(next[j], wrapped, keyFn);
1216
1302
  } else
1217
- target[STORE_NODE][j]?.write(wrap(next[j]));
1303
+ target[STORE_NODE][j]?.write(wrap2(next[j]));
1218
1304
  }
1219
1305
  if (start < next.length)
1220
1306
  changed = true;
1221
1307
  } else if (previous.length && next.length) {
1222
1308
  for (let i = 0, len = next.length; i < len; i++) {
1223
- isWrappable(previous[i]) && applyState(next[i], wrap(previous[i]), keyFn);
1309
+ isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
1224
1310
  }
1225
1311
  }
1226
1312
  if (previous.length !== next.length) {
@@ -1240,9 +1326,9 @@ function applyState(next, state, keyFn) {
1240
1326
  if (previousValue === nextValue)
1241
1327
  continue;
1242
1328
  if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
1243
- node.write(isWrappable(nextValue) ? wrap(nextValue) : nextValue);
1329
+ node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
1244
1330
  else
1245
- applyState(nextValue, wrap(previousValue), keyFn);
1331
+ applyState(nextValue, wrap2(previousValue), keyFn);
1246
1332
  }
1247
1333
  }
1248
1334
  if (nodes = target[STORE_HAS]) {
@@ -1414,123 +1500,169 @@ function omit(props, ...keys) {
1414
1500
  function mapArray(list, map, options) {
1415
1501
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1416
1502
  return updateKeyedMap.bind({
1417
- T: new Owner(),
1418
- w: 0,
1419
- U: list,
1420
- s: [],
1421
- N: map,
1422
- l: [],
1423
- g: [],
1424
- y: keyFn,
1425
- h: keyFn || options?.keyed === false ? [] : void 0,
1426
- i: map.length > 1 ? [] : void 0,
1427
- r: options?.fallback
1503
+ F: new Owner(),
1504
+ i: 0,
1505
+ W: list,
1506
+ u: [],
1507
+ G: map,
1508
+ f: [],
1509
+ c: [],
1510
+ D: keyFn,
1511
+ j: keyFn || options?.keyed === false ? [] : void 0,
1512
+ k: map.length > 1 ? [] : void 0,
1513
+ o: options?.fallback
1428
1514
  });
1429
1515
  }
1430
1516
  function updateKeyedMap() {
1431
- const newItems = this.U() || [], newLen = newItems.length;
1517
+ const newItems = this.W() || [], newLen = newItems.length;
1432
1518
  newItems[$TRACK];
1433
- runWithOwner(this.T, () => {
1434
- let i, j, mapper = this.h ? () => {
1435
- this.h[j] = new Computation(newItems[j], null);
1436
- this.i && (this.i[j] = new Computation(j, null));
1437
- return this.N(
1438
- Computation.prototype.read.bind(this.h[j]),
1439
- this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
1519
+ runWithOwner(this.F, () => {
1520
+ let i, j, mapper = this.j ? () => {
1521
+ this.j[j] = new Computation(newItems[j], null);
1522
+ this.k && (this.k[j] = new Computation(j, null));
1523
+ return this.G(
1524
+ Computation.prototype.read.bind(this.j[j]),
1525
+ this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
1440
1526
  );
1441
- } : this.i ? () => {
1527
+ } : this.k ? () => {
1442
1528
  const item = newItems[j];
1443
- this.i[j] = new Computation(j, null);
1444
- return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
1529
+ this.k[j] = new Computation(j, null);
1530
+ return this.G(() => item, Computation.prototype.read.bind(this.k[j]));
1445
1531
  } : () => {
1446
1532
  const item = newItems[j];
1447
- return this.N(() => item);
1533
+ return this.G(() => item);
1448
1534
  };
1449
1535
  if (newLen === 0) {
1450
- if (this.w !== 0) {
1451
- this.T.dispose(false);
1452
- this.g = [];
1453
- this.s = [];
1454
- this.l = [];
1455
- this.w = 0;
1456
- this.h && (this.h = []);
1457
- this.i && (this.i = []);
1536
+ if (this.i !== 0) {
1537
+ this.F.dispose(false);
1538
+ this.c = [];
1539
+ this.u = [];
1540
+ this.f = [];
1541
+ this.i = 0;
1542
+ this.j && (this.j = []);
1543
+ this.k && (this.k = []);
1458
1544
  }
1459
- if (this.r && !this.l[0]) {
1460
- this.l[0] = compute(
1461
- this.g[0] = new Owner(),
1462
- this.r,
1545
+ if (this.o && !this.f[0]) {
1546
+ this.f[0] = compute(
1547
+ this.c[0] = new Owner(),
1548
+ this.o,
1463
1549
  null
1464
1550
  );
1465
1551
  }
1466
- } else if (this.w === 0) {
1467
- if (this.g[0])
1468
- this.g[0].dispose();
1469
- this.l = new Array(newLen);
1552
+ } else if (this.i === 0) {
1553
+ if (this.c[0])
1554
+ this.c[0].dispose();
1555
+ this.f = new Array(newLen);
1470
1556
  for (j = 0; j < newLen; j++) {
1471
- this.s[j] = newItems[j];
1472
- this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
1557
+ this.u[j] = newItems[j];
1558
+ this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
1473
1559
  }
1474
- this.w = newLen;
1560
+ this.i = newLen;
1475
1561
  } else {
1476
- let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.h ? new Array(newLen) : void 0, tempIndexes = this.i ? new Array(newLen) : void 0;
1477
- for (start = 0, end = Math.min(this.w, newLen); start < end && (this.s[start] === newItems[start] || this.h && compare(this.y, this.s[start], newItems[start])); start++) {
1478
- if (this.h)
1479
- this.h[start].write(newItems[start]);
1562
+ let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
1563
+ for (start = 0, end = Math.min(this.i, newLen); start < end && (this.u[start] === newItems[start] || this.j && compare(this.D, this.u[start], newItems[start])); start++) {
1564
+ if (this.j)
1565
+ this.j[start].write(newItems[start]);
1480
1566
  }
1481
- for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.s[end] === newItems[newEnd] || this.h && compare(this.y, this.s[end], newItems[newEnd])); end--, newEnd--) {
1482
- temp[newEnd] = this.l[end];
1483
- tempNodes[newEnd] = this.g[end];
1484
- tempRows && (tempRows[newEnd] = this.h[end]);
1485
- tempIndexes && (tempIndexes[newEnd] = this.i[end]);
1567
+ for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.u[end] === newItems[newEnd] || this.j && compare(this.D, this.u[end], newItems[newEnd])); end--, newEnd--) {
1568
+ temp[newEnd] = this.f[end];
1569
+ tempNodes[newEnd] = this.c[end];
1570
+ tempRows && (tempRows[newEnd] = this.j[end]);
1571
+ tempIndexes && (tempIndexes[newEnd] = this.k[end]);
1486
1572
  }
1487
1573
  newIndices = /* @__PURE__ */ new Map();
1488
1574
  newIndicesNext = new Array(newEnd + 1);
1489
1575
  for (j = newEnd; j >= start; j--) {
1490
1576
  item = newItems[j];
1491
- key = this.y ? this.y(item) : item;
1577
+ key = this.D ? this.D(item) : item;
1492
1578
  i = newIndices.get(key);
1493
1579
  newIndicesNext[j] = i === void 0 ? -1 : i;
1494
1580
  newIndices.set(key, j);
1495
1581
  }
1496
1582
  for (i = start; i <= end; i++) {
1497
- item = this.s[i];
1498
- key = this.y ? this.y(item) : item;
1583
+ item = this.u[i];
1584
+ key = this.D ? this.D(item) : item;
1499
1585
  j = newIndices.get(key);
1500
1586
  if (j !== void 0 && j !== -1) {
1501
- temp[j] = this.l[i];
1502
- tempNodes[j] = this.g[i];
1503
- tempRows && (tempRows[j] = this.h[i]);
1504
- tempIndexes && (tempIndexes[j] = this.i[i]);
1587
+ temp[j] = this.f[i];
1588
+ tempNodes[j] = this.c[i];
1589
+ tempRows && (tempRows[j] = this.j[i]);
1590
+ tempIndexes && (tempIndexes[j] = this.k[i]);
1505
1591
  j = newIndicesNext[j];
1506
1592
  newIndices.set(key, j);
1507
1593
  } else
1508
- this.g[i].dispose();
1594
+ this.c[i].dispose();
1509
1595
  }
1510
1596
  for (j = start; j < newLen; j++) {
1511
1597
  if (j in temp) {
1512
- this.l[j] = temp[j];
1513
- this.g[j] = tempNodes[j];
1598
+ this.f[j] = temp[j];
1599
+ this.c[j] = tempNodes[j];
1514
1600
  if (tempRows) {
1515
- this.h[j] = tempRows[j];
1516
- this.h[j].write(newItems[j]);
1601
+ this.j[j] = tempRows[j];
1602
+ this.j[j].write(newItems[j]);
1517
1603
  }
1518
1604
  if (tempIndexes) {
1519
- this.i[j] = tempIndexes[j];
1520
- this.i[j].write(j);
1605
+ this.k[j] = tempIndexes[j];
1606
+ this.k[j].write(j);
1521
1607
  }
1522
1608
  } else {
1523
- this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
1609
+ this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
1524
1610
  }
1525
1611
  }
1526
- this.l = this.l.slice(0, this.w = newLen);
1527
- this.s = newItems.slice(0);
1612
+ this.f = this.f.slice(0, this.i = newLen);
1613
+ this.u = newItems.slice(0);
1614
+ }
1615
+ });
1616
+ return this.f;
1617
+ }
1618
+ function repeat(count, map, options) {
1619
+ return updateRepeat.bind({
1620
+ F: new Owner(),
1621
+ i: 0,
1622
+ X: count,
1623
+ G: map,
1624
+ c: [],
1625
+ f: [],
1626
+ o: options?.fallback
1627
+ });
1628
+ }
1629
+ function updateRepeat() {
1630
+ const newLen = this.X();
1631
+ runWithOwner(this.F, () => {
1632
+ if (newLen === 0) {
1633
+ if (this.i !== 0) {
1634
+ this.F.dispose(false);
1635
+ this.c = [];
1636
+ this.f = [];
1637
+ this.i = 0;
1638
+ }
1639
+ if (this.o && !this.f[0]) {
1640
+ this.f[0] = compute(
1641
+ this.c[0] = new Owner(),
1642
+ this.o,
1643
+ null
1644
+ );
1645
+ }
1646
+ } else {
1647
+ if (this.i === 0 && this.c[0])
1648
+ this.c[0].dispose();
1649
+ for (let i = this.i; i < newLen; i++) {
1650
+ this.f[i] = compute(
1651
+ this.c[i] = new Owner(),
1652
+ () => this.G(i),
1653
+ null
1654
+ );
1655
+ }
1656
+ for (let i = newLen; i < this.i; i++)
1657
+ this.c[i].dispose();
1658
+ this.f = this.f.slice(0, newLen);
1659
+ this.i = newLen;
1528
1660
  }
1529
1661
  });
1530
- return this.l;
1662
+ return this.f;
1531
1663
  }
1532
1664
  function compare(key, a, b) {
1533
1665
  return key ? key(a) === key(b) : true;
1534
1666
  }
1535
1667
 
1536
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
1668
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, resolveSync, runWithOwner, setContext, untrack, unwrap };