@solidjs/signals 0.0.7 → 0.0.9

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