@solidjs/signals 0.0.6 → 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.s();
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].t(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
- t(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].t(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.t(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.t(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
- s() {
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].s();
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);
440
- const options = void 0;
441
- const computation = new Computation(
442
- void 0,
443
- () => {
444
- track(node);
445
- node.s();
446
- return !!(node.f & LOADING_BIT);
447
- },
448
- options
449
- );
450
- computation.D = ERROR_BIT | LOADING_BIT;
451
- setOwner(prevOwner);
452
- return computation;
453
- }
454
- function errorState(node) {
455
- const prevOwner = setOwner(node.o);
442
+ const prevOwner = setOwner(node.r);
456
443
  const options = void 0;
457
444
  const computation = new Computation(
458
445
  void 0,
459
446
  () => {
460
447
  track(node);
461
- node.s();
462
- return !!(node.f & ERROR_BIT);
448
+ node.x();
449
+ return !!(node.h & LOADING_BIT);
463
450
  },
464
451
  options
465
452
  );
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,88 +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
- u = [[], [], []];
606
- A = [];
601
+ I = false;
602
+ t = [[], [], []];
603
+ E = [];
607
604
  enqueue(type, node) {
608
- this.u[0].push(node);
605
+ this.t[0].push(node);
609
606
  if (type)
610
- this.u[type].push(node);
607
+ this.t[type].push(node);
611
608
  schedule();
612
609
  }
613
610
  run(type) {
614
- if (this.u[type].length) {
611
+ if (this.t[type].length) {
615
612
  if (type === EFFECT_PURE) {
616
- runPureQueue(this.u[type]);
617
- this.u[type] = [];
613
+ runPureQueue(this.t[type]);
614
+ this.t[type] = [];
618
615
  } else {
619
- const effects = this.u[type];
620
- this.u[type] = [];
616
+ const effects = this.t[type];
617
+ this.t[type] = [];
621
618
  runEffectQueue(effects);
622
619
  }
623
620
  }
624
- for (let i = 0; i < this.A.length; i++) {
625
- this.A[i].run(type);
621
+ let rerun = false;
622
+ for (let i = 0; i < this.E.length; i++) {
623
+ rerun = this.E[i].run(type) || rerun;
626
624
  }
625
+ if (type === EFFECT_PURE && this.t[type].length)
626
+ return true;
627
627
  }
628
628
  flush() {
629
- if (this.E)
629
+ if (this.I)
630
630
  return;
631
- this.E = true;
631
+ this.I = true;
632
632
  try {
633
- this.run(EFFECT_PURE);
633
+ while (this.run(EFFECT_PURE)) {
634
+ }
634
635
  incrementClock();
635
636
  scheduled = false;
636
637
  this.run(EFFECT_RENDER);
637
638
  this.run(EFFECT_USER);
638
639
  } finally {
639
- this.E = false;
640
+ this.I = false;
640
641
  }
641
642
  }
642
643
  addChild(child) {
643
- this.A.push(child);
644
+ this.E.push(child);
644
645
  }
645
646
  removeChild(child) {
646
- const index = this.A.indexOf(child);
647
+ const index = this.E.indexOf(child);
647
648
  if (index >= 0)
648
- this.A.splice(index, 1);
649
+ this.E.splice(index, 1);
649
650
  }
650
651
  };
651
652
  var globalQueue = new Queue();
652
- var globalTasks = [];
653
653
  function flushSync() {
654
654
  while (scheduled) {
655
655
  globalQueue.flush();
656
- for (let i = 0; i < globalTasks.length; i++)
657
- globalTasks[i]();
658
- globalTasks.length = 0;
659
656
  }
660
657
  }
661
- function queueTask(fn) {
662
- globalTasks.push(fn);
663
- schedule();
664
- }
665
658
  function createBoundary(fn, queue) {
666
659
  const owner = new Owner();
667
- const parentQueue = owner.e || globalQueue;
668
- parentQueue.addChild(owner.e = queue);
669
- onCleanup(() => parentQueue.removeChild(owner.e));
660
+ const parentQueue = owner.g || globalQueue;
661
+ parentQueue.addChild(owner.g = queue);
662
+ onCleanup(() => parentQueue.removeChild(owner.g));
670
663
  return compute(owner, fn, null);
671
664
  }
672
665
  function runTop(node) {
673
666
  const ancestors = [];
674
- for (let current = node; current !== null; current = current.o) {
667
+ for (let current = node; current !== null; current = current.r) {
675
668
  if (current.a !== STATE_CLEAN) {
676
669
  ancestors.push(current);
677
670
  }
678
671
  }
679
672
  for (let i = ancestors.length - 1; i >= 0; i--) {
680
673
  if (ancestors[i].a !== STATE_DISPOSED)
681
- ancestors[i].s();
674
+ ancestors[i].x();
682
675
  }
683
676
  }
684
677
  function runPureQueue(queue) {
@@ -689,110 +682,138 @@ function runPureQueue(queue) {
689
682
  }
690
683
  function runEffectQueue(queue) {
691
684
  for (let i = 0; i < queue.length; i++)
692
- queue[i].R();
685
+ queue[i].V();
693
686
  }
694
687
 
695
688
  // src/core/effect.ts
696
689
  var Effect = class extends Computation {
697
- K;
698
- L = false;
699
- F;
690
+ J;
691
+ A;
700
692
  B;
701
- e;
702
- constructor(initialValue, compute2, effect, options) {
693
+ P = false;
694
+ K;
695
+ C;
696
+ g;
697
+ constructor(initialValue, compute2, effect, error, options) {
703
698
  super(initialValue, compute2, options);
704
- this.K = effect;
705
- this.F = initialValue;
706
- this.B = options?.render ? EFFECT_RENDER : EFFECT_USER;
707
- this.e = getOwner()?.e || globalQueue;
708
- this.s();
709
- 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
+ }
710
708
  }
711
709
  write(value, flags = 0) {
712
- const currentFlags = this.f;
713
- this.f = flags;
714
- if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
715
- 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);
716
714
  }
717
715
  if (value === UNCHANGED)
718
- return this.d;
719
- this.d = value;
720
- this.L = true;
716
+ return this.e;
717
+ this.e = value;
718
+ this.P = true;
721
719
  return value;
722
720
  }
723
- t(state) {
724
- if (this.a >= state)
721
+ q(state, skipQueue) {
722
+ if (this.a >= state || skipQueue)
725
723
  return;
726
724
  if (this.a === STATE_CLEAN)
727
- this.e.enqueue(this.B, this);
725
+ this.g.enqueue(this.C, this);
728
726
  this.a = state;
729
727
  }
730
- 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
+ }
731
741
  this.handleError(error);
732
742
  }
733
- x() {
743
+ y() {
744
+ if (this.a === STATE_DISPOSED)
745
+ return;
746
+ this.J = void 0;
734
747
  this.K = void 0;
735
- this.F = void 0;
736
- super.x();
737
- }
738
- R() {
739
- if (this.L && this.a !== STATE_DISPOSED) {
740
- this.K(this.d, this.F);
741
- this.F = this.d;
742
- 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
+ }
743
764
  }
744
765
  }
745
766
  };
746
767
  var EagerComputation = class extends Computation {
747
- e;
768
+ g;
748
769
  constructor(initialValue, compute2, options) {
749
770
  super(initialValue, compute2, options);
750
- this.e = getOwner()?.e || globalQueue;
751
- this.s();
771
+ this.g = getOwner()?.g || globalQueue;
772
+ this.x();
752
773
  }
753
- t(state) {
754
- if (this.a >= state)
774
+ q(state, skipQueue) {
775
+ if (this.a >= state && !this.H)
755
776
  return;
756
- if (this.a === STATE_CLEAN)
757
- this.e.enqueue(EFFECT_PURE, this);
758
- super.t(state);
777
+ if (this.a === STATE_CLEAN && !skipQueue)
778
+ this.g.enqueue(EFFECT_PURE, this);
779
+ super.q(state, skipQueue);
759
780
  }
760
781
  };
761
782
 
762
783
  // src/core/suspense.ts
763
784
  var SuspenseQueue = class extends Queue {
764
- g = /* @__PURE__ */ new Set();
765
- q = false;
766
- M = new Computation(false, null);
785
+ c = /* @__PURE__ */ new Set();
786
+ o = false;
787
+ R = new Computation(false, null);
767
788
  run(type) {
768
- if (type && this.q)
789
+ if (type && this.o)
769
790
  return;
770
- super.run(type);
771
- }
772
- S(node) {
773
- if (node.f & LOADING_BIT) {
774
- this.g.add(node);
775
- if (!this.q) {
776
- this.q = true;
777
- queueTask(() => this.M.write(true));
791
+ return super.run(type);
792
+ }
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);
778
799
  }
779
800
  } else {
780
- this.g.delete(node);
781
- if (this.g.size === 0) {
782
- this.q = false;
783
- 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);
784
805
  }
785
806
  }
786
807
  }
787
808
  };
788
809
  var LiveComputation = class extends EagerComputation {
789
810
  write(value, flags = 0) {
790
- const currentFlags = this.f;
811
+ const currentFlags = this.h;
791
812
  super.write(value, flags);
792
813
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
793
- this.e.S?.(this);
814
+ this.g.Q?.(this);
794
815
  }
795
- return this.d;
816
+ return this.e;
796
817
  }
797
818
  };
