@solidjs/signals 0.2.4 → 0.3.0

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
@@ -72,8 +72,8 @@ var Queue = class {
72
72
  for (let i = 0; i < this.F.length; i++) {
73
73
  rerun = this.F[i].run(type) || rerun;
74
74
  }
75
- if (type === EFFECT_PURE && this.s[type].length)
76
- return true;
75
+ if (type === EFFECT_PURE)
76
+ return rerun || !!this.s[type].length;
77
77
  }
78
78
  flush() {
79
79
  if (this.J)
@@ -107,14 +107,14 @@ function flushSync() {
107
107
  }
108
108
  function runTop(node) {
109
109
  const ancestors = [];
110
- for (let current = node; current !== null; current = current.t) {
110
+ for (let current = node; current !== null; current = current.x) {
111
111
  if (current.a !== STATE_CLEAN) {
112
112
  ancestors.push(current);
113
113
  }
114
114
  }
115
115
  for (let i = ancestors.length - 1; i >= 0; i--) {
116
116
  if (ancestors[i].a !== STATE_DISPOSED)
117
- ancestors[i].z();
117
+ ancestors[i].y();
118
118
  }
119
119
  }
120
120
  function runPureQueue(queue) {
@@ -125,13 +125,33 @@ function runPureQueue(queue) {
125
125
  }
126
126
  function runEffectQueue(queue) {
127
127
  for (let i = 0; i < queue.length; i++)
128
- queue[i].U();
128
+ queue[i].T();
129
129
  }
130
130
 
131
131
  // src/core/utils.ts
132
132
  function isUndefined(value) {
133
133
  return typeof value === "undefined";
134
134
  }
135
+ function tryCatch(fn) {
136
+ try {
137
+ const v = fn();
138
+ if (v instanceof Promise) {
139
+ return v.then(
140
+ (v2) => [void 0, v2],
141
+ (e) => {
142
+ if (e instanceof NotReadyError)
143
+ throw e;
144
+ return [e];
145
+ }
146
+ );
147
+ }
148
+ return [void 0, v];
149
+ } catch (e) {
150
+ if (e instanceof NotReadyError)
151
+ throw e;
152
+ return [e];
153
+ }
154
+ }
135
155
 
136
156
  // src/core/owner.ts
137
157
  var currentOwner = null;
@@ -144,34 +164,46 @@ function setOwner(owner) {
144
164
  currentOwner = owner;
145
165
  return out;
146
166
  }
167
+ function formatId(prefix, id) {
168
+ const num = id.toString(36), len = num.length - 1;
169
+ return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
170
+ }
147
171
  var Owner = class {
148
172
  // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
149
173
  // However, the children are actually added in reverse creation order
150
174
  // See comment at the top of the file for an example of the _nextSibling traversal
175
+ x = null;
176
+ l = null;
151
177
  t = null;
152
- n = null;
153
- u = null;
154
178
  a = STATE_CLEAN;
155
- l = null;
156
- p = defaultContext;
157
179
  m = null;
180
+ o = defaultContext;
181
+ n = null;
158
182
  h = globalQueue;
159
- constructor(signal = false) {
160
- if (currentOwner && !signal)
183
+ O = null;
184
+ X = 0;
185
+ id = null;
186
+ constructor(id = null, skipAppend = false) {
187
+ this.id = id;
188
+ if (currentOwner && !skipAppend)
161
189
  currentOwner.append(this);
162
190
  }
163
191
  append(child) {
192
+ child.x = this;
164
193
  child.t = this;
165
- child.u = this;
166
- if (this.n)
167
- this.n.u = child;
168
- child.n = this.n;
169
- this.n = child;
170
- if (child.p !== this.p) {
171
- child.p = { ...this.p, ...child.p };
194
+ if (this.id) {
195
+ child.O = this.l ? this.l.O + 1 : 0;
196
+ child.id = formatId(this.id, child.O);
172
197
  }
173
- if (this.m) {
174
- child.m = !child.m ? this.m : [...child.m, ...this.m];
198
+ if (this.l)
199
+ this.l.t = child;
200
+ child.l = this.l;
201
+ this.l = child;
202
+ if (child.o !== this.o) {
203
+ child.o = { ...this.o, ...child.o };
204
+ }
205
+ if (this.n) {
206
+ child.n = !child.n ? this.n : [...child.n, ...this.n];
175
207
  }
176
208
  if (this.h)
177
209
  child.h = this.h;
@@ -179,51 +211,54 @@ var Owner = class {
179
211
  dispose(self = true) {
180
212
  if (this.a === STATE_DISPOSED)
181
213
  return;
182
- let head = self ? this.u || this.t : this, current = this.n, next = null;
183
- while (current && current.t === this) {
214
+ let head = self ? this.t || this.x : this, current = this.l, next = null;
215
+ while (current && current.x === this) {
184
216
  current.dispose(true);
185
- current.A();
186
- next = current.n;
187
- current.n = null;
217
+ current.z();
218
+ next = current.l;
219
+ current.l = null;
188
220
  current = next;
189
221
  }
190
222
  if (self)
191
- this.A();
223
+ this.z();
192
224
  if (current)
193
- current.u = !self ? this : this.u;
225
+ current.t = !self ? this : this.t;
194
226
  if (head)
195
- head.n = current;
227
+ head.l = current;
196
228
  }
197
- A() {
198
- if (this.u)
199
- this.u.n = null;
229
+ z() {
230
+ if (this.t)
231
+ this.t.l = null;
232
+ this.x = null;
200
233
  this.t = null;
201
- this.u = null;
202
- this.p = defaultContext;
203
- this.m = null;
234
+ this.o = defaultContext;
235
+ this.n = null;
204
236
  this.a = STATE_DISPOSED;
205
237
  this.emptyDisposal();
206
238
  }
207
239
  emptyDisposal() {
208
- if (!this.l)
240
+ if (!this.m)
209
241
  return;
210
- if (Array.isArray(this.l)) {
211
- for (let i = 0; i < this.l.length; i++) {
212
- const callable = this.l[i];
242
+ if (Array.isArray(this.m)) {
243
+ for (let i = 0; i < this.m.length; i++) {
244
+ const callable = this.m[i];
213
245
  callable.call(callable);
214
246
  }
215
247
  } else {
216
- this.l.call(this.l);
248
+ this.m.call(this.m);
217
249
  }
218
- this.l = null;
250
+ this.m = null;
251
+ }
252
+ addErrorHandler(handler) {
253
+ this.n = this.n ? [handler, ...this.n] : [handler];
219
254
  }
220
255
  handleError(error) {
221
- if (!this.m)
256
+ if (!this.n)
222
257
  throw error;
223
- let i = 0, len = this.m.length;
258
+ let i = 0, len = this.n.length;
224
259
  for (i = 0; i < len; i++) {
225
260
  try {
226
- this.m[i](error, this);
261
+ this.n[i](error, this);
227
262
  break;
228
263
  } catch (e) {
229
264
  error = e;
@@ -232,6 +267,11 @@ var Owner = class {
232
267
  if (i === len)
233
268
  throw error;
234
269
  }
270
+ getNextChildId() {
271
+ if (this.id)
272
+ return formatId(this.id + "-", this.X++);
273
+ throw new Error("Cannot get child id from owner without an id");
274
+ }
235
275
  };
236
276
  function createContext(defaultValue, description) {
237
277
  return { id: Symbol(description), defaultValue };
@@ -240,7 +280,7 @@ function getContext(context, owner = currentOwner) {
240
280
  if (!owner) {
241
281
  throw new NoOwnerError();
242
282
  }
243
- const value = hasContext(context, owner) ? owner.p[context.id] : context.defaultValue;
283
+ const value = hasContext(context, owner) ? owner.o[context.id] : context.defaultValue;
244
284
  if (isUndefined(value)) {
245
285
  throw new ContextNotFoundError();
246
286
  }
@@ -250,24 +290,24 @@ function setContext(context, value, owner = currentOwner) {
250
290
  if (!owner) {
251
291
  throw new NoOwnerError();
252
292
  }
253
- owner.p = {
254
- ...owner.p,
293
+ owner.o = {
294
+ ...owner.o,
255
295
  [context.id]: isUndefined(value) ? context.defaultValue : value
256
296
  };
257
297
  }
258
298
  function hasContext(context, owner = currentOwner) {
259
- return !isUndefined(owner?.p[context.id]);
299
+ return !isUndefined(owner?.o[context.id]);
260
300
  }
261
301
  function onCleanup(fn) {
262
302
  if (!currentOwner)
263
303
  return fn;
264
304
  const node = currentOwner;
265
- if (!node.l) {
266
- node.l = fn;
267
- } else if (Array.isArray(node.l)) {
268
- node.l.push(fn);
305
+ if (!node.m) {
306
+ node.m = fn;
307
+ } else if (Array.isArray(node.m)) {
308
+ node.m.push(fn);
269
309
  } else {
270
- node.l = [node.l, fn];
310
+ node.m = [node.m, fn];
271
311
  }
272
312
  return fn;
273
313
  }
@@ -295,46 +335,44 @@ function getObserver() {
295
335
  }
296
336
  var UNCHANGED = Symbol(0);
297
337
  var Computation = class extends Owner {
298
- b = null;
299
- e = null;
338
+ c = null;
339
+ f = null;
300
340
  g;
301
341
  G;
302
- B;
342
+ A;
303
343
  // Used in __DEV__ mode, hopefully removed in production
304
344
  $;
305
345
  // Using false is an optimization as an alternative to _equals: () => false
306
346
  // which could enable more efficient DIRTY notification
307
- O = isEqual;
308
- V;
347
+ P = isEqual;
348
+ U;
309
349
  /** Whether the computation is an error or has ancestors that are unresolved */
310
- f = 0;
350
+ d = 0;
311
351
  /** Which flags raised by sources are handled, vs. being passed through. */
312
- P = DEFAULT_FLAGS;
313
- Q = null;
314
- y = -1;
352
+ Q = DEFAULT_FLAGS;
353
+ B = -1;
315
354
  K = false;
316
355
  constructor(initialValue, compute2, options) {
317
- super(compute2 === null);
318
- this.B = compute2;
356
+ super(null, compute2 === null);
357
+ this.A = compute2;
319
358
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
320
- this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
359
+ this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
321
360
  this.g = initialValue;
322
361
  if (options?.equals !== void 0)
323
- this.O = options.equals;
362
+ this.P = options.equals;
324
363
  if (options?.unobserved)
325
- this.V = options?.unobserved;
364
+ this.U = options?.unobserved;
326
365
  }
327
- W() {
328
- if (this.B) {
329
- if (this.f & ERROR_BIT && this.y <= getClock())
366
+ V() {
367
+ if (this.A) {
368
+ if (this.d & ERROR_BIT && this.B <= getClock())
330
369
  update(this);
331
370
  else
332
- this.z();
371
+ this.y();
333
372
  }
334
- if (!this.B || this.b?.length)
335
- track(this);
336
- newFlags |= this.f & ~currentMask;
337
- if (this.f & ERROR_BIT) {
373
+ track(this);
374
+ newFlags |= this.d & ~currentMask;
375
+ if (this.d & ERROR_BIT) {
338
376
  throw this.G;
339
377
  } else {
340
378
  return this.g;
@@ -345,7 +383,7 @@ var Computation = class extends Owner {
345
383
  * Automatically re-executes the surrounding computation when the value changes
346
384
  */
347
385
  read() {
348
- return this.W();
386
+ return this.V();
349
387
  }
350
388
  /**
351
389
  * Return the current value of this computation
@@ -355,46 +393,37 @@ var Computation = class extends Owner {
355
393
  * before continuing
356
394
  */
357
395
  wait() {
358
- if (this.B && this.f & ERROR_BIT && this.y <= getClock()) {
396
+ if (this.A && this.d & ERROR_BIT && this.B <= getClock()) {
359
397
  update(this);
398
+ } else {
399
+ this.y();
360
400
  }
361
- if ((notStale || this.f & UNINITIALIZED_BIT) && this.loading()) {
401
+ track(this);
402
+ if ((notStale || this.d & UNINITIALIZED_BIT) && this.d & LOADING_BIT) {
362
403
  throw new NotReadyError();
363
404
  }
364
- if (staleCheck && this.loading())
405
+ if (staleCheck && this.d & LOADING_BIT) {
365
406
  staleCheck.g = true;
366
- return this.W();
367
- }
368
- /**
369
- * Return true if the computation is the value is dependent on an unresolved promise
370
- * Triggers re-execution of the computation when the loading state changes
371
- *
372
- * This is useful especially when effects want to re-execute when a computation's
373
- * loading state changes
374
- */
375
- loading() {
376
- if (this.Q === null) {
377
- this.Q = loadingState(this);
378
407
  }
379
- return this.Q.read();
408
+ return this.V();
380
409
  }
381
410
  /** Update the computation with a new value. */
382
411
  write(value, flags = 0, raw = false) {
383
412
  const newValue = !raw && typeof value === "function" ? value(this.g) : value;
384
- const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || this.O === false || !this.O(this.g, newValue));
413
+ const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.d & LOADING_BIT & ~flags || this.P === false || !this.P(this.g, newValue));
385
414
  if (valueChanged) {
386
415
  this.g = newValue;
387
416
  this.G = void 0;
388
417
  }
389
- const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
390
- this.f = flags;
391
- this.y = getClock() + 1;
392
- if (this.e) {
393
- for (let i = 0; i < this.e.length; i++) {
418
+ const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
419
+ this.d = flags;
420
+ this.B = getClock() + 1;
421
+ if (this.f) {
422
+ for (let i = 0; i < this.f.length; i++) {
394
423
  if (valueChanged) {
395
- this.e[i].q(STATE_DIRTY);
424
+ this.f[i].r(STATE_DIRTY);
396
425
  } else if (changedFlagsMask) {
397
- this.e[i].X(changedFlagsMask, changedFlags);
426
+ this.f[i].W(changedFlagsMask, changedFlags);
398
427
  }
399
428
  }
400
429
  }
@@ -403,14 +432,14 @@ var Computation = class extends Owner {
403
432
  /**
404
433
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
405
434
  */
406
- q(state, skipQueue) {
435
+ r(state, skipQueue) {
407
436
  if (this.a >= state && !this.K)
408
437
  return;
409
438
  this.K = !!skipQueue;
410
439
  this.a = state;
411
- if (this.e) {
412
- for (let i = 0; i < this.e.length; i++) {
413
- this.e[i].q(STATE_CHECK, skipQueue);
440
+ if (this.f) {
441
+ for (let i = 0; i < this.f.length; i++) {
442
+ this.f[i].r(STATE_CHECK, skipQueue);
414
443
  }
415
444
  }
416
445
  }
@@ -420,31 +449,31 @@ var Computation = class extends Owner {
420
449
  * @param mask A bitmask for which flag(s) were changed.
421
450
  * @param newFlags The source's new flags, masked to just the changed ones.
422
451
  */
423
- X(mask, newFlags2) {
452
+ W(mask, newFlags2) {
424
453
  if (this.a >= STATE_DIRTY)
425
454
  return;
426
- if (mask & this.P) {
427
- this.q(STATE_DIRTY);
455
+ if (mask & this.Q) {
456
+ this.r(STATE_DIRTY);
428
457
  return;
429
458
  }
430
459
  if (this.a >= STATE_CHECK)
431
460
  return;
432
- const prevFlags = this.f & mask;
461
+ const prevFlags = this.d & mask;
433
462
  const deltaFlags = prevFlags ^ newFlags2;
434
463
  if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
435
- this.q(STATE_CHECK);
464
+ this.r(STATE_CHECK);
436
465
  } else {
437
- this.f ^= deltaFlags;
438
- if (this.e) {
439
- for (let i = 0; i < this.e.length; i++) {
440
- this.e[i].X(mask, newFlags2);
466
+ this.d ^= deltaFlags;
467
+ if (this.f) {
468
+ for (let i = 0; i < this.f.length; i++) {
469
+ this.f[i].W(mask, newFlags2);
441
470
  }
442
471
  }
443
472
  }
444
473
  }
445
474
  H(error) {
446
475
  this.G = error;
447
- this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
476
+ this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
448
477
  }
449
478
  /**
450
479
  * This is the core part of the reactivity system, which makes sure that the values are updated
@@ -453,18 +482,21 @@ var Computation = class extends Owner {
453
482
  *
454
483
  * This function will ensure that the value and states we read from the computation are up to date
455
484
  */
456
- z() {
485
+ y() {
486
+ if (!this.A) {
487
+ return;
488
+ }
457
489
  if (this.a === STATE_DISPOSED) {
458
- throw new Error("Tried to read a disposed computation");
490
+ return;
459
491
  }
460
492
  if (this.a === STATE_CLEAN) {
461
493
  return;
462
494
  }
463
495
  let observerFlags = 0;
464
496
  if (this.a === STATE_CHECK) {
465
- for (let i = 0; i < this.b.length; i++) {
466
- this.b[i].z();
467
- observerFlags |= this.b[i].f;
497
+ for (let i = 0; i < this.c.length; i++) {
498
+ this.c[i].y();
499
+ observerFlags |= this.c[i].d;
468
500
  if (this.a === STATE_DIRTY) {
469
501
  break;
470
502
  }
@@ -480,33 +512,17 @@ var Computation = class extends Owner {
480
512
  /**
481
513
  * Remove ourselves from the owner graph and the computation graph
482
514
  */
483
- A() {
515
+ z() {
484
516
  if (this.a === STATE_DISPOSED)
485
517
  return;
486
- if (this.b)
518
+ if (this.c)
487
519
  removeSourceObservers(this, 0);
488
- super.A();
520
+ super.z();
489
521
  }
490
522
  };
491
- function loadingState(node) {
492
- const prevOwner = setOwner(node.t);
493
- const options = void 0;
494
- const computation = new Computation(
495
- void 0,
496
- () => {
497
- track(node);
498
- node.z();
499
- return !!(node.f & LOADING_BIT);
500
- },
501
- options
502
- );
503
- computation.P = ERROR_BIT | LOADING_BIT;
504
- setOwner(prevOwner);
505
- return computation;
506
- }
507
523
  function track(computation) {
508
524
  if (currentObserver) {
509
- if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
525
+ if (!newSources && currentObserver.c && currentObserver.c[newSourcesIndex] === computation) {
510
526
  newSourcesIndex++;
511
527
  } else if (!newSources)
512
528
  newSources = [computation];
@@ -514,7 +530,7 @@ function track(computation) {
514
530
  newSources.push(computation);
515
531
  }
516
532
  if (updateCheck) {
517
- updateCheck.g = computation.y > currentObserver.y;
533
+ updateCheck.g = computation.B > currentObserver.B;
518
534
  }
519
535
  }
520
536
  }
@@ -526,56 +542,56 @@ function update(node) {
526
542
  try {
527
543
  node.dispose(false);
528
544
  node.emptyDisposal();
529
- const result = compute(node, node.B, node);
545
+ const result = compute(node, node.A, node);
530
546
  node.write(result, newFlags, true);
531
547
  } catch (error) {
532
548
  if (error instanceof NotReadyError) {
533
- node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
549
+ node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
534
550
  } else {
535
551
  node.H(error);
536
552
  }
537
553
  } finally {
538
554
  if (newSources) {
539
- if (node.b)
555
+ if (node.c)
540
556
  removeSourceObservers(node, newSourcesIndex);
541
- if (node.b && newSourcesIndex > 0) {
542
- node.b.length = newSourcesIndex + newSources.length;
557
+ if (node.c && newSourcesIndex > 0) {
558
+ node.c.length = newSourcesIndex + newSources.length;
543
559
  for (let i = 0; i < newSources.length; i++) {
544
- node.b[newSourcesIndex + i] = newSources[i];
560
+ node.c[newSourcesIndex + i] = newSources[i];
545
561
  }
546
562
  } else {
547
- node.b = newSources;
563
+ node.c = newSources;
548
564
  }
549
565
  let source;
550
- for (let i = newSourcesIndex; i < node.b.length; i++) {
551
- source = node.b[i];
552
- if (!source.e)
553
- source.e = [node];
566
+ for (let i = newSourcesIndex; i < node.c.length; i++) {
567
+ source = node.c[i];
568
+ if (!source.f)
569
+ source.f = [node];
554
570
  else
555
- source.e.push(node);
571
+ source.f.push(node);
556
572
  }
557
- } else if (node.b && newSourcesIndex < node.b.length) {
573
+ } else if (node.c && newSourcesIndex < node.c.length) {
558
574
  removeSourceObservers(node, newSourcesIndex);
559
- node.b.length = newSourcesIndex;
575
+ node.c.length = newSourcesIndex;
560
576
  }
561
577
  newSources = prevSources;
562
578
  newSourcesIndex = prevSourcesIndex;
563
579
  newFlags = prevFlags;
564
- node.y = getClock() + 1;
580
+ node.B = getClock() + 1;
565
581
  node.a = STATE_CLEAN;
566
582
  }
567
583
  }
568
584
  function removeSourceObservers(node, index) {
569
585
  let source;
570
586
  let swap;
571
- for (let i = index; i < node.b.length; i++) {
572
- source = node.b[i];
573
- if (source.e) {
574
- swap = source.e.indexOf(node);
575
- source.e[swap] = source.e[source.e.length - 1];
576
- source.e.pop();
577
- if (!source.e.length)
578
- source.V?.();
587
+ for (let i = index; i < node.c.length; i++) {
588
+ source = node.c[i];
589
+ if (source.f) {
590
+ swap = source.f.indexOf(node);
591
+ source.f[swap] = source.f[source.f.length - 1];
592
+ source.f.pop();
593
+ if (!source.f.length)
594
+ source.U?.();
579
595
  }
580
596
  }
581
597
  }
@@ -597,8 +613,7 @@ function hasUpdated(fn) {
597
613
  updateCheck = current;
598
614
  }
599
615
  }
600
- function isPending(fn, loadingValue) {
601
- const argLength = arguments.length;
616
+ function pendingCheck(fn, loadingValue) {
602
617
  const current = staleCheck;
603
618
  staleCheck = { g: false };
604
619
  try {
@@ -607,13 +622,20 @@ function isPending(fn, loadingValue) {
607
622
  } catch (err) {
608
623
  if (!(err instanceof NotReadyError))
609
624
  return false;
610
- if (argLength > 1)
625
+ if (loadingValue !== void 0)
611
626
  return loadingValue;
612
627
  throw err;
613
628
  } finally {
614
629
  staleCheck = current;
615
630
  }
616
631
  }
632
+ function isPending(fn, loadingValue) {
633
+ if (!currentObserver)
634
+ return pendingCheck(fn, loadingValue);
635
+ const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
636
+ c.Q |= LOADING_BIT;
637
+ return c.read();
638
+ }
617
639
  function latest(fn, fallback) {
618
640
  const argLength = arguments.length;
619
641
  const prevFlags = newFlags;
@@ -630,19 +652,10 @@ function latest(fn, fallback) {
630
652
  notStale = prevNotStale;
631
653
  }
632
654
  }
633
- function catchError(fn) {
634
- try {
635
- fn();
636
- } catch (e) {
637
- if (e instanceof NotReadyError)
638
- throw e;
639
- return e;
640
- }
641
- }
642
655
  function runWithObserver(observer, run) {
643
656
  const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
644
657
  newSources = null;
645
- newSourcesIndex = observer.b ? observer.b.length : 0;
658
+ newSourcesIndex = observer.c ? observer.c.length : 0;
646
659
  newFlags = 0;
647
660
  try {
648
661
  return compute(observer, run, observer);
@@ -650,7 +663,7 @@ function runWithObserver(observer, run) {
650
663
  if (error instanceof NotReadyError) {
651
664
  observer.write(
652
665
  UNCHANGED,
653
- newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
666
+ newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
654
667
  );
655
668
  } else {
656
669
  observer.H(error);
@@ -658,20 +671,20 @@ function runWithObserver(observer, run) {
658
671
  } finally {
659
672
  if (newSources) {
660
673
  if (newSourcesIndex > 0) {
661
- observer.b.length = newSourcesIndex + newSources.length;
674
+ observer.c.length = newSourcesIndex + newSources.length;
662
675
  for (let i = 0; i < newSources.length; i++) {
663
- observer.b[newSourcesIndex + i] = newSources[i];
676
+ observer.c[newSourcesIndex + i] = newSources[i];
664
677
  }
665
678
  } else {
666
- observer.b = newSources;
679
+ observer.c = newSources;
667
680
  }
668
681
  let source;
669
- for (let i = newSourcesIndex; i < observer.b.length; i++) {
670
- source = observer.b[i];
671
- if (!source.e)
672
- source.e = [observer];
682
+ for (let i = newSourcesIndex; i < observer.c.length; i++) {
683
+ source = observer.c[i];
684
+ if (!source.f)
685
+ source.f = [observer];
673
686
  else
674
- source.e.push(observer);
687
+ source.f.push(observer);
675
688
  }
676
689
  }
677
690
  newSources = prevSources;
@@ -682,7 +695,7 @@ function runWithObserver(observer, run) {
682
695
  function compute(owner, fn, observer) {
683
696
  const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
684
697
  currentObserver = observer;
685
- currentMask = observer?.P ?? DEFAULT_FLAGS;
698
+ currentMask = observer?.Q ?? DEFAULT_FLAGS;
686
699
  notStale = true;
687
700
  try {
688
701
  return fn(observer ? observer.g : void 0);
@@ -755,13 +768,6 @@ function flattenArray(children, results = [], options) {
755
768
  throw notReady;
756
769
  return needsUnwrap;
757
770
  }
758
- function createBoundary(fn, queue) {
759
- const owner = new Owner();
760
- const parentQueue = owner.h;
761
- parentQueue.addChild(owner.h = queue);
762
- onCleanup(() => parentQueue.removeChild(owner.h));
763
- return compute(owner, fn, null);
764
- }
765
771
 
766
772
  // src/core/effect.ts
767
773
  var Effect = class extends Computation {
@@ -770,24 +776,24 @@ var Effect = class extends Computation {
770
776
  C;
771
777
  R = false;
772
778
  N;
773
- w;
779
+ u;
774
780
  constructor(initialValue, compute2, effect, error, options) {
775
781
  super(initialValue, compute2, options);
776
782
  this.L = effect;
777
783
  this.M = error;
778
784
  this.N = initialValue;
779
- this.w = options?.render ? EFFECT_RENDER : EFFECT_USER;
780
- if (this.w === EFFECT_RENDER) {
781
- this.B = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
785
+ this.u = options?.render ? EFFECT_RENDER : EFFECT_USER;
786
+ if (this.u === EFFECT_RENDER) {
787
+ this.A = (p) => getClock() > this.h.created && !(this.d & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
782
788
  }
783
- this.z();
784
- !options?.defer && (this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.U());
789
+ this.y();
790
+ !options?.defer && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
785
791
  }
786
792
  write(value, flags = 0) {
787
793
  if (this.a == STATE_DIRTY) {
788
- const currentFlags = this.f;
789
- this.f = flags;
790
- if (this.w === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
794
+ const currentFlags = this.d;
795
+ this.d = flags;
796
+ if (this.u === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
791
797
  this.h.S?.(this);
792
798
  }
793
799
  }
@@ -797,20 +803,20 @@ var Effect = class extends Computation {
797
803
  this.R = true;
798
804
  return value;
799
805
  }
800
- q(state, skipQueue) {
806
+ r(state, skipQueue) {
801
807
  if (this.a >= state || skipQueue)
802
808
  return;
803
809
  if (this.a === STATE_CLEAN)
804
- this.h.enqueue(this.w, this);
810
+ this.h.enqueue(this.u, this);
805
811
  this.a = state;
806
812
  }
807
813
  H(error) {
808
814
  this.C?.();
809
- if (this.f & LOADING_BIT) {
815
+ if (this.d & LOADING_BIT) {
810
816
  this.h.S?.(this);
811
817
  }
812
- this.f = ERROR_BIT;
813
- if (this.w === EFFECT_USER) {
818
+ this.d = ERROR_BIT;
819
+ if (this.u === EFFECT_USER) {
814
820
  try {
815
821
  return this.M ? this.C = this.M(error) : console.error(new EffectError(this.L, error));
816
822
  } catch (e) {
@@ -819,7 +825,7 @@ var Effect = class extends Computation {
819
825
  }
820
826
  this.handleError(error);
821
827
  }
822
- A() {
828
+ z() {
823
829
  if (this.a === STATE_DISPOSED)
824
830
  return;
825
831
  this.L = void 0;
@@ -827,9 +833,9 @@ var Effect = class extends Computation {
827
833
  this.M = void 0;
828
834
  this.C?.();
829
835
  this.C = void 0;
830
- super.A();
836
+ super.z();
831
837
  }
832
- U() {
838
+ T() {
833
839
  if (this.R && this.a !== STATE_DISPOSED) {
834
840
  this.C?.();
835
841
  try {
@@ -846,75 +852,126 @@ var Effect = class extends Computation {
846
852
  var EagerComputation = class extends Computation {
847
853
  constructor(initialValue, compute2, options) {
848
854
  super(initialValue, compute2, options);
849
- !options?.defer && this.z();
855
+ !options?.defer && this.y();
850
856
  }
851
- q(state, skipQueue) {
857
+ r(state, skipQueue) {
852
858
  if (this.a >= state && !this.K)
853
859
  return;
854
860
  if (this.a === STATE_CLEAN && !skipQueue)
855
861
  this.h.enqueue(EFFECT_PURE, this);
856
- super.q(state, skipQueue);
862
+ super.r(state, skipQueue);
857
863
  }
858
864
  };
859
865
  var ProjectionComputation = class extends Computation {
860
866
  constructor(compute2) {
861
- super(null, compute2);
867
+ super(void 0, compute2);
862
868
  }
863
- q(state, skipQueue) {
869
+ r(state, skipQueue) {
864
870
  if (this.a >= state && !this.K)
865
871
  return;
866
872
  if (this.a === STATE_CLEAN && !skipQueue)
867
873
  this.h.enqueue(EFFECT_PURE, this);
868
- super.q(state, true);
874
+ super.r(state, true);
869
875
  }
870
876
  };
871
877
 
872
- // src/core/suspense.ts
878
+ // src/core/boundaries.ts
879
+ function createBoundary(owner, fn, queue) {
880
+ if (queue) {
881
+ const parentQueue = owner.h;
882
+ parentQueue.addChild(owner.h = queue);
883
+ onCleanup(() => parentQueue.removeChild(owner.h));
884
+ }
885
+ return compute(
886
+ owner,
887
+ () => {
888
+ const c = new Computation(void 0, fn);
889
+ return new EagerComputation(void 0, () => flatten(c.wait()), { defer: true });
890
+ },
891
+ null
892
+ );
893
+ }
894
+ function createDecision(main, condition, fallback) {
895
+ const decision = new Computation(void 0, () => {
896
+ if (!condition.read()) {
897
+ const resolved = main.read();
898
+ if (!condition.read())
899
+ return resolved;
900
+ }
901
+ return fallback();
902
+ });
903
+ return decision.read.bind(decision);
904
+ }
873
905
  var SuspenseQueue = class extends Queue {
874
- c = /* @__PURE__ */ new Set();
875
- o = false;
876
- T = new Computation(false, null);
906
+ b = /* @__PURE__ */ new Set();
907
+ p = new Computation(false, null);
877
908
  run(type) {
878
- if (type && this.o)
909
+ if (type && this.p.read())
879
910
  return;
880
911
  return super.run(type);
881
912
  }
882
913
  S(node) {
883
- if (node.f & LOADING_BIT) {
884
- this.c.add(node);
885
- if (!this.o) {
886
- this.o = true;
887
- this.T.write(true);
888
- }
914
+ if (node.d & LOADING_BIT) {
915
+ this.b.add(node);
916
+ if (this.b.size === 1)
917
+ this.p.write(true);
889
918
  } else {
890
- this.c.delete(node);
891
- if (this.c.size === 0) {
892
- this.o = false;
893
- this.T.write(false);
894
- }
919
+ this.b.delete(node);
920
+ if (this.b.size === 0)
921
+ this.p.write(false);
895
922
  }
896
923
  }
897
924
  };
898
- var LiveComputation = class extends EagerComputation {
899
- write(value, flags = 0) {
900
- const currentFlags = this.f;
925
+ function createSuspense(fn, fallback) {
926
+ const owner = new Owner();
927
+ const queue = new SuspenseQueue();
928
+ const tree = createBoundary(owner, fn, queue);
929
+ const ogWrite = tree.write;
930
+ tree.write = function(value, flags = 0) {
931
+ const currentFlags = this.d;
901
932
  const dirty = this.a === STATE_DIRTY;
902
- super.write(value, flags);
933
+ ogWrite.call(this, value, flags);
903
934
  if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
904
935
  this.h.S?.(this);
905
936
  }
906
937
  return this.g;
938
+ };
939
+ return createDecision(tree, queue.p, fallback);
940
+ }
941
+ function createErrorBoundary(fn, fallback) {
942
+ const owner = new Owner();
943
+ const error = new Computation(void 0, null);
944
+ const nodes = /* @__PURE__ */ new Set();
945
+ function handler(err, node) {
946
+ if (nodes.has(node))
947
+ return;
948
+ compute(
949
+ node,
950
+ () => onCleanup(() => {
951
+ nodes.delete(node);
952
+ if (!nodes.size)
953
+ error.write(void 0);
954
+ }),
955
+ null
956
+ );
957
+ nodes.add(node);
958
+ if (nodes.size === 1)
959
+ error.write({ G: err });
907
960
  }
908
- };
909
- function createSuspense(fn, fallback) {
910
- const queue = new SuspenseQueue();
911
- const tree = createBoundary(() => {
912
- const child = new Computation(null, fn);
913
- return new LiveComputation(null, () => flatten(child.wait()));
914
- }, queue);
915
- const equality = new Computation(null, () => queue.T.read() || queue.o);
916
- const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
917
- return comp.read.bind(comp);
961
+ owner.addErrorHandler(handler);
962
+ const tree = createBoundary(owner, fn);
963
+ tree.H = tree.handleError;
964
+ return createDecision(
965
+ tree,
966
+ error,
967
+ () => fallback(error.read().G, () => {
968
+ incrementClock();
969
+ for (let node of nodes) {
970
+ node.a = STATE_DIRTY;
971
+ node.h?.enqueue(node.u, node);
972
+ }
973
+ })
974
+ );
918
975
  }
919
976
 
920
977
  // src/signals.ts
@@ -942,77 +999,64 @@ function createMemo(compute2, value, options) {
942
999
  let resolvedValue;
943
1000
  return () => {
944
1001
  if (node) {
1002
+ if (node.a === STATE_DISPOSED) {
1003
+ node = void 0;
1004
+ return resolvedValue;
1005
+ }
945
1006
  resolvedValue = node.wait();
946
- if (!node.b?.length && node.n?.t !== node) {
1007
+ if (!node.c?.length && node.l?.x !== node) {
947
1008
  node.dispose();
948
1009
  node = void 0;
949
- } else if (!node.t && !node.e?.length) {
950
- node.dispose();
951
- node.a = STATE_DIRTY;
952
1010
  }
953
1011
  }
954
1012
  return resolvedValue;
955
1013
  };
956
1014
  }
957
1015
  function createAsync(compute2, value, options) {
958
- let uninitialized = value === void 0;
959
- const lhs = new EagerComputation(
960
- {
961
- g: value
962
- },
1016
+ const node = new EagerComputation(
1017
+ value,
963
1018
  (p) => {
964
- const value2 = p?.g;
965
- const source = compute2(value2);
1019
+ const source = compute2(p);
966
1020
  const isPromise = source instanceof Promise;
967
1021
  const iterator = source[Symbol.asyncIterator];
968
1022
  if (!isPromise && !iterator) {
969
- return {
970
- wait() {
971
- return source;
972
- },
973
- g: source
974
- };
1023
+ return source;
975
1024
  }
976
- const signal = new Computation(value2, null, options);
977
- const w = signal.wait;
978
- signal.wait = function() {
979
- if (signal.f & ERROR_BIT && signal.y <= getClock()) {
980
- lhs.q(STATE_DIRTY);
981
- throw new NotReadyError();
982
- }
983
- return w.call(this);
984
- };
985
- signal.write(UNCHANGED, LOADING_BIT | (uninitialized ? UNINITIALIZED_BIT : 0));
1025
+ let abort = false;
1026
+ onCleanup(() => abort = true);
986
1027
  if (isPromise) {
987
1028
  source.then(
988
1029
  (value3) => {
989
- uninitialized = false;
990
- signal.write(value3, 0, true);
1030
+ if (abort)
1031
+ return;
1032
+ node.write(value3, 0, true);
991
1033
  },
992
1034
  (error) => {
993
- uninitialized = true;
994
- signal.H(error);
1035
+ if (abort)
1036
+ return;
1037
+ node.H(error);
995
1038
  }
996
1039
  );
997
1040
  } else {
998
- let abort = false;
999
- onCleanup(() => abort = true);
1000
1041
  (async () => {
1001
1042
  try {
1002
1043
  for await (let value3 of source) {
1003
1044
  if (abort)
1004
1045
  return;
1005
- signal.write(value3, 0, true);
1046
+ node.write(value3, 0, true);
1006
1047
  }
1007
1048
  } catch (error) {
1008
- signal.write(error, ERROR_BIT);
1049
+ if (abort)
1050
+ return;
1051
+ node.write(error, ERROR_BIT);
1009
1052
  }
1010
1053
  })();
1011
1054
  }
1012
- return signal;
1013
- }
1055
+ throw new NotReadyError();
1056
+ },
1057
+ options
1014
1058
  );
1015
- return () => lhs.wait().wait();
1059
+ return node.wait.bind(node);
1016
1060
  }
1017
1061
  function createEffect(compute2, effect, error, value, options) {
1018
1062
  void new Effect(
@@ -1029,62 +1073,13 @@ function createRenderEffect(compute2, effect, value, options) {
1029
1073
  ...options
1030
1074
  });
1031
1075
  }
1032
- function createRoot(init) {
1033
- const owner = new Owner();
1076
+ function createRoot(init, options) {
1077
+ const owner = new Owner(options?.id);
1034
1078
  return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
1035
1079
  }
1036
1080
  function runWithOwner(owner, run) {
1037
1081
  return compute(owner, run, null);
1038
1082
  }
1039
- function createErrorBoundary(fn, fallback) {
1040
- const owner = new Owner();
1041
- const error = new Computation(void 0, null);
1042
- const nodes = /* @__PURE__ */ new Set();
1043
- function handler(err, node) {
1044
- if (nodes.has(node))
1045
- return;
1046
- compute(
1047
- node,
1048
- () => onCleanup(() => {
1049
- nodes.delete(node);
1050
- if (!nodes.size)
1051
- error.write(void 0);
1052
- }),
1053
- null
1054
- );
1055
- nodes.add(node);
1056
- if (nodes.size === 1)
1057
- error.write({ G: err });
1058
- }
1059
- owner.m = owner.m ? [handler, ...owner.m] : [handler];
1060
- const guarded = compute(
1061
- owner,
1062
- () => {
1063
- const c = new Computation(void 0, fn);
1064
- const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
1065
- f.H = function(error2) {
1066
- this.handleError(error2);
1067
- };
1068
- return f;
1069
- },
1070
- null
1071
- );
1072
- const decision = new Computation(null, () => {
1073
- if (!error.read()) {
1074
- const resolved = guarded.read();
1075
- if (!error.read())
1076
- return resolved;
1077
- }
1078
- return fallback(error.read().G, () => {
1079
- incrementClock();
1080
- for (let node of nodes) {
1081
- node.a = STATE_DIRTY;
1082
- node.h?.enqueue(node.w, node);
1083
- }
1084
- });
1085
- });
1086
- return decision.read.bind(decision);
1087
- }
1088
1083
  function resolve(fn) {
1089
1084
  return new Promise((res, rej) => {
1090
1085
  createRoot((dispose) => {
@@ -1137,8 +1132,10 @@ function wrap(source, node, wrapped) {
1137
1132
  // src/store/store.ts
1138
1133
  var $RAW = Symbol(0);
1139
1134
  var $TRACK = Symbol(0);
1135
+ var $DEEP = Symbol(0);
1140
1136
  var $TARGET = Symbol(0);
1141
1137
  var $PROXY = Symbol(0);
1138
+ var PARENTS = /* @__PURE__ */ new WeakMap();
1142
1139
  var STORE_VALUE = "v";
1143
1140
  var STORE_NODE = "n";
1144
1141
  var STORE_HAS = "h";
@@ -1161,11 +1158,11 @@ function wrap2(value) {
1161
1158
  function isWrappable(obj) {
1162
1159
  return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
1163
1160
  }
1164
- function unwrap(item, deep = true, set) {
1161
+ function unwrap(item, deep2 = true, set) {
1165
1162
  let result, unwrapped, v, prop;
1166
1163
  if (result = item != null && item[$RAW])
1167
1164
  return result;
1168
- if (!deep)
1165
+ if (!deep2)
1169
1166
  return item;
1170
1167
  if (!isWrappable(item) || set?.has(item))
1171
1168
  return item;
@@ -1175,11 +1172,11 @@ function unwrap(item, deep = true, set) {
1175
1172
  if (Array.isArray(item)) {
1176
1173
  for (let i = 0, l = item.length; i < l; i++) {
1177
1174
  v = item[i];
1178
- if ((unwrapped = unwrap(v, deep, set)) !== v)
1175
+ if ((unwrapped = unwrap(v, deep2, set)) !== v)
1179
1176
  item[i] = unwrapped;
1180
1177
  }
1181
1178
  } else {
1182
- if (!deep)
1179
+ if (!deep2)
1183
1180
  return item;
1184
1181
  const keys = Object.keys(item);
1185
1182
  for (let i = 0, l = keys.length; i < l; i++) {
@@ -1188,7 +1185,7 @@ function unwrap(item, deep = true, set) {
1188
1185
  if (desc.get)
1189
1186
  continue;
1190
1187
  v = item[prop];
1191
- if ((unwrapped = unwrap(v, deep, set)) !== v)
1188
+ if ((unwrapped = unwrap(v, deep2, set)) !== v)
1192
1189
  item[prop] = unwrapped;
1193
1190
  }
1194
1191
  }
@@ -1221,8 +1218,8 @@ function proxyDescriptor(target, property) {
1221
1218
  desc.get = () => target[STORE_VALUE][$PROXY][property];
1222
1219
  return desc;
1223
1220
  }
1224
- function trackSelf(target) {
1225
- getObserver() && getNode(getNodes(target, STORE_NODE), $TRACK, void 0, false).read();
1221
+ function trackSelf(target, symbol = $TRACK) {
1222
+ getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
1226
1223
  }
1227
1224
  function ownKeys(target) {
1228
1225
  trackSelf(target);
@@ -1237,8 +1234,8 @@ var proxyTraps = {
1237
1234
  return target[STORE_VALUE];
1238
1235
  if (property === $PROXY)
1239
1236
  return receiver;
1240
- if (property === $TRACK) {
1241
- trackSelf(target);
1237
+ if (property === $TRACK || property === $DEEP) {
1238
+ trackSelf(target, property);
1242
1239
  return receiver;
1243
1240
  }
1244
1241
  const nodes = getNodes(target, STORE_NODE);
@@ -1259,7 +1256,7 @@ var proxyTraps = {
1259
1256
  let proto;
1260
1257
  return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
1261
1258
  } else if (getObserver()) {
1262
- value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
1259
+ return getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
1263
1260
  }
1264
1261
  }
1265
1262
  return isWrappable(value) ? wrap2(value) : value;
@@ -1294,6 +1291,13 @@ function setProperty(state, property, value, deleting = false) {
1294
1291
  delete state[property];
1295
1292
  else
1296
1293
  state[property] = value;
1294
+ const wrappable = isWrappable(value);
1295
+ if (isWrappable(prev)) {
1296
+ const parents = PARENTS.get(prev);
1297
+ parents && (parents instanceof Set ? parents.delete(state) : PARENTS.delete(prev));
1298
+ }
1299
+ if (recursivelyNotify(state) && wrappable)
1300
+ recursivelyAddParent(value[$RAW] || value, state);
1297
1301
  const target = state[$PROXY]?.[$TARGET];
1298
1302
  if (!target)
1299
1303
  return;
@@ -1302,15 +1306,54 @@ function setProperty(state, property, value, deleting = false) {
1302
1306
  else
1303
1307
  target[STORE_HAS]?.[property]?.write(true);
1304
1308
  const nodes = getNodes(target, STORE_NODE);
1305
- let node;
1306
- if (node = nodes[property])
1307
- node.write(isWrappable(value) ? wrap2(value) : value);
1308
- Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
1309
- (node = nodes[$TRACK]) && node.write(void 0);
1309
+ nodes[property]?.write(wrappable ? wrap2(value) : value);
1310
+ Array.isArray(state) && state.length !== len && nodes.length?.write(state.length);
1311
+ nodes[$TRACK]?.write(void 0);
1312
+ }
1313
+ function recursivelyNotify(state) {
1314
+ let target = state[$PROXY]?.[$TARGET];
1315
+ let notified = false;
1316
+ target && (getNodes(target, STORE_NODE)[$DEEP]?.write(void 0), notified = true);
1317
+ const parents = PARENTS.get(state);
1318
+ if (!parents)
1319
+ return notified;
1320
+ if (parents instanceof Set) {
1321
+ for (let parent of parents)
1322
+ notified = recursivelyNotify(parent) || notified;
1323
+ } else
1324
+ notified = recursivelyNotify(parents) || notified;
1325
+ return notified;
1326
+ }
1327
+ function recursivelyAddParent(state, parent) {
1328
+ if (parent) {
1329
+ let parents = PARENTS.get(state);
1330
+ if (!parents)
1331
+ PARENTS.set(state, parent);
1332
+ else if (parents !== parent) {
1333
+ if (!(parents instanceof Set))
1334
+ PARENTS.set(state, parents = /* @__PURE__ */ new Set([parents]));
1335
+ else if (parents.has(parent))
1336
+ return;
1337
+ parents.add(parent);
1338
+ } else
1339
+ return;
1340
+ }
1341
+ if (Array.isArray(state)) {
1342
+ for (let i = 0; i < state.length; i++) {
1343
+ const item = state[i];
1344
+ isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
1345
+ }
1346
+ } else {
1347
+ const keys = Object.keys(state);
1348
+ for (let i = 0; i < keys.length; i++) {
1349
+ const item = state[keys[i]];
1350
+ isWrappable(item) && recursivelyAddParent(item[$RAW] || item, state);
1351
+ }
1352
+ }
1310
1353
  }
1311
1354
  function createStore(first, second) {
1312
1355
  const derived = typeof first === "function", store = derived ? second : first;
1313
- const unwrappedStore = unwrap(store, false);
1356
+ const unwrappedStore = unwrap(store);
1314
1357
  let wrappedStore = wrap2(unwrappedStore);
1315
1358
  const setStore = (fn) => {
1316
1359
  try {
@@ -1324,6 +1367,10 @@ function createStore(first, second) {
1324
1367
  return wrapProjection(first, wrappedStore, setStore);
1325
1368
  return [wrappedStore, setStore];
1326
1369
  }
1370
+ function deep(store) {
1371
+ recursivelyAddParent(store[$RAW] || store);
1372
+ return store[$DEEP];
1373
+ }
1327
1374
 
1328
1375
  // src/store/reconcile.ts
1329
1376
  function applyState(next, state, keyFn) {
@@ -1592,14 +1639,14 @@ function mapArray(list, map, options) {
1592
1639
  I: new Owner(),
1593
1640
  i: 0,
1594
1641
  Y: list,
1595
- x: [],
1642
+ w: [],
1596
1643
  D: map,
1597
- d: [],
1598
- c: [],
1644
+ e: [],
1645
+ b: [],
1599
1646
  E: keyFn,
1600
1647
  j: keyFn || options?.keyed === false ? [] : void 0,
1601
1648
  k: map.length > 1 ? [] : void 0,
1602
- o: options?.fallback
1649
+ p: options?.fallback
1603
1650
  });
1604
1651
  }
1605
1652
  function updateKeyedMap() {
@@ -1624,38 +1671,38 @@ function updateKeyedMap() {
1624
1671
  if (newLen === 0) {
1625
1672
  if (this.i !== 0) {
1626
1673
  this.I.dispose(false);
1627
- this.c = [];
1628
- this.x = [];
1629
- this.d = [];
1674
+ this.b = [];
1675
+ this.w = [];
1676
+ this.e = [];
1630
1677
  this.i = 0;
1631
1678
  this.j && (this.j = []);
1632
1679
  this.k && (this.k = []);
1633
1680
  }
1634
- if (this.o && !this.d[0]) {
1635
- this.d[0] = compute(
1636
- this.c[0] = new Owner(),
1637
- this.o,
1681
+ if (this.p && !this.e[0]) {
1682
+ this.e[0] = compute(
1683
+ this.b[0] = new Owner(),
1684
+ this.p,
1638
1685
  null
1639
1686
  );
1640
1687
  }
1641
1688
  } else if (this.i === 0) {
1642
- if (this.c[0])
1643
- this.c[0].dispose();
1644
- this.d = new Array(newLen);
1689
+ if (this.b[0])
1690
+ this.b[0].dispose();
1691
+ this.e = new Array(newLen);
1645
1692
  for (j = 0; j < newLen; j++) {
1646
- this.x[j] = newItems[j];
1647
- this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
1693
+ this.w[j] = newItems[j];
1694
+ this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1648
1695
  }
1649
1696
  this.i = newLen;
1650
1697
  } else {
1651
1698
  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;
1652
- for (start = 0, end = Math.min(this.i, newLen); start < end && (this.x[start] === newItems[start] || this.j && compare(this.E, this.x[start], newItems[start])); start++) {
1699
+ for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.E, this.w[start], newItems[start])); start++) {
1653
1700
  if (this.j)
1654
1701
  this.j[start].write(newItems[start]);
1655
1702
  }
1656
- for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.x[end] === newItems[newEnd] || this.j && compare(this.E, this.x[end], newItems[newEnd])); end--, newEnd--) {
1657
- temp[newEnd] = this.d[end];
1658
- tempNodes[newEnd] = this.c[end];
1703
+ for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.E, this.w[end], newItems[newEnd])); end--, newEnd--) {
1704
+ temp[newEnd] = this.e[end];
1705
+ tempNodes[newEnd] = this.b[end];
1659
1706
  tempRows && (tempRows[newEnd] = this.j[end]);
1660
1707
  tempIndexes && (tempIndexes[newEnd] = this.k[end]);
1661
1708
  }
@@ -1669,23 +1716,23 @@ function updateKeyedMap() {
1669
1716
  newIndices.set(key, j);
1670
1717
  }
1671
1718
  for (i = start; i <= end; i++) {
1672
- item = this.x[i];
1719
+ item = this.w[i];
1673
1720
  key = this.E ? this.E(item) : item;
1674
1721
  j = newIndices.get(key);
1675
1722
  if (j !== void 0 && j !== -1) {
1676
- temp[j] = this.d[i];
1677
- tempNodes[j] = this.c[i];
1723
+ temp[j] = this.e[i];
1724
+ tempNodes[j] = this.b[i];
1678
1725
  tempRows && (tempRows[j] = this.j[i]);
1679
1726
  tempIndexes && (tempIndexes[j] = this.k[i]);
1680
1727
  j = newIndicesNext[j];
1681
1728
  newIndices.set(key, j);
1682
1729
  } else
1683
- this.c[i].dispose();
1730
+ this.b[i].dispose();
1684
1731
  }
1685
1732
  for (j = start; j < newLen; j++) {
1686
1733
  if (j in temp) {
1687
- this.d[j] = temp[j];
1688
- this.c[j] = tempNodes[j];
1734
+ this.e[j] = temp[j];
1735
+ this.b[j] = tempNodes[j];
1689
1736
  if (tempRows) {
1690
1737
  this.j[j] = tempRows[j];
1691
1738
  this.j[j].write(newItems[j]);
@@ -1695,26 +1742,26 @@ function updateKeyedMap() {
1695
1742
  this.k[j].write(j);
1696
1743
  }
1697
1744
  } else {
1698
- this.d[j] = compute(this.c[j] = new Owner(), mapper, null);
1745
+ this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
1699
1746
  }
1700
1747
  }
1701
- this.d = this.d.slice(0, this.i = newLen);
1702
- this.x = newItems.slice(0);
1748
+ this.e = this.e.slice(0, this.i = newLen);
1749
+ this.w = newItems.slice(0);
1703
1750
  }
1704
1751
  });
1705
- return this.d;
1752
+ return this.e;
1706
1753
  }
1707
1754
  function repeat(count, map, options) {
1708
1755
  return updateRepeat.bind({
1709
1756
  I: new Owner(),
1710
1757
  i: 0,
1711
- r: 0,
1758
+ q: 0,
1712
1759
  Z: count,
1713
1760
  D: map,
1714
- c: [],
1715
- d: [],
1761
+ b: [],
1762
+ e: [],
1716
1763
  _: options?.from,
1717
- o: options?.fallback
1764
+ p: options?.fallback
1718
1765
  });
1719
1766
  }
1720
1767
  function updateRepeat() {
@@ -1724,63 +1771,63 @@ function updateRepeat() {
1724
1771
  if (newLen === 0) {
1725
1772
  if (this.i !== 0) {
1726
1773
  this.I.dispose(false);
1727
- this.c = [];
1728
- this.d = [];
1774
+ this.b = [];
1775
+ this.e = [];
1729
1776
  this.i = 0;
1730
1777
  }
1731
- if (this.o && !this.d[0]) {
1732
- this.d[0] = compute(
1733
- this.c[0] = new Owner(),
1734
- this.o,
1778
+ if (this.p && !this.e[0]) {
1779
+ this.e[0] = compute(
1780
+ this.b[0] = new Owner(),
1781
+ this.p,
1735
1782
  null
1736
1783
  );
1737
1784
  }
1738
1785
  return;
1739
1786
  }
1740
1787
  const to = from + newLen;
1741
- const prevTo = this.r + this.i;
1742
- if (this.i === 0 && this.c[0])
1743
- this.c[0].dispose();
1788
+ const prevTo = this.q + this.i;
1789
+ if (this.i === 0 && this.b[0])
1790
+ this.b[0].dispose();
1744
1791
  for (let i = to; i < prevTo; i++)
1745
- this.c[i - this.r].dispose();
1746
- if (this.r < from) {
1747
- let i = this.r;
1792
+ this.b[i - this.q].dispose();
1793
+ if (this.q < from) {
1794
+ let i = this.q;
1748
1795
  while (i < from && i < this.i)
1749
- this.c[i++].dispose();
1750
- this.c.splice(0, from - this.r);
1751
- this.d.splice(0, from - this.r);
1752
- } else if (this.r > from) {
1753
- let i = prevTo - this.r - 1;
1754
- let difference = this.r - from;
1755
- this.c.length = this.d.length = newLen;
1796
+ this.b[i++].dispose();
1797
+ this.b.splice(0, from - this.q);
1798
+ this.e.splice(0, from - this.q);
1799
+ } else if (this.q > from) {
1800
+ let i = prevTo - this.q - 1;
1801
+ let difference = this.q - from;
1802
+ this.b.length = this.e.length = newLen;
1756
1803
  while (i >= difference) {
1757
- this.c[i] = this.c[i - difference];
1758
- this.d[i] = this.d[i - difference];
1804
+ this.b[i] = this.b[i - difference];
1805
+ this.e[i] = this.e[i - difference];
1759
1806
  i--;
1760
1807
  }
1761
1808
  for (let i2 = 0; i2 < difference; i2++) {
1762
- this.d[i2] = compute(
1763
- this.c[i2] = new Owner(),
1809
+ this.e[i2] = compute(
1810
+ this.b[i2] = new Owner(),
1764
1811
  () => this.D(i2 + from),
1765
1812
  null
1766
1813
  );
1767
1814
  }
1768
1815
  }
1769
1816
  for (let i = prevTo; i < to; i++) {
1770
- this.d[i - from] = compute(
1771
- this.c[i - from] = new Owner(),
1817
+ this.e[i - from] = compute(
1818
+ this.b[i - from] = new Owner(),
1772
1819
  () => this.D(i),
1773
1820
  null
1774
1821
  );
1775
1822
  }
1776
- this.d = this.d.slice(0, newLen);
1777
- this.r = from;
1823
+ this.e = this.e.slice(0, newLen);
1824
+ this.q = from;
1778
1825
  this.i = newLen;
1779
1826
  });
1780
- return this.d;
1827
+ return this.e;
1781
1828
  }
1782
1829
  function compare(key, a, b) {
1783
1830
  return key ? key(a) === key(b) : true;
1784
1831
  }
1785
1832
 
1786
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, 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, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
1833
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, tryCatch, untrack, unwrap };