798
819
  function createSuspense(fn, fallback) {
@@ -801,7 +822,7 @@ function createSuspense(fn, fallback) {
801
822
  const child = new Computation(null, fn);
802
823
  return new LiveComputation(null, () => flatten(child.wait()));
803
824
  }, queue);
804
- const equality = new Computation(null, () => queue.M.read() || queue.q);
825
+ const equality = new Computation(null, () => queue.R.read() || queue.o);
805
826
  const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
806
827
  return comp.read.bind(comp);
807
828
  }
@@ -832,10 +853,10 @@ function createMemo(compute2, value, options) {
832
853
  return () => {
833
854
  if (node) {
834
855
  resolvedValue = node.wait();
835
- if (!node.c?.length && node.m?.o !== node) {
856
+ if (!node.d?.length && node.n?.r !== node) {
836
857
  node.dispose();
837
858
  node = void 0;
838
- } else if (!node.o && !node.b?.length) {
859
+ } else if (!node.r && !node.b?.length) {
839
860
  node.dispose();
840
861
  node.a = STATE_UNINITIALIZED;
841
862
  }
@@ -846,10 +867,10 @@ function createMemo(compute2, value, options) {
846
867
  function createAsync(compute2, value, options) {
847
868
  const lhs = new EagerComputation(
848
869
  {
849
- d: value
870
+ e: value
850
871
  },
851
872
  (p) => {
852
- const value2 = p?.d;
873
+ const value2 = p?.e;
853
874
  const source = compute2(value2);
854
875
  const isPromise = source instanceof Promise;
855
876
  const iterator = source[Symbol.asyncIterator];
@@ -858,10 +879,18 @@ function createAsync(compute2, value, options) {
858
879
  wait() {
859
880
  return source;
860
881
  },
861
- d: source
882
+ e: source
862
883
  };
863
884
  }
864
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
+ };
865
894
  signal.write(UNCHANGED, LOADING_BIT);
866
895
  if (isPromise) {
867
896
  source.then(
@@ -892,16 +921,17 @@ function createAsync(compute2, value, options) {
892
921
  );
893
922
  return () => lhs.wait().wait();
894
923
  }
895
- function createEffect(compute2, effect, value, options) {
924
+ function createEffect(compute2, effect, error, value, options) {
896
925
  void new Effect(
897
926
  value,
898
927
  compute2,
899
928
  effect,
929
+ error,
900
930
  void 0
901
931
  );
902
932
  }
903
933
  function createRenderEffect(compute2, effect, value, options) {
904
- void new Effect(value, compute2, effect, {
934
+ void new Effect(value, compute2, effect, void 0, {
905
935
  render: true,
906
936
  ...void 0
907
937
  });
@@ -922,14 +952,14 @@ function createErrorBoundary(fn, fallback) {
922
952
  const owner = new Owner();
923
953
  const error = new Computation(null, null);
924
954
  const reset = new Computation(null, null, { equals: false });
925
- const handler = (err) => error.write({ z: err });
926
- 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];
927
957
  const guarded = compute(
928
958
  owner,
929
959
  () => {
930
960
  const c = new Computation(null, () => (reset.read(), fn()));
931
961
  const f = new Computation(null, () => flatten(c.read()));
932
- f.J = function(error2) {
962
+ f.O = function(error2) {
933
963
  this.handleError(error2);
934
964
  };
935
965
  return f;
@@ -942,13 +972,78 @@ function createErrorBoundary(fn, fallback) {
942
972
  if (!error.read())
943
973
  return resolved;
944
974
  }
945
- return fallback(error.read().z, () => {
975
+ return fallback(error.read().A, () => {
946
976
  error.write(null);
947
977
  reset.write(null);
948
978
  });
949
979
  });
950
980
  return decision.read.bind(decision);
951
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
+ }
952
1047
 
953
1048
  // src/store/store.ts
954
1049
  var $RAW = Symbol(0);
@@ -958,7 +1053,7 @@ var $PROXY = Symbol(0);
958
1053
  var STORE_VALUE = "v";
959
1054
  var STORE_NODE = "n";
960
1055
  var STORE_HAS = "h";
961
- function wrap(value) {
1056
+ function wrap2(value) {
962
1057
  let p = value[$PROXY];
963
1058
  if (!p) {
964
1059
  let target;
@@ -1066,8 +1161,8 @@ var proxyTraps = {
1066
1161
  return desc.get.call(receiver);
1067
1162
  }
1068
1163
  if (Writing.has(storeValue)) {
1069
- const value2 = tracked ? tracked.d : storeValue[property];
1070
- 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;
1071
1166
  }
1072
1167
  let value = tracked ? nodes[property].read() : storeValue[property];
1073
1168
  if (!tracked) {
@@ -1075,10 +1170,10 @@ var proxyTraps = {
1075
1170
  let proto;
1076
1171
  return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
1077
1172
  } else if (getObserver()) {
1078
- value = getNode(nodes, property, isWrappable(value) ? wrap(value) : value).read();
1173
+ value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
1079
1174
  }
1080
1175
  }
1081
- return isWrappable(value) ? wrap(value) : value;
1176
+ return isWrappable(value) ? wrap2(value) : value;
1082
1177
  },
1083
1178
  has(target, property) {
1084
1179
  if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
@@ -1120,13 +1215,16 @@ function setProperty(state, property, value, deleting = false) {
1120
1215
  const nodes = getNodes(target, STORE_NODE);
1121
1216
  let node;
1122
1217
  if (node = nodes[property])
1123
- node.write(isWrappable(value) ? wrap(value) : value);
1218
+ node.write(isWrappable(value) ? wrap2(value) : value);
1124
1219
  Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
1125
1220
  (node = nodes[$TRACK]) && node.write(void 0);
1126
1221
  }
1127
1222
  function createStore(first, second) {
1128
- const derived = typeof first === "function", store = derived ? second : first, unwrappedStore = unwrap(store, false);
1129
- 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);
1130
1228
  const setStore = (fn) => {
1131
1229
  try {
1132
1230
  Writing.add(unwrappedStore);
@@ -1135,15 +1233,8 @@ function createStore(first, second) {
1135
1233
  Writing.clear();
1136
1234
  }
1137
1235
  };
1138
- if (derived) {
1139
- new EagerComputation(void 0, () => setStore(first));
1140
- }
1141
1236
  return [wrappedStore, setStore];
1142
1237
  }
1143
- function createProjection(fn, initialValue = {}) {
1144
- const [store] = createStore(fn, initialValue);
1145
- return store;
1146
- }
1147
1238
 
1148
1239
  // src/store/reconcile.ts
1149
1240
  function applyState(next, state, keyFn) {
@@ -1164,7 +1255,7 @@ function applyState(next, state, keyFn) {
1164
1255
  if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
1165
1256
  let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1166
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++) {
1167
- applyState(next[start], wrap(previous[start]), keyFn);
1258
+ applyState(next[start], wrap2(previous[start]), keyFn);
1168
1259
  }
1169
1260
  const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1170
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--) {
@@ -1173,11 +1264,11 @@ function applyState(next, state, keyFn) {
1173
1264
  if (start > newEnd || start > end) {
1174
1265
  for (j = start; j <= newEnd; j++) {
1175
1266
  changed = true;
1176
- target[STORE_NODE][j]?.write(wrap(next[j]));
1267
+ target[STORE_NODE][j]?.write(wrap2(next[j]));
1177
1268
  }
1178
1269
  for (; j < next.length; j++) {
1179
1270
  changed = true;
1180
- const wrapped = wrap(temp[j]);
1271
+ const wrapped = wrap2(temp[j]);
1181
1272
  target[STORE_NODE][j]?.write(wrapped);
1182
1273
  applyState(next[j], wrapped, keyFn);
1183
1274
  }
@@ -1205,17 +1296,17 @@ function applyState(next, state, keyFn) {
1205
1296
  }
1206
1297
  for (j = start; j < next.length; j++) {
1207
1298
  if (j in temp) {
1208
- const wrapped = wrap(temp[j]);
1299
+ const wrapped = wrap2(temp[j]);
1209
1300
  target[STORE_NODE][j]?.write(wrapped);
1210
1301
  applyState(next[j], wrapped, keyFn);
1211
1302
  } else
1212
- target[STORE_NODE][j]?.write(wrap(next[j]));
1303
+ target[STORE_NODE][j]?.write(wrap2(next[j]));
1213
1304
  }
1214
1305
  if (start < next.length)
1215
1306
  changed = true;
1216
1307
  } else if (previous.length && next.length) {
1217
1308
  for (let i = 0, len = next.length; i < len; i++) {
1218
- isWrappable(previous[i]) && applyState(next[i], wrap(previous[i]), keyFn);
1309
+ isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
1219
1310
  }
1220
1311
  }
1221
1312
  if (previous.length !== next.length) {
@@ -1235,9 +1326,9 @@ function applyState(next, state, keyFn) {
1235
1326
  if (previousValue === nextValue)
1236
1327
  continue;
1237
1328
  if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
1238
- node.write(isWrappable(nextValue) ? wrap(nextValue) : nextValue);
1329
+ node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
1239
1330
  else
1240
- applyState(nextValue, wrap(previousValue), keyFn);
1331
+ applyState(nextValue, wrap2(previousValue), keyFn);
1241
1332
  }
1242
1333
  }
1243
1334
  if (nodes = target[STORE_HAS]) {
@@ -1409,123 +1500,169 @@ function omit(props, ...keys) {
1409
1500
  function mapArray(list, map, options) {
1410
1501
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1411
1502
  return updateKeyedMap.bind({
1412
- T: new Owner(),
1413
- w: 0,
1414
- U: list,
1415
- r: [],
1416
- N: map,
1417
- l: [],
1418
- g: [],
1419
- y: keyFn,
1420
- h: keyFn || options?.keyed === false ? [] : void 0,
1421
- i: map.length > 1 ? [] : void 0,
1422
- q: 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
1423
1514
  });
1424
1515
  }
1425
1516
  function updateKeyedMap() {
1426
- const newItems = this.U() || [], newLen = newItems.length;
1517
+ const newItems = this.W() || [], newLen = newItems.length;
1427
1518
  newItems[$TRACK];
1428
- runWithOwner(this.T, () => {
1429
- let i, j, mapper = this.h ? () => {
1430
- this.h[j] = new Computation(newItems[j], null);
1431
- this.i && (this.i[j] = new Computation(j, null));
1432
- return this.N(
1433
- Computation.prototype.read.bind(this.h[j]),
1434
- 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
1435
1526
  );
1436
- } : this.i ? () => {
1527
+ } : this.k ? () => {
1437
1528
  const item = newItems[j];
1438
- this.i[j] = new Computation(j, null);
1439
- 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]));
1440
1531
  } : () => {
1441
1532
  const item = newItems[j];
1442
- return this.N(() => item);
1533
+ return this.G(() => item);
1443
1534
  };
1444
1535
  if (newLen === 0) {
1445
- if (this.w !== 0) {
1446
- this.T.dispose(false);
1447
- this.g = [];
1448
- this.r = [];
1449
- this.l = [];
1450
- this.w = 0;
1451
- this.h && (this.h = []);
1452
- 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 = []);
1453
1544
  }
1454
- if (this.q && !this.l[0]) {
1455
- this.l[0] = compute(
1456
- this.g[0] = new Owner(),
1457
- this.q,
1545
+ if (this.o && !this.f[0]) {
1546
+ this.f[0] = compute(
1547
+ this.c[0] = new Owner(),
1548
+ this.o,
1458
1549
  null
1459
1550
  );
1460
1551
  }
1461
- } else if (this.w === 0) {
1462
- if (this.g[0])
1463
- this.g[0].dispose();
1464
- 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);
1465
1556
  for (j = 0; j < newLen; j++) {
1466
- this.r[j] = newItems[j];
1467
- 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);
1468
1559
  }
1469
- this.w = newLen;
1560
+ this.i = newLen;
1470
1561
  } else {
1471
- 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;
1472
- for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.h && compare(this.y, this.r[start], newItems[start])); start++) {
1473
- if (this.h)
1474
- 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]);
1475
1566
  }
1476
- for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.h && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
1477
- temp[newEnd] = this.l[end];
1478
- tempNodes[newEnd] = this.g[end];
1479
- tempRows && (tempRows[newEnd] = this.h[end]);
1480
- 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]);
1481
1572
  }
1482
1573
  newIndices = /* @__PURE__ */ new Map();
1483
1574
  newIndicesNext = new Array(newEnd + 1);
1484
1575
  for (j = newEnd; j >= start; j--) {
1485
1576
  item = newItems[j];
1486
- key = this.y ? this.y(item) : item;
1577
+ key = this.D ? this.D(item) : item;
1487
1578
  i = newIndices.get(key);
1488
1579
  newIndicesNext[j] = i === void 0 ? -1 : i;
1489
1580
  newIndices.set(key, j);
1490
1581
  }
1491
1582
  for (i = start; i <= end; i++) {
1492
- item = this.r[i];
1493
- key = this.y ? this.y(item) : item;
1583
+ item = this.u[i];
1584
+ key = this.D ? this.D(item) : item;
1494
1585
  j = newIndices.get(key);
1495
1586
  if (j !== void 0 && j !== -1) {
1496
- temp[j] = this.l[i];
1497
- tempNodes[j] = this.g[i];
1498
- tempRows && (tempRows[j] = this.h[i]);
1499
- 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]);
1500
1591
  j = newIndicesNext[j];
1501
1592
  newIndices.set(key, j);
1502
1593
  } else
1503
- this.g[i].dispose();
1594
+ this.c[i].dispose();
1504
1595
  }
1505
1596
  for (j = start; j < newLen; j++) {
1506
1597
  if (j in temp) {
1507
- this.l[j] = temp[j];
1508
- this.g[j] = tempNodes[j];
1598
+ this.f[j] = temp[j];
1599
+ this.c[j] = tempNodes[j];
1509
1600
  if (tempRows) {
1510
- this.h[j] = tempRows[j];
1511
- this.h[j].write(newItems[j]);
1601
+ this.j[j] = tempRows[j];
1602
+ this.j[j].write(newItems[j]);
1512
1603
  }
1513
1604
  if (tempIndexes) {
1514
- this.i[j] = tempIndexes[j];
1515
- this.i[j].write(j);
1605
+ this.k[j] = tempIndexes[j];
1606
+ this.k[j].write(j);
1516
1607
  }
1517
1608
  } else {
1518
- this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
1609
+ this.f[j] = compute(this.c[j] = new Owner(), mapper, null);
1519
1610
  }
1520
1611
  }
1521
- this.l = this.l.slice(0, this.w = newLen);
1522
- this.r = 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;
1523
1660
  }
1524
1661
  });
1525
- return this.l;
1662
+ return this.f;
1526
1663
  }
1527
1664
  function compare(key, a, b) {
1528
1665
  return key ? key(a) === key(b) : true;
1529
1666
  }
1530
1667
 
1531
- 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 };