@solidjs/signals 0.9.4 → 0.9.6

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
@@ -23,12 +23,14 @@ const REACTIVE_IN_HEAP = 1 << 3;
23
23
  const REACTIVE_IN_HEAP_HEIGHT = 1 << 4;
24
24
  const REACTIVE_ZOMBIE = 1 << 5;
25
25
  const REACTIVE_DISPOSED = 1 << 6;
26
+ const REACTIVE_OPTIMISTIC_DIRTY = 1 << 7;
26
27
  const STATUS_NONE = 0;
27
28
  const STATUS_PENDING = 1 << 0;
28
29
  const STATUS_ERROR = 1 << 1;
29
30
  const STATUS_UNINITIALIZED = 1 << 2;
30
31
  const EFFECT_RENDER = 1;
31
32
  const EFFECT_USER = 2;
33
+ const EFFECT_TRACKED = 3;
32
34
  const NOT_PENDING = {};
33
35
  const SUPPORTS_PROXY = typeof Proxy === "function";
34
36
  const defaultContext = {};
@@ -45,7 +47,7 @@ function actualInsertIntoHeap(e, t) {
45
47
  e.T = t;
46
48
  r.T = e;
47
49
  }
48
- if (i > t.h) t.h = i;
50
+ if (i > t.O) t.O = i;
49
51
  }
50
52
  function insertIntoHeap(e, t) {
51
53
  let n = e.S;
@@ -70,10 +72,10 @@ function deleteFromHeap(e, t) {
70
72
  else {
71
73
  const n = e.R;
72
74
  const r = t.l[i];
73
- const s = n ?? r;
75
+ const o = n ?? r;
74
76
  if (e === r) t.l[i] = n;
75
77
  else e.T.R = n;
76
- s.T = e.T;
78
+ o.T = e.T;
77
79
  }
78
80
  e.T = e;
79
81
  e.R = undefined;
@@ -81,7 +83,7 @@ function deleteFromHeap(e, t) {
81
83
  function markHeap(e) {
82
84
  if (e._) return;
83
85
  e._ = true;
84
- for (let t = 0; t <= e.h; t++) {
86
+ for (let t = 0; t <= e.O; t++) {
85
87
  for (let n = e.l[t]; n !== undefined; n = n.R) {
86
88
  if (n.S & REACTIVE_IN_HEAP) markNode(n);
87
89
  }
@@ -91,69 +93,77 @@ function markNode(e, t = REACTIVE_DIRTY) {
91
93
  const n = e.S;
92
94
  if ((n & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
93
95
  e.S = (n & -4) | t;
94
- for (let t = e.O; t !== null; t = t.p) {
95
- markNode(t.A, REACTIVE_CHECK);
96
+ for (let t = e.p; t !== null; t = t.I) {
97
+ markNode(t.h, REACTIVE_CHECK);
96
98
  }
97
- if (e.N !== null) {
98
- for (let t = e.N; t !== null; t = t.I) {
99
- for (let e = t.O; e !== null; e = e.p) {
100
- markNode(e.A, REACTIVE_CHECK);
99
+ if (e.A !== null) {
100
+ for (let t = e.A; t !== null; t = t.P) {
101
+ for (let e = t.p; e !== null; e = e.I) {
102
+ markNode(e.h, REACTIVE_CHECK);
101
103
  }
102
104
  }
103
105
  }
104
106
  }
105
107
  function runHeap(e, t) {
106
108
  e._ = false;
107
- for (e.C = 0; e.C <= e.h; e.C++) {
108
- let n = e.l[e.C];
109
+ for (e.N = 0; e.N <= e.O; e.N++) {
110
+ let n = e.l[e.N];
109
111
  while (n !== undefined) {
110
112
  if (n.S & REACTIVE_IN_HEAP) t(n);
111
113
  else adjustHeight(n, e);
112
- n = e.l[e.C];
114
+ n = e.l[e.N];
113
115
  }
114
116
  }
115
- e.h = 0;
117
+ e.O = 0;
116
118
  }
117
119
  function adjustHeight(e, t) {
118
120
  deleteFromHeap(e, t);
119
121
  let n = e.o;
120
- for (let t = e.D; t; t = t.P) {
122
+ for (let t = e.C; t; t = t.D) {
121
123
  const e = t.V;
122
124
  const i = e.m || e;
123
125
  if (i.U && i.o >= n) n = i.o + 1;
124
126
  }
125
127
  if (e.o !== n) {
126
128
  e.o = n;
127
- for (let n = e.O; n !== null; n = n.p) {
128
- insertIntoHeapHeight(n.A, t);
129
+ for (let n = e.p; n !== null; n = n.I) {
130
+ insertIntoHeapHeight(n.h, t);
129
131
  }
130
132
  }
131
133
  }
132
134
  const transitions = new Set();
133
- let optimisticRun = false;
134
- const dirtyQueue = { l: new Array(2e3).fill(undefined), _: false, C: 0, h: 0 };
135
- const zombieQueue = { l: new Array(2e3).fill(undefined), _: false, C: 0, h: 0 };
135
+ const dirtyQueue = { l: new Array(2e3).fill(undefined), _: false, N: 0, O: 0 };
136
+ const zombieQueue = { l: new Array(2e3).fill(undefined), _: false, N: 0, O: 0 };
136
137
  let clock = 0;
137
138
  let activeTransition = null;
138
139
  let scheduled = false;
140
+ let optimisticReadActive = false;
141
+ let projectionWriteActive = false;
142
+ function setOptimisticReadActive(e) {
143
+ optimisticReadActive = e;
144
+ }
145
+ function setProjectionWriteActive(e) {
146
+ projectionWriteActive = e;
147
+ }
139
148
  function schedule() {
140
149
  if (scheduled) return;
141
150
  scheduled = true;
142
- if (!globalQueue.k) Promise.resolve().then(() => queueMicrotask(flush));
151
+ if (!globalQueue.k) queueMicrotask(flush);
143
152
  }
144
153
  class Queue {
145
154
  i = null;
155
+ W = [[], []];
146
156
  G = [[], []];
147
- H = [];
157
+ M = [];
148
158
  created = clock;
149
159
  addChild(e) {
150
- this.H.push(e);
160
+ this.M.push(e);
151
161
  e.i = this;
152
162
  }
153
163
  removeChild(e) {
154
- const t = this.H.indexOf(e);
164
+ const t = this.M.indexOf(e);
155
165
  if (t >= 0) {
156
- this.H.splice(t, 1);
166
+ this.M.splice(t, 1);
157
167
  e.i = null;
158
168
  }
159
169
  }
@@ -161,40 +171,49 @@ class Queue {
161
171
  if (this.i) return this.i.notify(e, t, n);
162
172
  return false;
163
173
  }
164
- run(e) {
165
- if (this.G[e - 1].length) {
166
- const t = this.G[e - 1];
167
- this.G[e - 1] = [];
168
- runQueue(t, e);
174
+ $(e, t, n) {
175
+ if (t[e - 1].length) {
176
+ const n = t[e - 1];
177
+ t[e - 1] = [];
178
+ runQueue(n, e);
169
179
  }
170
- for (let t = 0; t < this.H.length; t++) {
171
- this.H[t].run(e);
180
+ for (let t = 0; t < this.M.length; t++) {
181
+ this.M[t][n]?.(e);
172
182
  }
173
183
  }
184
+ run(e) {
185
+ this.$(e, this.W, "run");
186
+ }
187
+ runOptimistic(e) {
188
+ this.$(e, this.G, "runOptimistic");
189
+ }
174
190
  enqueue(e, t) {
175
- if (e) this.G[e - 1].push(t);
191
+ if (e) {
192
+ const n = optimisticReadActive ? this.G : this.W;
193
+ n[e - 1].push(t);
194
+ }
176
195
  schedule();
177
196
  }
178
197
  stashQueues(e) {
179
- e.G[0].push(...this.G[0]);
180
- e.G[1].push(...this.G[1]);
181
- this.G = [[], []];
182
- for (let t = 0; t < this.H.length; t++) {
183
- let n = this.H[t];
184
- let i = e.H[t];
198
+ e.W[0].push(...this.W[0]);
199
+ e.W[1].push(...this.W[1]);
200
+ this.W = [[], []];
201
+ for (let t = 0; t < this.M.length; t++) {
202
+ let n = this.M[t];
203
+ let i = e.M[t];
185
204
  if (!i) {
186
- i = { G: [[], []], H: [] };
187
- e.H[t] = i;
205
+ i = { W: [[], []], M: [] };
206
+ e.M[t] = i;
188
207
  }
189
208
  n.stashQueues(i);
190
209
  }
191
210
  }
192
211
  restoreQueues(e) {
193
- this.G[0].push(...e.G[0]);
194
- this.G[1].push(...e.G[1]);
195
- for (let t = 0; t < e.H.length; t++) {
196
- const n = e.H[t];
197
- let i = this.H[t];
212
+ this.W[0].push(...e.W[0]);
213
+ this.W[1].push(...e.W[1]);
214
+ for (let t = 0; t < e.M.length; t++) {
215
+ const n = e.M[t];
216
+ let i = this.M[t];
198
217
  if (i) i.restoreQueues(n);
199
218
  }
200
219
  }
@@ -202,39 +221,50 @@ class Queue {
202
221
  class GlobalQueue extends Queue {
203
222
  k = false;
204
223
  L = [];
205
- $ = [];
206
- static F;
207
- static W;
224
+ H = [];
225
+ F = new Set();
226
+ static j;
227
+ static K;
228
+ static Y = null;
208
229
  flush() {
209
230
  if (this.k) return;
210
231
  this.k = true;
211
232
  try {
212
- runHeap(dirtyQueue, GlobalQueue.F);
233
+ runHeap(dirtyQueue, GlobalQueue.j);
213
234
  if (activeTransition) {
214
- if (!transitionComplete(activeTransition)) {
235
+ const e = transitionComplete(activeTransition);
236
+ if (!e) {
215
237
  let e = activeTransition;
216
- runHeap(zombieQueue, GlobalQueue.F);
238
+ runHeap(zombieQueue, GlobalQueue.j);
217
239
  this.L = [];
240
+ this.H = [];
241
+ this.F = new Set();
242
+ this.runOptimistic(EFFECT_RENDER);
243
+ this.runOptimistic(EFFECT_USER);
218
244
  this.stashQueues(activeTransition.queueStash);
219
245
  clock++;
220
246
  scheduled = false;
221
- runTransitionPending(activeTransition.pendingNodes, true);
247
+ runTransitionPending(activeTransition.pendingNodes);
222
248
  activeTransition = null;
223
- runOptimistic(e);
249
+ finalizePureQueue(null, true);
224
250
  return;
225
251
  }
226
- this.L.push(...activeTransition.pendingNodes);
227
- this.$ !== activeTransition.optimisticNodes &&
228
- this.$.push(...activeTransition.optimisticNodes);
252
+ this.L !== activeTransition.pendingNodes && this.L.push(...activeTransition.pendingNodes);
229
253
  this.restoreQueues(activeTransition.queueStash);
230
254
  transitions.delete(activeTransition);
255
+ const t = activeTransition;
231
256
  activeTransition = null;
232
- runTransitionPending(this.L, false);
233
- } else if (transitions.size) runHeap(zombieQueue, GlobalQueue.F);
234
- runOptimistic();
257
+ runTransitionPending(this.L);
258
+ finalizePureQueue(t);
259
+ } else {
260
+ if (transitions.size) runHeap(zombieQueue, GlobalQueue.j);
261
+ finalizePureQueue();
262
+ }
235
263
  clock++;
236
- scheduled = false;
264
+ scheduled = dirtyQueue.O >= dirtyQueue.N;
265
+ this.runOptimistic(EFFECT_RENDER);
237
266
  this.run(EFFECT_RENDER);
267
+ this.runOptimistic(EFFECT_USER);
238
268
  this.run(EFFECT_USER);
239
269
  } finally {
240
270
  this.k = false;
@@ -243,8 +273,8 @@ class GlobalQueue extends Queue {
243
273
  notify(e, t, n) {
244
274
  if (t & STATUS_PENDING) {
245
275
  if (n & STATUS_PENDING) {
246
- if (activeTransition && !activeTransition.asyncNodes.includes(e.j.cause)) {
247
- activeTransition.asyncNodes.push(e.j.cause);
276
+ if (activeTransition && e.B && !activeTransition.asyncNodes.includes(e.B.cause)) {
277
+ activeTransition.asyncNodes.push(e.B.cause);
248
278
  schedule();
249
279
  }
250
280
  }
@@ -253,80 +283,109 @@ class GlobalQueue extends Queue {
253
283
  return false;
254
284
  }
255
285
  initTransition(e) {
256
- if (activeTransition && activeTransition.time === clock) return;
286
+ if (e) e = currentTransition(e);
287
+ if (e && e === activeTransition) return;
288
+ if (!e && activeTransition && activeTransition.time === clock) return;
257
289
  if (!activeTransition) {
258
- activeTransition = e?.K ?? {
290
+ activeTransition = e ?? {
259
291
  time: clock,
260
292
  pendingNodes: [],
261
293
  asyncNodes: [],
262
294
  optimisticNodes: [],
295
+ optimisticStores: new Set(),
263
296
  actions: [],
264
- queueStash: { G: [[], []], H: [] },
297
+ queueStash: { W: [[], []], M: [] },
265
298
  done: false
266
299
  };
300
+ } else if (e) {
301
+ activeTransition.done = e;
302
+ e.actions.push(...activeTransition.actions);
303
+ transitions.delete(activeTransition);
304
+ activeTransition = e;
267
305
  }
268
306
  transitions.add(activeTransition);
269
307
  activeTransition.time = clock;
270
308
  for (let e = 0; e < this.L.length; e++) {
271
309
  const t = this.L[e];
272
- t.K = activeTransition;
310
+ t.X = activeTransition;
273
311
  activeTransition.pendingNodes.push(t);
274
312
  }
275
- for (let e = 0; e < this.$.length; e++) {
276
- const t = this.$[e];
277
- t.K = activeTransition;
313
+ this.L = activeTransition.pendingNodes;
314
+ for (let e = 0; e < this.H.length; e++) {
315
+ const t = this.H[e];
316
+ t.X = activeTransition;
278
317
  activeTransition.optimisticNodes.push(t);
279
318
  }
280
- this.L = activeTransition.pendingNodes;
281
- this.$ = activeTransition.optimisticNodes;
282
- }
283
- }
284
- function notifySubs(e) {
285
- for (let t = e.O; t !== null; t = t.p) {
286
- const e = t.A.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
287
- if (e.C > t.A.o) e.C = t.A.o;
288
- insertIntoHeap(t.A, e);
319
+ this.H = activeTransition.optimisticNodes;
320
+ for (const e of this.F) {
321
+ activeTransition.optimisticStores.add(e);
322
+ }
323
+ this.F = activeTransition.optimisticStores;
289
324
  }
290
325
  }
291
- function runOptimistic(e = null) {
292
- let t = !e;
293
- const n = globalQueue.$;
294
- optimisticRun = true;
295
- for (let t = 0; t < n.length; t++) {
296
- const i = n[t];
297
- if (!e && (!i.K || i.K.done) && i.M !== NOT_PENDING) {
298
- i.Y = i.M;
299
- i.M = NOT_PENDING;
326
+ function insertSubs(e, t = false) {
327
+ for (let n = e.p; n !== null; n = n.I) {
328
+ if (t) n.h.S |= REACTIVE_OPTIMISTIC_DIRTY;
329
+ const e = n.h;
330
+ if (e.q === EFFECT_TRACKED) {
331
+ if (!e.Z) {
332
+ e.Z = true;
333
+ e.J.enqueue(EFFECT_USER, e.ee);
334
+ }
335
+ continue;
300
336
  }
301
- i.K = e;
302
- notifySubs(i);
303
- }
304
- globalQueue.$ = [];
305
- if (dirtyQueue.h >= dirtyQueue.C) {
306
- t = true;
307
- runHeap(dirtyQueue, GlobalQueue.F);
337
+ const i = n.h.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
338
+ if (i.N > n.h.o) i.N = n.h.o;
339
+ insertIntoHeap(n.h, i);
308
340
  }
309
- optimisticRun = false;
310
- t && runPending(globalQueue.L);
311
341
  }
312
- function runPending(e) {
313
- for (let t = 0; t < e.length; t++) {
314
- const n = e[t];
315
- if (n.M !== NOT_PENDING) {
316
- n.Y = n.M;
317
- n.M = NOT_PENDING;
318
- if (n.B) n.X = true;
342
+ function finalizePureQueue(e = null, t = false) {
343
+ let n = !t;
344
+ if (dirtyQueue.O >= dirtyQueue.N) {
345
+ n = true;
346
+ runHeap(dirtyQueue, GlobalQueue.j);
347
+ }
348
+ if (n) {
349
+ const t = globalQueue.L;
350
+ for (let e = 0; e < t.length; e++) {
351
+ const n = t[e];
352
+ if (n.te !== NOT_PENDING) {
353
+ n.ne = n.te;
354
+ n.te = NOT_PENDING;
355
+ if (n.q && n.q !== EFFECT_TRACKED) n.Z = true;
356
+ }
357
+ if (n.U) GlobalQueue.K(n, false, true);
358
+ }
359
+ t.length = 0;
360
+ const n = e ? e.optimisticNodes : globalQueue.H;
361
+ for (let e = 0; e < n.length; e++) {
362
+ const t = n[e];
363
+ const i = t.te;
364
+ if (i !== NOT_PENDING && t.ne !== i) {
365
+ t.ne = i;
366
+ insertSubs(t, true);
367
+ }
368
+ t.te = NOT_PENDING;
369
+ t.X = null;
370
+ }
371
+ n.length = 0;
372
+ const i = e ? e.optimisticStores : globalQueue.F;
373
+ if (GlobalQueue.Y && i.size) {
374
+ for (const e of i) {
375
+ GlobalQueue.Y(e);
376
+ }
377
+ i.clear();
378
+ schedule();
319
379
  }
320
- if (n.U) GlobalQueue.W(n, false, true);
321
380
  }
322
- e.length = 0;
323
381
  }
324
- function runTransitionPending(e, t) {
325
- const n = e.slice();
326
- for (let e = 0; e < n.length; e++) {
327
- const i = n[e];
328
- i.K = activeTransition;
329
- if (i.q) i.q.Z(t);
382
+ function trackOptimisticStore(e) {
383
+ globalQueue.F.add(e);
384
+ schedule();
385
+ }
386
+ function runTransitionPending(e) {
387
+ for (let t = 0; t < e.length; t++) {
388
+ e[t].X = activeTransition;
330
389
  }
331
390
  }
332
391
  const globalQueue = new GlobalQueue();
@@ -343,7 +402,7 @@ function transitionComplete(e) {
343
402
  if (e.actions.length) return false;
344
403
  let t = true;
345
404
  for (let n = 0; n < e.asyncNodes.length; n++) {
346
- if (e.asyncNodes[n].J & STATUS_PENDING) {
405
+ if (e.asyncNodes[n].ie & STATUS_PENDING) {
347
406
  t = false;
348
407
  break;
349
408
  }
@@ -351,168 +410,271 @@ function transitionComplete(e) {
351
410
  t && (e.done = true);
352
411
  return t;
353
412
  }
413
+ function currentTransition(e) {
414
+ while (e.done && typeof e.done === "object") e = e.done;
415
+ return e;
416
+ }
354
417
  function runInTransition(e, t) {
355
418
  const n = activeTransition;
356
419
  try {
357
- activeTransition = e;
420
+ activeTransition = currentTransition(e);
358
421
  return t();
359
422
  } finally {
360
423
  activeTransition = n;
361
424
  }
362
425
  }
426
+ function restoreTransition(e, t) {
427
+ globalQueue.initTransition(e);
428
+ const n = t();
429
+ flush();
430
+ return n;
431
+ }
363
432
  function action(e) {
364
- return (...t) => {
365
- const n = e(...t);
366
- globalQueue.initTransition();
367
- let i = activeTransition;
368
- i.actions.push(n);
369
- const step = e => {
370
- let t = n.next(e);
371
- if (t instanceof Promise) return t.then(process);
372
- process(t);
373
- };
374
- const process = e => {
375
- if (e.done) {
376
- i.actions.splice(i.actions.indexOf(n), 1);
377
- activeTransition = i;
433
+ return (...t) =>
434
+ new Promise((n, i) => {
435
+ const r = e(...t);
436
+ globalQueue.initTransition();
437
+ let o = activeTransition;
438
+ o.actions.push(r);
439
+ const done = (e, t) => {
440
+ o = currentTransition(o);
441
+ const s = o.actions.indexOf(r);
442
+ if (s >= 0) o.actions.splice(s, 1);
443
+ activeTransition = o;
378
444
  schedule();
379
- flush();
380
- return;
381
- }
382
- const t = e.value;
383
- if (t instanceof Promise) return t.then(step);
384
- runInTransition(i, () => step(t));
385
- };
386
- runInTransition(i, () => step());
387
- };
445
+ t ? i(t) : n(e);
446
+ };
447
+ const step = (e, t) => {
448
+ let n;
449
+ try {
450
+ n = t ? r.throw(e) : r.next(e);
451
+ } catch (e) {
452
+ return done(undefined, e);
453
+ }
454
+ if (n instanceof Promise)
455
+ return void n.then(run, e => restoreTransition(o, () => step(e, true)));
456
+ run(n);
457
+ };
458
+ const run = e => {
459
+ if (e.done) return done(e.value);
460
+ if (e.value instanceof Promise)
461
+ return void e.value.then(
462
+ e => restoreTransition(o, () => step(e)),
463
+ e => restoreTransition(o, () => step(e, true))
464
+ );
465
+ restoreTransition(o, () => step(e.value));
466
+ };
467
+ step();
468
+ });
388
469
  }
389
- GlobalQueue.F = recompute;
390
- GlobalQueue.W = disposeChildren;
470
+ GlobalQueue.j = recompute;
471
+ GlobalQueue.K = disposeChildren;
391
472
  let tracking = false;
392
473
  let stale = false;
393
- let pendingValueCheck = false;
394
- let pendingCheck = null;
395
474
  let refreshing = false;
475
+ let pendingCheckActive = false;
476
+ let foundPending = false;
477
+ let pendingReadActive = false;
396
478
  let context = null;
397
479
  function recompute(e, t = false) {
398
- const n = e.B && e.K != activeTransition;
480
+ const n = e.q;
399
481
  if (!t) {
400
- if (e.K && activeTransition !== e.K && !n) globalQueue.initTransition(e);
482
+ if (e.X && (!n || activeTransition) && activeTransition !== e.X)
483
+ globalQueue.initTransition(e.X);
401
484
  deleteFromHeap(e, e.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
402
- if (e.K) disposeChildren(e);
485
+ if (e.X) disposeChildren(e);
403
486
  else {
404
487
  markDisposal(e);
405
- e.ee = e.te;
406
- e.ne = e.ie;
407
- e.te = null;
408
- e.ie = null;
488
+ e.re = e.oe;
489
+ e.se = e.ue;
490
+ e.oe = null;
491
+ e.ue = null;
409
492
  }
410
493
  }
411
- const i = context;
494
+ const i = !!(e.S & REACTIVE_OPTIMISTIC_DIRTY);
495
+ const r = e.le && e.te !== NOT_PENDING;
496
+ const o = context;
412
497
  context = e;
413
- e.re = null;
498
+ e.ce = null;
414
499
  e.S = REACTIVE_RECOMPUTING_DEPS;
415
- e.se = clock;
416
- let r = e.M === NOT_PENDING || (e.oe && e.K) ? e.Y : e.M;
417
- let s = e.o;
418
- let o = e.J;
419
- let u = e.j;
500
+ e.ae = clock;
501
+ let s = e.te === NOT_PENDING ? e.ne : e.te;
502
+ let u = e.o;
420
503
  let l = tracking;
421
- setStatusFlags(e, STATUS_NONE | (o & STATUS_UNINITIALIZED));
504
+ let c = optimisticReadActive;
422
505
  tracking = true;
506
+ if (i) setOptimisticReadActive(true);
423
507
  try {
424
- r = handleAsync(e, e.U(r));
425
- e.J &= ~STATUS_UNINITIALIZED;
508
+ s = handleAsync(e, e.U(s));
509
+ clearStatus(e);
426
510
  } catch (t) {
427
511
  if (t instanceof NotReadyError) {
428
512
  if (t.cause !== e) link(t.cause, e);
429
- setStatusFlags(e, (o & ~STATUS_ERROR) | STATUS_PENDING, t);
430
- } else setStatusFlags(e, STATUS_ERROR, t);
513
+ notifyStatus(e, STATUS_PENDING, t);
514
+ } else notifyStatus(e, STATUS_ERROR, t);
431
515
  } finally {
432
516
  tracking = l;
517
+ e.S = REACTIVE_NONE;
518
+ context = o;
433
519
  }
434
- e.S = REACTIVE_NONE;
435
- context = i;
436
- if (!(e.J & STATUS_PENDING)) {
437
- const t = e.re;
438
- let n = t !== null ? t.P : e.D;
439
- if (n !== null) {
520
+ if (!e.B) {
521
+ const o = e.ce;
522
+ let l = o !== null ? o.D : e.C;
523
+ if (l !== null) {
440
524
  do {
441
- n = unlinkSubs(n);
442
- } while (n !== null);
443
- if (t !== null) t.P = null;
444
- else e.D = null;
525
+ l = unlinkSubs(l);
526
+ } while (l !== null);
527
+ if (o !== null) o.D = null;
528
+ else e.C = null;
445
529
  }
446
- }
447
- const c = !e.ue || !e.ue(e.M === NOT_PENDING || (e.oe && e.K) || n ? e.Y : e.M, r);
448
- const a = e.J !== o || e.j !== u;
449
- e.le?.(a, o);
450
- if (c || a) {
530
+ const c = !e.fe || !e.fe(e.te === NOT_PENDING ? e.ne : e.te, s);
451
531
  if (c) {
452
- if (t || e.oe || n) e.Y = r;
453
- else e.M = r;
454
- if (e.ce) setSignal(e.ce, r);
455
- }
456
- (!e.oe || optimisticRun) && notifySubs(e);
457
- } else if (e.o != s) {
458
- for (let t = e.O; t !== null; t = t.p) {
459
- insertIntoHeapHeight(t.A, t.A.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
532
+ if (t || (n && activeTransition !== e.X) || i) e.ne = s;
533
+ else e.te = s;
534
+ insertSubs(e, i || r);
535
+ } else if (e.o != u) {
536
+ for (let t = e.p; t !== null; t = t.I) {
537
+ insertIntoHeapHeight(t.h, t.h.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
538
+ }
460
539
  }
461
540
  }
462
- e.oe && !optimisticRun && globalQueue.$.push(e);
463
- (!t || e.J & STATUS_PENDING) && !e.K && globalQueue.L.push(e);
464
- e.K && n && runInTransition(e.K, () => recompute(e));
541
+ setOptimisticReadActive(c);
542
+ (!t || e.ie & STATUS_PENDING) && !e.X && globalQueue.L.push(e);
543
+ e.X && n && activeTransition !== e.X && runInTransition(e.X, () => recompute(e));
465
544
  }
466
545
  function handleAsync(e, t, n) {
467
546
  const i = typeof t === "object" && t !== null;
468
- const r = i && t instanceof Promise;
469
- const s = i && untrack(() => t[Symbol.asyncIterator]);
470
- if (!r && !s) {
471
- e.ae = null;
547
+ const r = i && untrack(() => t[Symbol.asyncIterator]);
548
+ const o = !r && i && untrack(() => typeof t.then === "function");
549
+ if (!o && !r) {
550
+ e.Ee = null;
472
551
  return t;
473
552
  }
474
- e.ae = t;
475
- if (r) {
476
- t.then(i => {
477
- if (e.ae !== t) return;
478
- globalQueue.initTransition(e);
479
- n?.(i) ?? setSignal(e, () => i);
480
- flush();
481
- }).catch(n => {
482
- if (e.ae !== t) return;
483
- globalQueue.initTransition(e);
484
- setStatusFlags(e, STATUS_ERROR, n);
485
- e.se = clock;
486
- notifySubs(e);
553
+ e.Ee = t;
554
+ let s;
555
+ const handleError = n => {
556
+ if (e.Ee !== t) return;
557
+ globalQueue.initTransition(e.X);
558
+ if (n instanceof NotReadyError) {
559
+ if (n.cause !== e) link(n.cause, e);
560
+ notifyStatus(e, STATUS_PENDING, n);
561
+ } else notifyStatus(e, STATUS_ERROR, n);
562
+ e.ae = clock;
563
+ };
564
+ const asyncWrite = (i, r) => {
565
+ if (e.Ee !== t) return;
566
+ globalQueue.initTransition(e.X);
567
+ clearStatus(e);
568
+ if (n) n(i);
569
+ else if (e.le) {
570
+ const t = e.te !== NOT_PENDING;
571
+ if (e.U) e.te = i;
572
+ if (!t) {
573
+ e.ne = i;
574
+ insertSubs(e);
575
+ }
576
+ e.ae = clock;
487
577
  schedule();
488
- flush();
489
- });
578
+ } else setSignal(e, () => i);
579
+ flush();
580
+ r?.();
581
+ };
582
+ if (o) {
583
+ let n = false,
584
+ i = true;
585
+ t.then(
586
+ e => {
587
+ if (i) {
588
+ s = e;
589
+ n = true;
590
+ } else asyncWrite(e);
591
+ },
592
+ e => {
593
+ if (!i) handleError(e);
594
+ }
595
+ );
596
+ i = false;
597
+ if (!n) {
598
+ globalQueue.initTransition(e.X);
599
+ throw new NotReadyError(context);
600
+ }
601
+ }
602
+ if (r) {
603
+ const n = t[Symbol.asyncIterator]();
604
+ let i = false;
605
+ const iterate = () => {
606
+ let e,
607
+ t = false,
608
+ r = true;
609
+ n.next().then(
610
+ n => {
611
+ if (r) {
612
+ e = n;
613
+ t = true;
614
+ } else if (!n.done) asyncWrite(n.value, iterate);
615
+ },
616
+ e => {
617
+ if (!r) handleError(e);
618
+ }
619
+ );
620
+ r = false;
621
+ if (t && !e.done) {
622
+ s = e.value;
623
+ i = true;
624
+ return iterate();
625
+ }
626
+ return t && e.done;
627
+ };
628
+ const r = iterate();
629
+ if (!i && !r) {
630
+ globalQueue.initTransition(e.X);
631
+ throw new NotReadyError(context);
632
+ }
633
+ }
634
+ return s;
635
+ }
636
+ function clearStatus(e) {
637
+ e.ie = STATUS_NONE;
638
+ e.B = null;
639
+ updatePendingSignal(e);
640
+ if (e.Te) {
641
+ e.Te();
490
642
  } else {
491
- (async () => {
492
- try {
493
- for await (let i of t) {
494
- if (e.ae !== t) return;
495
- globalQueue.initTransition(e);
496
- n?.(i) ?? setSignal(e, () => i);
497
- flush();
643
+ if (!e.X) {
644
+ for (let t = e.p; t !== null; t = t.I) {
645
+ if (t.h.ie & STATUS_PENDING) {
646
+ insertIntoHeap(t.h, t.h.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
498
647
  }
499
- } catch (n) {
500
- if (e.ae !== t) return;
501
- globalQueue.initTransition(e);
502
- setStatusFlags(e, STATUS_ERROR, n);
503
- e.se = clock;
504
- notifySubs(e);
505
- schedule();
506
- flush();
507
648
  }
508
- })();
649
+ }
650
+ schedule();
651
+ }
652
+ }
653
+ function notifyStatus(e, t, n) {
654
+ e.ie = t | (e.ie & STATUS_UNINITIALIZED);
655
+ e.B = n;
656
+ updatePendingSignal(e);
657
+ if (e.Te) return e.Te();
658
+ for (let i = e.p; i !== null; i = i.I) {
659
+ i.h.ae = clock;
660
+ if (i.h.B !== n) {
661
+ !i.h.X && globalQueue.L.push(i.h);
662
+ notifyStatus(i.h, t, n);
663
+ }
664
+ }
665
+ for (let i = e.A; i !== null; i = i.P) {
666
+ for (let e = i.p; e !== null; e = e.I) {
667
+ e.h.ae = clock;
668
+ if (e.h.B !== n) {
669
+ !e.h.X && globalQueue.L.push(e.h);
670
+ notifyStatus(e.h, t, n);
671
+ }
672
+ }
509
673
  }
510
- globalQueue.initTransition(e);
511
- throw new NotReadyError(context);
512
674
  }
513
675
  function updateIfNecessary(e) {
514
676
  if (e.S & REACTIVE_CHECK) {
515
- for (let t = e.D; t; t = t.P) {
677
+ for (let t = e.C; t; t = t.D) {
516
678
  const n = t.V;
517
679
  const i = n.m || n;
518
680
  if (i.U) {
@@ -530,68 +692,64 @@ function updateIfNecessary(e) {
530
692
  }
531
693
  function unlinkSubs(e) {
532
694
  const t = e.V;
533
- const n = e.P;
534
- const i = e.p;
535
- const r = e.fe;
536
- if (i !== null) i.fe = r;
537
- else t.Ee = r;
538
- if (r !== null) r.p = i;
695
+ const n = e.D;
696
+ const i = e.I;
697
+ const r = e.Re;
698
+ if (i !== null) i.Re = r;
699
+ else t.de = r;
700
+ if (r !== null) r.I = i;
539
701
  else {
540
- t.O = i;
702
+ t.p = i;
541
703
  if (i === null) {
542
- t.de?.();
543
- t.U && !t.Te && unobserved(t);
704
+ t.Oe?.();
705
+ t.U && !t.Se && unobserved(t);
544
706
  }
545
707
  }
546
708
  return n;
547
709
  }
548
710
  function unobserved(e) {
549
711
  deleteFromHeap(e, e.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
550
- let t = e.D;
712
+ let t = e.C;
551
713
  while (t !== null) {
552
714
  t = unlinkSubs(t);
553
715
  }
554
- e.D = null;
716
+ e.C = null;
555
717
  disposeChildren(e, true);
556
718
  }
557
719
  function link(e, t) {
558
- const n = t.re;
720
+ const n = t.ce;
559
721
  if (n !== null && n.V === e) return;
560
722
  let i = null;
561
723
  const r = t.S & REACTIVE_RECOMPUTING_DEPS;
562
724
  if (r) {
563
- i = n !== null ? n.P : t.D;
725
+ i = n !== null ? n.D : t.C;
564
726
  if (i !== null && i.V === e) {
565
- t.re = i;
727
+ t.ce = i;
566
728
  return;
567
729
  }
568
730
  }
569
- const s = e.Ee;
570
- if (s !== null && s.A === t && (!r || isValidLink(s, t))) return;
571
- const o = (t.re = e.Ee = { V: e, A: t, P: i, fe: s, p: null });
572
- if (n !== null) n.P = o;
573
- else t.D = o;
574
- if (s !== null) s.p = o;
575
- else e.O = o;
731
+ const o = e.de;
732
+ if (o !== null && o.h === t && (!r || isValidLink(o, t))) return;
733
+ const s = (t.ce = e.de = { V: e, h: t, D: i, Re: o, I: null });
734
+ if (n !== null) n.D = s;
735
+ else t.C = s;
736
+ if (o !== null) o.I = s;
737
+ else e.p = s;
576
738
  }
577
739
  function isValidLink(e, t) {
578
- const n = t.re;
740
+ const n = t.ce;
579
741
  if (n !== null) {
580
- let i = t.D;
742
+ let i = t.C;
581
743
  do {
582
744
  if (i === e) return true;
583
745
  if (i === n) break;
584
- i = i.P;
746
+ i = i.D;
585
747
  } while (i !== null);
586
748
  }
587
749
  return false;
588
750
  }
589
- function setStatusFlags(e, t, n = null) {
590
- e.J = t;
591
- e.j = n;
592
- }
593
751
  function markDisposal(e) {
594
- let t = e.ie;
752
+ let t = e.ue;
595
753
  while (t) {
596
754
  t.S |= REACTIVE_ZOMBIE;
597
755
  if (t.S & REACTIVE_IN_HEAP) {
@@ -599,47 +757,47 @@ function markDisposal(e) {
599
757
  insertIntoHeap(t, zombieQueue);
600
758
  }
601
759
  markDisposal(t);
602
- t = t.Re;
760
+ t = t._e;
603
761
  }
604
762
  }
605
763
  function dispose(e) {
606
- let t = e.D || null;
764
+ let t = e.C || null;
607
765
  do {
608
766
  t = unlinkSubs(t);
609
767
  } while (t !== null);
610
- e.D = null;
611
- e.re = null;
768
+ e.C = null;
769
+ e.ce = null;
612
770
  disposeChildren(e, true);
613
771
  }
614
772
  function disposeChildren(e, t = false, n) {
615
773
  if (e.S & REACTIVE_DISPOSED) return;
616
774
  if (t) e.S = REACTIVE_DISPOSED;
617
- let i = n ? e.ne : e.ie;
775
+ let i = n ? e.se : e.ue;
618
776
  while (i) {
619
- const e = i.Re;
620
- if (i.D) {
777
+ const e = i._e;
778
+ if (i.C) {
621
779
  const e = i;
622
780
  deleteFromHeap(e, e.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
623
- let t = e.D;
781
+ let t = e.C;
624
782
  do {
625
783
  t = unlinkSubs(t);
626
784
  } while (t !== null);
627
- e.D = null;
628
- e.re = null;
785
+ e.C = null;
786
+ e.ce = null;
629
787
  }
630
788
  disposeChildren(i, true);
631
789
  i = e;
632
790
  }
633
791
  if (n) {
634
- e.ne = null;
792
+ e.se = null;
635
793
  } else {
636
- e.ie = null;
637
- e.Re = null;
794
+ e.ue = null;
795
+ e._e = null;
638
796
  }
639
797
  runDisposal(e, n);
640
798
  }
641
799
  function runDisposal(e, t) {
642
- let n = t ? e.ee : e.te;
800
+ let n = t ? e.re : e.oe;
643
801
  if (!n) return;
644
802
  if (Array.isArray(n)) {
645
803
  for (let e = 0; e < n.length; e++) {
@@ -649,10 +807,10 @@ function runDisposal(e, t) {
649
807
  } else {
650
808
  n.call(n);
651
809
  }
652
- t ? (e.ee = null) : (e.te = null);
810
+ t ? (e.re = null) : (e.oe = null);
653
811
  }
654
812
  function getNextChildId(e) {
655
- if (e.id != null) return formatId(e.id, e.he++);
813
+ if (e.id != null) return formatId(e.id, e.pe++);
656
814
  throw new Error("Cannot get child id from owner without an id");
657
815
  }
658
816
  function formatId(e, t) {
@@ -663,45 +821,44 @@ function formatId(e, t) {
663
821
  function computed(e, t, n) {
664
822
  const i = {
665
823
  id: n?.id ?? (context?.id != null ? getNextChildId(context) : undefined),
666
- ue: n?.equals != null ? n.equals : isEqual,
667
- Se: !!n?.pureWrite,
668
- de: n?.unobserved,
669
- te: null,
670
- _e: context?._e ?? globalQueue,
671
- Oe: context?.Oe ?? defaultContext,
672
- he: 0,
824
+ fe: n?.equals != null ? n.equals : isEqual,
825
+ Ie: !!n?.pureWrite,
826
+ Oe: n?.unobserved,
827
+ oe: null,
828
+ J: context?.J ?? globalQueue,
829
+ he: context?.he ?? defaultContext,
830
+ pe: 0,
673
831
  U: e,
674
- Y: t,
832
+ ne: t,
675
833
  o: 0,
676
- N: null,
834
+ A: null,
677
835
  R: undefined,
678
836
  T: null,
679
- D: null,
680
- re: null,
681
- O: null,
682
- Ee: null,
837
+ C: null,
838
+ ce: null,
839
+ p: null,
840
+ de: null,
683
841
  i: context,
684
- Re: null,
685
- ie: null,
842
+ _e: null,
843
+ ue: null,
686
844
  S: REACTIVE_NONE,
687
- J: STATUS_UNINITIALIZED,
688
- se: clock,
689
- M: NOT_PENDING,
690
- ee: null,
691
- ne: null,
692
- ae: null,
693
- K: null
845
+ ie: STATUS_UNINITIALIZED,
846
+ ae: clock,
847
+ te: NOT_PENDING,
848
+ re: null,
849
+ se: null,
850
+ Ee: null,
851
+ X: null
694
852
  };
695
- if (n?.pe) Object.assign(i, n.pe);
696
853
  i.T = i;
697
854
  const r = context?.t ? context.u : context;
698
855
  if (context) {
699
- const e = context.ie;
856
+ const e = context.ue;
700
857
  if (e === null) {
701
- context.ie = i;
858
+ context.ue = i;
702
859
  } else {
703
- i.Re = e;
704
- context.ie = i;
860
+ i._e = e;
861
+ context.ue = i;
705
862
  }
706
863
  }
707
864
  if (r) i.o = r.o + 1;
@@ -710,22 +867,54 @@ function computed(e, t, n) {
710
867
  }
711
868
  function signal(e, t, n = null) {
712
869
  const i = {
713
- id: t?.id ?? (context?.id != null ? getNextChildId(context) : undefined),
714
- ue: t?.equals != null ? t.equals : isEqual,
715
- Se: !!t?.pureWrite,
716
- de: t?.unobserved,
717
- Y: e,
718
- O: null,
719
- Ee: null,
720
- J: STATUS_NONE,
721
- se: clock,
870
+ fe: t?.equals != null ? t.equals : isEqual,
871
+ Ie: !!t?.pureWrite,
872
+ Oe: t?.unobserved,
873
+ ne: e,
874
+ p: null,
875
+ de: null,
876
+ ae: clock,
722
877
  m: n,
723
- I: n?.N || null,
724
- M: NOT_PENDING
878
+ P: n?.A || null,
879
+ te: NOT_PENDING
725
880
  };
726
- n && (n.N = i);
881
+ n && (n.A = i);
727
882
  return i;
728
883
  }
884
+ function optimisticSignal(e, t) {
885
+ const n = signal(e, t);
886
+ n.le = true;
887
+ return n;
888
+ }
889
+ function optimisticComputed(e, t, n) {
890
+ const i = computed(e, t, n);
891
+ i.le = true;
892
+ return i;
893
+ }
894
+ function getPendingSignal(e) {
895
+ if (!e.Ae) {
896
+ e.Ae = optimisticSignal(false, { pureWrite: true });
897
+ if (computePendingState(e)) setSignal(e.Ae, true);
898
+ }
899
+ return e.Ae;
900
+ }
901
+ function computePendingState(e) {
902
+ if (e.te !== NOT_PENDING) return true;
903
+ const t = e;
904
+ return !!(t.ie & STATUS_PENDING && !(t.ie & STATUS_UNINITIALIZED));
905
+ }
906
+ function getPendingValueComputed(e) {
907
+ if (!e.ge) {
908
+ const t = pendingReadActive;
909
+ pendingReadActive = false;
910
+ e.ge = optimisticComputed(() => read(e));
911
+ pendingReadActive = t;
912
+ }
913
+ return e.ge;
914
+ }
915
+ function updatePendingSignal(e) {
916
+ if (e.Ae) setSignal(e.Ae, computePendingState(e));
917
+ }
729
918
  function isEqual(e, t) {
730
919
  return e === t;
731
920
  }
@@ -739,16 +928,36 @@ function untrack(e) {
739
928
  }
740
929
  }
741
930
  function read(e) {
931
+ if (pendingCheckActive) {
932
+ const t = e.m || e;
933
+ const n = getPendingSignal(t);
934
+ const i = pendingCheckActive;
935
+ pendingCheckActive = false;
936
+ if (read(n)) {
937
+ foundPending = true;
938
+ }
939
+ pendingCheckActive = i;
940
+ return e.ne;
941
+ }
942
+ if (pendingReadActive) {
943
+ const t = getPendingValueComputed(e);
944
+ const n = pendingReadActive;
945
+ pendingReadActive = false;
946
+ const i = read(t);
947
+ pendingReadActive = n;
948
+ if (t.ie & STATUS_PENDING) return e.ne;
949
+ return i;
950
+ }
742
951
  let t = context;
743
952
  if (t?.t) t = t.u;
744
953
  if (refreshing && e.U) recompute(e);
745
- if (t && tracking && !pendingCheck && !pendingValueCheck) {
954
+ if (t && tracking) {
746
955
  if (e.U && e.S & REACTIVE_DISPOSED) recompute(e);
747
956
  link(e, t);
748
957
  const n = e.m || e;
749
958
  if (n.U) {
750
959
  const i = e.S & REACTIVE_ZOMBIE;
751
- if (n.o >= (i ? zombieQueue.C : dirtyQueue.C)) {
960
+ if (n.o >= (i ? zombieQueue.N : dirtyQueue.N)) {
752
961
  markNode(t);
753
962
  markHeap(i ? zombieQueue : dirtyQueue);
754
963
  updateIfNecessary(n);
@@ -759,72 +968,60 @@ function read(e) {
759
968
  }
760
969
  }
761
970
  }
762
- if (pendingValueCheck) {
763
- if (!e.ce) {
764
- e.ce = signal(e.Y);
765
- e.ce.oe = true;
766
- }
767
- pendingValueCheck = false;
768
- try {
769
- return read(e.ce);
770
- } finally {
771
- pendingValueCheck = true;
772
- }
773
- }
774
971
  const n = e.m || e;
775
- if (pendingCheck) {
776
- if (!n.q) {
777
- n.q = signal(false);
778
- n.q.oe = true;
779
- n.q.Z = e => setSignal(n.q, e);
780
- }
781
- const e = pendingCheck;
782
- pendingCheck = null;
783
- e.Y = read(n.q) || e.Y;
784
- pendingCheck = e;
785
- }
786
- if (!pendingCheck && n.J & STATUS_PENDING) {
787
- if ((t && !stale) || n.J & STATUS_UNINITIALIZED || e.m) throw n.j;
788
- else if (t && stale) {
789
- setStatusFlags(t, t.J | STATUS_PENDING, n.j);
790
- }
791
- }
792
- if (e.J & STATUS_ERROR) {
793
- if (e.se < clock) {
972
+ if (
973
+ t &&
974
+ !optimisticReadActive &&
975
+ n.ie & STATUS_PENDING &&
976
+ !(stale && n.X && activeTransition !== n.X)
977
+ )
978
+ throw n.B;
979
+ if (e.U && e.ie & STATUS_ERROR) {
980
+ if (e.ae < clock) {
794
981
  recompute(e, true);
795
982
  return read(e);
796
- } else {
797
- throw e.j;
798
- }
983
+ } else throw e.B;
799
984
  }
800
985
  return !t ||
801
- e.oe ||
802
- e.M === NOT_PENDING ||
803
- (stale && !pendingCheck && (t.oe || (e.K && activeTransition !== e.K)))
804
- ? e.Y
805
- : e.M;
986
+ optimisticReadActive ||
987
+ e.te === NOT_PENDING ||
988
+ (stale && e.X && activeTransition !== e.X)
989
+ ? e.ne
990
+ : e.te;
806
991
  }
807
992
  function setSignal(e, t) {
808
- if (typeof t === "function") {
809
- t = t(e.M === NOT_PENDING || (e.oe && e.K) ? e.Y : e.M);
810
- }
811
- const n = !e.ue || !e.ue(e.M === NOT_PENDING || (e.oe && e.K) ? e.Y : e.M, t);
812
- if (!n && !e.J) return t;
993
+ if (e.X && activeTransition !== e.X) globalQueue.initTransition(e.X);
994
+ const n = e.le && !projectionWriteActive;
995
+ const i = n ? e.ne : e.te === NOT_PENDING ? e.ne : e.te;
996
+ if (typeof t === "function") t = t(i);
997
+ const r = !e.fe || !e.fe(i, t);
998
+ if (!r) return t;
813
999
  if (n) {
814
- if (e.oe) e.Y = t;
815
- else {
816
- if (e.M === NOT_PENDING) globalQueue.L.push(e);
817
- e.M = t;
1000
+ const n = e.te === NOT_PENDING;
1001
+ if (e.X && !n) {
1002
+ globalQueue.initTransition(e.X);
818
1003
  }
819
- if (e.ce) setSignal(e.ce, t);
1004
+ if (n) {
1005
+ e.te = e.ne;
1006
+ globalQueue.H.push(e);
1007
+ }
1008
+ e.ne = t;
1009
+ } else {
1010
+ if (e.te === NOT_PENDING) globalQueue.L.push(e);
1011
+ e.te = t;
1012
+ }
1013
+ updatePendingSignal(e);
1014
+ if (e.ge) {
1015
+ setSignal(e.ge, t);
820
1016
  }
821
- setStatusFlags(e, STATUS_NONE);
822
- e.se = clock;
823
- e.oe && !optimisticRun ? globalQueue.$.push(e) : notifySubs(e);
1017
+ e.ae = clock;
1018
+ insertSubs(e, n);
824
1019
  schedule();
825
1020
  return t;
826
1021
  }
1022
+ const PENDING_OWNER = {};
827
1023
  function getObserver() {
1024
+ if (pendingCheckActive || pendingReadActive) return PENDING_OWNER;
828
1025
  return tracking ? context : null;
829
1026
  }
830
1027
  function getOwner() {
@@ -832,42 +1029,37 @@ function getOwner() {
832
1029
  }
833
1030
  function onCleanup(e) {
834
1031
  if (!context) return e;
835
- const t = context;
836
- if (!t.te) {
837
- t.te = e;
838
- } else if (Array.isArray(t.te)) {
839
- t.te.push(e);
840
- } else {
841
- t.te = [t.te, e];
842
- }
1032
+ if (!context.oe) context.oe = e;
1033
+ else if (Array.isArray(context.oe)) context.oe.push(e);
1034
+ else context.oe = [context.oe, e];
843
1035
  return e;
844
1036
  }
845
1037
  function createOwner(e) {
846
1038
  const t = context;
847
1039
  const n = {
1040
+ id: e?.id ?? (t?.id != null ? getNextChildId(t) : undefined),
848
1041
  t: true,
849
1042
  u: t?.t ? t.u : t,
850
- ie: null,
851
- Re: null,
852
- te: null,
853
- id: e?.id ?? (t?.id != null ? getNextChildId(t) : undefined),
854
- _e: t?._e ?? globalQueue,
855
- Oe: t?.Oe || defaultContext,
856
- he: 0,
857
- ee: null,
858
- ne: null,
1043
+ ue: null,
1044
+ _e: null,
1045
+ oe: null,
1046
+ J: t?.J ?? globalQueue,
1047
+ he: t?.he || defaultContext,
1048
+ pe: 0,
1049
+ re: null,
1050
+ se: null,
859
1051
  i: t,
860
1052
  dispose(e = true) {
861
1053
  disposeChildren(n, e);
862
1054
  }
863
1055
  };
864
1056
  if (t) {
865
- const e = t.ie;
1057
+ const e = t.ue;
866
1058
  if (e === null) {
867
- t.ie = n;
1059
+ t.ue = n;
868
1060
  } else {
869
- n.Re = e;
870
- t.ie = n;
1061
+ n._e = e;
1062
+ t.ue = n;
871
1063
  }
872
1064
  }
873
1065
  return n;
@@ -878,11 +1070,14 @@ function createRoot(e, t) {
878
1070
  }
879
1071
  function runWithOwner(e, t) {
880
1072
  const n = context;
1073
+ const i = tracking;
881
1074
  context = e;
1075
+ tracking = false;
882
1076
  try {
883
1077
  return t();
884
1078
  } finally {
885
1079
  context = n;
1080
+ tracking = i;
886
1081
  }
887
1082
  }
888
1083
  function staleValues(e, t = true) {
@@ -895,25 +1090,25 @@ function staleValues(e, t = true) {
895
1090
  }
896
1091
  }
897
1092
  function pending(e) {
898
- const t = pendingValueCheck;
899
- pendingValueCheck = true;
1093
+ const t = pendingReadActive;
1094
+ pendingReadActive = true;
900
1095
  try {
901
- return staleValues(e, false);
1096
+ return e();
902
1097
  } finally {
903
- pendingValueCheck = t;
1098
+ pendingReadActive = t;
904
1099
  }
905
1100
  }
906
1101
  function isPending(e) {
907
- const t = pendingCheck;
908
- pendingCheck = { Y: false };
1102
+ const t = pendingCheckActive;
1103
+ const n = foundPending;
1104
+ pendingCheckActive = true;
1105
+ foundPending = false;
909
1106
  try {
910
- staleValues(e);
911
- return pendingCheck.Y;
912
- } catch (e) {
913
- if (!(e instanceof NotReadyError)) return false;
914
- throw e;
1107
+ e();
1108
+ return foundPending;
915
1109
  } finally {
916
- pendingCheck = t;
1110
+ pendingCheckActive = t;
1111
+ foundPending = n;
917
1112
  }
918
1113
  }
919
1114
  function refresh(e) {
@@ -929,7 +1124,6 @@ function refresh(e) {
929
1124
  refreshing = t;
930
1125
  if (!t) {
931
1126
  schedule();
932
- flush();
933
1127
  }
934
1128
  }
935
1129
  }
@@ -943,7 +1137,7 @@ function getContext(e, t = getOwner()) {
943
1137
  if (!t) {
944
1138
  throw new NoOwnerError();
945
1139
  }
946
- const n = hasContext(e, t) ? t.Oe[e.id] : e.defaultValue;
1140
+ const n = hasContext(e, t) ? t.he[e.id] : e.defaultValue;
947
1141
  if (isUndefined(n)) {
948
1142
  throw new ContextNotFoundError();
949
1143
  }
@@ -953,73 +1147,92 @@ function setContext(e, t, n = getOwner()) {
953
1147
  if (!n) {
954
1148
  throw new NoOwnerError();
955
1149
  }
956
- n.Oe = { ...n.Oe, [e.id]: isUndefined(t) ? e.defaultValue : t };
1150
+ n.he = { ...n.he, [e.id]: isUndefined(t) ? e.defaultValue : t };
957
1151
  }
958
1152
  function hasContext(e, t) {
959
- return !isUndefined(t?.Oe[e.id]);
1153
+ return !isUndefined(t?.he[e.id]);
960
1154
  }
961
1155
  function isUndefined(e) {
962
1156
  return typeof e === "undefined";
963
1157
  }
964
1158
  function effect(e, t, n, i, r) {
965
- let s = false;
966
- const o = computed(e, i, {
1159
+ let o = false;
1160
+ const s = computed(r?.render ? t => staleValues(() => e(t)) : e, i, {
967
1161
  ...r,
968
- pe: {
969
- X: true,
970
- Ae: i,
971
- Ne: t,
972
- ge: n,
973
- Ie: undefined,
974
- B: r?.render ? EFFECT_RENDER : EFFECT_USER,
975
- le(e, t) {
976
- if (s) {
977
- const n = this.J && this.J === t && e;
978
- this.X = !(this.J & STATUS_ERROR) && !(this.J & STATUS_PENDING & ~t) && !n;
979
- if (this.X) this._e.enqueue(this.B, runEffect.bind(this));
980
- }
981
- if (this.J & STATUS_ERROR) {
982
- let e = this.j;
983
- this._e.notify(this, STATUS_PENDING, 0);
984
- if (this.B === EFFECT_USER) {
985
- try {
986
- return this.ge
987
- ? this.ge(e, () => {
988
- this.Ie?.();
989
- this.Ie = undefined;
990
- })
991
- : console.error(e);
992
- } catch (t) {
993
- e = t;
994
- }
995
- }
996
- if (!this._e.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
997
- } else if (this.B === EFFECT_RENDER) {
998
- this._e.notify(this, STATUS_PENDING | STATUS_ERROR, this.J);
1162
+ equals: () => {
1163
+ s.Z = !s.B;
1164
+ if (o) s.J.enqueue(s.q, runEffect.bind(s));
1165
+ return false;
1166
+ },
1167
+ lazy: true
1168
+ });
1169
+ s.Pe = i;
1170
+ s.Ne = t;
1171
+ s.Ce = n;
1172
+ s.ye = undefined;
1173
+ s.q = r?.render ? EFFECT_RENDER : EFFECT_USER;
1174
+ s.Te = () => {
1175
+ if (s.ie & STATUS_ERROR) {
1176
+ let e = s.B;
1177
+ s.J.notify(s, STATUS_PENDING, 0);
1178
+ if (s.q === EFFECT_USER) {
1179
+ try {
1180
+ return s.Ce
1181
+ ? s.Ce(e, () => {
1182
+ s.ye?.();
1183
+ s.ye = undefined;
1184
+ })
1185
+ : console.error(e);
1186
+ } catch (t) {
1187
+ e = t;
999
1188
  }
1000
1189
  }
1001
- }
1002
- });
1003
- s = true;
1004
- if (o.B === EFFECT_RENDER) o.U = t => staleValues(() => e(t));
1005
- !r?.defer &&
1006
- !(o.J & (STATUS_ERROR | STATUS_PENDING)) &&
1007
- (o.B === EFFECT_USER ? o._e.enqueue(o.B, runEffect.bind(o)) : runEffect.call(o));
1008
- onCleanup(() => o.Ie?.());
1190
+ if (!s.J.notify(s, STATUS_ERROR, STATUS_ERROR)) throw e;
1191
+ } else if (s.q === EFFECT_RENDER) s.J.notify(s, STATUS_PENDING | STATUS_ERROR, s.ie);
1192
+ };
1193
+ recompute(s, true);
1194
+ !r?.defer && (s.q === EFFECT_USER ? s.J.enqueue(s.q, runEffect.bind(s)) : runEffect.call(s));
1195
+ o = true;
1196
+ onCleanup(() => s.ye?.());
1009
1197
  }
1010
1198
  function runEffect() {
1011
- if (!this.X || this.S & REACTIVE_DISPOSED) return;
1012
- this.Ie?.();
1013
- this.Ie = undefined;
1199
+ if (!this.Z || this.S & REACTIVE_DISPOSED) return;
1200
+ this.ye?.();
1201
+ this.ye = undefined;
1014
1202
  try {
1015
- this.Ie = this.Ne(this.Y, this.Ae);
1203
+ this.ye = this.Ne(this.ne, this.Pe);
1016
1204
  } catch (e) {
1017
- if (!this._e.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
1205
+ if (!this.J.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
1018
1206
  } finally {
1019
- this.Ae = this.Y;
1020
- this.X = false;
1207
+ this.Pe = this.ne;
1208
+ this.Z = false;
1021
1209
  }
1022
1210
  }
1211
+ function trackedEffect(e, t) {
1212
+ const run = () => {
1213
+ if (!n.Z || n.S & REACTIVE_DISPOSED) return;
1214
+ n.Z = false;
1215
+ recompute(n);
1216
+ };
1217
+ const n = computed(
1218
+ () => {
1219
+ try {
1220
+ n.ye?.();
1221
+ n.ye = undefined;
1222
+ n.ye = staleValues(e) || undefined;
1223
+ } finally {
1224
+ }
1225
+ },
1226
+ undefined,
1227
+ { ...t, lazy: true, pureWrite: true }
1228
+ );
1229
+ n.ye = undefined;
1230
+ n.Z = true;
1231
+ n.q = EFFECT_TRACKED;
1232
+ n.ee = run;
1233
+ n.J.enqueue(EFFECT_USER, run);
1234
+ onCleanup(() => n.ye?.());
1235
+ }
1023
1236
  function createSignal(e, t, n) {
1024
1237
  if (typeof e === "function") {
1025
1238
  const i = computed(e, t, n);
@@ -1033,12 +1246,14 @@ function createMemo(e, t, n) {
1033
1246
  return read.bind(null, i);
1034
1247
  }
1035
1248
  function createEffect(e, t, n, i) {
1036
- void effect(e, t.effect || t, t.error, n, i);
1249
+ effect(e, t.effect || t, t.error, n, i);
1037
1250
  }
1038
1251
  function createRenderEffect(e, t, n, i) {
1039
- void effect(e, t, undefined, n, { render: true, ...i });
1252
+ effect(e, t, undefined, n, { render: true, ...i });
1253
+ }
1254
+ function createTrackedEffect(e, t) {
1255
+ trackedEffect(e, t);
1040
1256
  }
1041
- function createTrackedEffect(e, t) {}
1042
1257
  function createReaction(e, t) {
1043
1258
  let n = undefined;
1044
1259
  onCleanup(() => n?.());
@@ -1075,39 +1290,16 @@ function resolve(e) {
1075
1290
  });
1076
1291
  }
1077
1292
  function createOptimistic(e, t, n) {
1078
- if (typeof e === "function") {
1079
- const i = computed(
1080
- t => {
1081
- const n = getOwner();
1082
- const i = e(t);
1083
- if (n.J & STATUS_UNINITIALIZED) return i;
1084
- n.M = i;
1085
- return t;
1086
- },
1087
- t,
1088
- n
1089
- );
1090
- i.oe = true;
1091
- return [read.bind(null, i), setSignal.bind(null, i)];
1092
- }
1093
- const i = signal(e, t);
1094
- i.oe = true;
1095
- return [
1096
- read.bind(null, i),
1097
- t => {
1098
- i.M = e;
1099
- return setSignal(i, t);
1100
- }
1101
- ];
1293
+ const i = typeof e === "function" ? optimisticComputed(e, t, n) : optimisticSignal(e, t);
1294
+ return [read.bind(null, i), setSignal.bind(null, i)];
1102
1295
  }
1103
1296
  function onSettled(e) {
1104
- let t;
1105
- const n = getOwner();
1106
- if (n) onCleanup(() => t?.());
1107
- globalQueue.enqueue(EFFECT_USER, () => {
1108
- t = e();
1109
- !n && t?.();
1110
- });
1297
+ getOwner()
1298
+ ? createTrackedEffect(() => untrack(e))
1299
+ : globalQueue.enqueue(EFFECT_USER, () => {
1300
+ const t = e();
1301
+ t?.();
1302
+ });
1111
1303
  }
1112
1304
  function unwrap(e) {
1113
1305
  return e?.[$TARGET]?.[STORE_NODE] ?? e;
@@ -1123,67 +1315,67 @@ function getAllKeys(e, t, n) {
1123
1315
  function applyState(e, t, n, i) {
1124
1316
  const r = t?.[$TARGET];
1125
1317
  if (!r) return;
1126
- const s = r[STORE_VALUE];
1127
- const o = r[STORE_OVERRIDE];
1318
+ const o = r[STORE_VALUE];
1319
+ const s = r[STORE_OVERRIDE];
1128
1320
  let u = r[STORE_NODE];
1129
- if (e === s && !o) return;
1321
+ if (e === o && !s) return;
1130
1322
  (r[STORE_LOOKUP] || storeLookup).set(e, r[$PROXY]);
1131
1323
  r[STORE_VALUE] = e;
1132
1324
  r[STORE_OVERRIDE] = undefined;
1133
- if (Array.isArray(s)) {
1325
+ if (Array.isArray(o)) {
1134
1326
  let t = false;
1135
- const l = getOverrideValue(s, o, u, "length");
1327
+ const l = getOverrideValue(o, s, u, "length");
1136
1328
  if (e.length && l && e[0] && n(e[0]) != null) {
1137
- let c, a, f, E, d, T, R, h;
1329
+ let c, a, f, E, T, R, d, O;
1138
1330
  for (
1139
1331
  f = 0, E = Math.min(l, e.length);
1140
- f < E && ((T = getOverrideValue(s, o, u, f)) === e[f] || (T && e[f] && n(T) === n(e[f])));
1332
+ f < E && ((R = getOverrideValue(o, s, u, f)) === e[f] || (R && e[f] && n(R) === n(e[f])));
1141
1333
  f++
1142
1334
  ) {
1143
- applyState(e[f], wrap(T, r), n, i);
1335
+ applyState(e[f], wrap(R, r), n, i);
1144
1336
  }
1145
1337
  const S = new Array(e.length),
1146
1338
  _ = new Map();
1147
1339
  for (
1148
- E = l - 1, d = e.length - 1;
1340
+ E = l - 1, T = e.length - 1;
1149
1341
  E >= f &&
1150
- d >= f &&
1151
- ((T = getOverrideValue(s, o, u, E)) === e[d] || (T && e[d] && n(T) === n(e[d])));
1152
- E--, d--
1342
+ T >= f &&
1343
+ ((R = getOverrideValue(o, s, u, E)) === e[T] || (R && e[T] && n(R) === n(e[T])));
1344
+ E--, T--
1153
1345
  ) {
1154
- S[d] = T;
1346
+ S[T] = R;
1155
1347
  }
1156
- if (f > d || f > E) {
1157
- for (a = f; a <= d; a++) {
1348
+ if (f > T || f > E) {
1349
+ for (a = f; a <= T; a++) {
1158
1350
  t = true;
1159
1351
  r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], wrap(e[a], r));
1160
1352
  }
1161
1353
  for (; a < e.length; a++) {
1162
1354
  t = true;
1163
- const s = wrap(S[a], r);
1164
- r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], s);
1165
- applyState(e[a], s, n, i);
1355
+ const o = wrap(S[a], r);
1356
+ r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], o);
1357
+ applyState(e[a], o, n, i);
1166
1358
  }
1167
1359
  t && r[STORE_NODE][$TRACK] && setSignal(r[STORE_NODE][$TRACK], void 0);
1168
1360
  l !== e.length && r[STORE_NODE].length && setSignal(r[STORE_NODE].length, e.length);
1169
1361
  return;
1170
1362
  }
1171
- R = new Array(d + 1);
1172
- for (a = d; a >= f; a--) {
1173
- T = e[a];
1174
- h = T ? n(T) : T;
1175
- c = _.get(h);
1176
- R[a] = c === undefined ? -1 : c;
1177
- _.set(h, a);
1363
+ d = new Array(T + 1);
1364
+ for (a = T; a >= f; a--) {
1365
+ R = e[a];
1366
+ O = R ? n(R) : R;
1367
+ c = _.get(O);
1368
+ d[a] = c === undefined ? -1 : c;
1369
+ _.set(O, a);
1178
1370
  }
1179
1371
  for (c = f; c <= E; c++) {
1180
- T = getOverrideValue(s, o, u, c);
1181
- h = T ? n(T) : T;
1182
- a = _.get(h);
1372
+ R = getOverrideValue(o, s, u, c);
1373
+ O = R ? n(R) : R;
1374
+ a = _.get(O);
1183
1375
  if (a !== undefined && a !== -1) {
1184
- S[a] = T;
1185
- a = R[a];
1186
- _.set(h, a);
1376
+ S[a] = R;
1377
+ a = d[a];
1378
+ _.set(O, a);
1187
1379
  }
1188
1380
  }
1189
1381
  for (a = f; a < e.length; a++) {
@@ -1196,7 +1388,7 @@ function applyState(e, t, n, i) {
1196
1388
  if (f < e.length) t = true;
1197
1389
  } else if (e.length) {
1198
1390
  for (let t = 0, l = e.length; t < l; t++) {
1199
- const l = getOverrideValue(s, o, u, t);
1391
+ const l = getOverrideValue(o, s, u, t);
1200
1392
  isWrappable(l)
1201
1393
  ? applyState(e[t], wrap(l, r), n, i)
1202
1394
  : r[STORE_NODE][t] && setSignal(r[STORE_NODE][t], e[t]);
@@ -1211,17 +1403,17 @@ function applyState(e, t, n, i) {
1211
1403
  }
1212
1404
  if (u) {
1213
1405
  const t = u[$TRACK];
1214
- const l = t || i ? getAllKeys(s, o, e) : Object.keys(u);
1406
+ const l = t || i ? getAllKeys(o, s, e) : Object.keys(u);
1215
1407
  for (let c = 0, a = l.length; c < a; c++) {
1216
1408
  const a = l[c];
1217
1409
  const f = u[a];
1218
- const E = unwrap(getOverrideValue(s, o, u, a));
1219
- let d = unwrap(e[a]);
1220
- if (E === d) continue;
1221
- if (!E || !isWrappable(E) || (n(E) != null && n(E) !== n(d))) {
1410
+ const E = unwrap(getOverrideValue(o, s, u, a));
1411
+ let T = unwrap(e[a]);
1412
+ if (E === T) continue;
1413
+ if (!E || !isWrappable(E) || (n(E) != null && n(E) !== n(T))) {
1222
1414
  t && setSignal(t, void 0);
1223
- f && setSignal(f, isWrappable(d) ? wrap(d, r) : d);
1224
- } else applyState(d, wrap(E, r), n, i);
1415
+ f && setSignal(f, isWrappable(T) ? wrap(T, r) : T);
1416
+ } else applyState(T, wrap(E, r), n, i);
1225
1417
  }
1226
1418
  }
1227
1419
  if ((u = r[STORE_HAS])) {
@@ -1236,8 +1428,8 @@ function reconcile(e, t, n = false) {
1236
1428
  return i => {
1237
1429
  if (i == null) throw new Error("Cannot reconcile null or undefined state");
1238
1430
  const r = typeof t === "string" ? e => e[t] : t;
1239
- const s = r(i);
1240
- if (s !== undefined && r(e) !== r(i))
1431
+ const o = r(i);
1432
+ if (o !== undefined && r(e) !== r(i))
1241
1433
  throw new Error("Cannot reconcile states with different identity");
1242
1434
  applyState(e, i, r, n);
1243
1435
  };
@@ -1262,19 +1454,19 @@ function createProjectionInternal(e, t = {}, n) {
1262
1454
  r.set(e, t);
1263
1455
  return t;
1264
1456
  };
1265
- const s = wrapProjection(t);
1457
+ const o = wrapProjection(t);
1266
1458
  i = computed(() => {
1267
1459
  const t = getOwner();
1268
- storeSetter(new Proxy(s, writeTraps), i => {
1460
+ storeSetter(new Proxy(o, writeTraps), i => {
1269
1461
  const r = handleAsync(t, e(i), e => {
1270
- e !== s && e !== undefined && storeSetter(s, reconcile(e, n?.key || "id", n?.all));
1462
+ e !== i && e !== undefined && storeSetter(o, reconcile(e, n?.key || "id", n?.all));
1271
1463
  setSignal(t, undefined);
1272
1464
  });
1273
- r !== s && r !== undefined && reconcile(r, n?.key || "id", n?.all)(s);
1465
+ r !== i && r !== undefined && reconcile(r, n?.key || "id", n?.all)(o);
1274
1466
  });
1275
1467
  });
1276
- i.Te = true;
1277
- return { store: s, node: i };
1468
+ i.Se = true;
1469
+ return { store: o, node: i };
1278
1470
  }
1279
1471
  function createProjection(e, t = {}, n) {
1280
1472
  return createProjectionInternal(e, t, n).store;
@@ -1283,28 +1475,34 @@ const writeTraps = {
1283
1475
  get(e, t) {
1284
1476
  let n;
1285
1477
  setWriteOverride(true);
1478
+ setProjectionWriteActive(true);
1286
1479
  try {
1287
1480
  n = e[t];
1288
1481
  } finally {
1289
1482
  setWriteOverride(false);
1483
+ setProjectionWriteActive(false);
1290
1484
  }
1291
1485
  return typeof n === "object" && n !== null ? new Proxy(n, writeTraps) : n;
1292
1486
  },
1293
1487
  set(e, t, n) {
1294
1488
  setWriteOverride(true);
1489
+ setProjectionWriteActive(true);
1295
1490
  try {
1296
1491
  e[t] = n;
1297
1492
  } finally {
1298
1493
  setWriteOverride(false);
1494
+ setProjectionWriteActive(false);
1299
1495
  }
1300
1496
  return true;
1301
1497
  },
1302
1498
  deleteProperty(e, t) {
1303
1499
  setWriteOverride(true);
1500
+ setProjectionWriteActive(true);
1304
1501
  try {
1305
1502
  delete e[t];
1306
1503
  } finally {
1307
1504
  setWriteOverride(false);
1505
+ setProjectionWriteActive(false);
1308
1506
  }
1309
1507
  return true;
1310
1508
  }
@@ -1317,11 +1515,13 @@ const $TRACK = Symbol(0),
1317
1515
  const PARENTS = new WeakMap();
1318
1516
  const STORE_VALUE = "v",
1319
1517
  STORE_OVERRIDE = "o",
1518
+ STORE_OPTIMISTIC_OVERRIDE = "x",
1320
1519
  STORE_NODE = "n",
1321
1520
  STORE_HAS = "h",
1322
1521
  STORE_WRAP = "w",
1323
1522
  STORE_LOOKUP = "l",
1324
- STORE_FIREWALL = "f";
1523
+ STORE_FIREWALL = "f",
1524
+ STORE_OPTIMISTIC = "p";
1325
1525
  function createStoreProxy(e, t = storeTraps, n) {
1326
1526
  let i;
1327
1527
  if (Array.isArray(e)) {
@@ -1353,9 +1553,9 @@ function getNodes(e, t) {
1353
1553
  if (!n) e[t] = n = Object.create(null);
1354
1554
  return n;
1355
1555
  }
1356
- function getNode(e, t, n, i, r = isEqual) {
1556
+ function getNode(e, t, n, i, r = isEqual, o) {
1357
1557
  if (e[t]) return e[t];
1358
- return (e[t] = signal(
1558
+ const s = signal(
1359
1559
  n,
1360
1560
  {
1361
1561
  equals: r,
@@ -1364,17 +1564,22 @@ function getNode(e, t, n, i, r = isEqual) {
1364
1564
  }
1365
1565
  },
1366
1566
  i
1367
- ));
1567
+ );
1568
+ if (o) s.le = true;
1569
+ return (e[t] = s);
1368
1570
  }
1369
1571
  function trackSelf(e, t = $TRACK) {
1370
- getObserver() && read(getNode(getNodes(e, STORE_NODE), t, undefined, e[STORE_FIREWALL], false));
1572
+ getObserver() &&
1573
+ read(
1574
+ getNode(getNodes(e, STORE_NODE), t, undefined, e[STORE_FIREWALL], false, e[STORE_OPTIMISTIC])
1575
+ );
1371
1576
  }
1372
1577
  function getKeys(e, t, n = true) {
1373
1578
  const i = untrack(() => (n ? Object.keys(e) : Reflect.ownKeys(e)));
1374
1579
  if (!t) return i;
1375
1580
  const r = new Set(i);
1376
- const s = Reflect.ownKeys(t);
1377
- for (const e of s) {
1581
+ const o = Reflect.ownKeys(t);
1582
+ for (const e of o) {
1378
1583
  if (t[e] !== $DELETED) r.add(e);
1379
1584
  else r.delete(e);
1380
1585
  }
@@ -1400,104 +1605,170 @@ const storeTraps = {
1400
1605
  }
1401
1606
  const i = getNodes(e, STORE_NODE);
1402
1607
  const r = i[t];
1403
- const s = e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE];
1404
- const o = !!e[STORE_VALUE][$TARGET];
1405
- const u = s ? e[STORE_OVERRIDE] : e[STORE_VALUE];
1608
+ const o = e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE];
1609
+ const s = o || (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]);
1610
+ const u = !!e[STORE_VALUE][$TARGET];
1611
+ const l = o
1612
+ ? e[STORE_OPTIMISTIC_OVERRIDE]
1613
+ : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
1614
+ ? e[STORE_OVERRIDE]
1615
+ : e[STORE_VALUE];
1406
1616
  if (!r) {
1407
- const e = Object.getOwnPropertyDescriptor(u, t);
1617
+ const e = Object.getOwnPropertyDescriptor(l, t);
1408
1618
  if (e && e.get) return e.get.call(n);
1409
1619
  }
1410
1620
  if (writeOnly(n)) {
1411
- let n = r && (s || !o) ? (r.M !== NOT_PENDING ? r.M : r.Y) : u[t];
1621
+ let n = r && (s || !u) ? (r.te !== NOT_PENDING ? (r.le ? r.ne : r.te) : r.ne) : l[t];
1412
1622
  n === $DELETED && (n = undefined);
1413
1623
  if (!isWrappable(n)) return n;
1414
1624
  const i = wrap(n, e);
1415
1625
  Writing?.add(i);
1416
1626
  return i;
1417
1627
  }
1418
- let l = r ? (s || !o ? read(i[t]) : (read(i[t]), u[t])) : u[t];
1419
- l === $DELETED && (l = undefined);
1628
+ let c = r ? (s || !u ? read(i[t]) : (read(i[t]), l[t])) : l[t];
1629
+ c === $DELETED && (c = undefined);
1420
1630
  if (!r) {
1421
- if (!s && typeof l === "function" && !u.hasOwnProperty(t)) {
1631
+ if (!s && typeof c === "function" && !l.hasOwnProperty(t)) {
1422
1632
  let t;
1423
1633
  return !Array.isArray(e[STORE_VALUE]) &&
1424
1634
  (t = Object.getPrototypeOf(e[STORE_VALUE])) &&
1425
1635
  t !== Object.prototype
1426
- ? l.bind(u)
1427
- : l;
1636
+ ? c.bind(l)
1637
+ : c;
1428
1638
  } else if (getObserver()) {
1429
- return read(getNode(i, t, isWrappable(l) ? wrap(l, e) : l, e[STORE_FIREWALL]));
1639
+ return read(
1640
+ getNode(
1641
+ i,
1642
+ t,
1643
+ isWrappable(c) ? wrap(c, e) : c,
1644
+ e[STORE_FIREWALL],
1645
+ isEqual,
1646
+ e[STORE_OPTIMISTIC]
1647
+ )
1648
+ );
1430
1649
  }
1431
1650
  }
1432
- return isWrappable(l) ? wrap(l, e) : l;
1651
+ return isWrappable(c) ? wrap(c, e) : c;
1433
1652
  },
1434
1653
  has(e, t) {
1435
1654
  if (t === $PROXY || t === $TRACK || t === "__proto__") return true;
1436
1655
  const n =
1437
- e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
1438
- ? e[STORE_OVERRIDE][t] !== $DELETED
1439
- : t in e[STORE_VALUE];
1440
- getObserver() && read(getNode(getNodes(e, STORE_HAS), t, n, e[STORE_FIREWALL]));
1656
+ e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
1657
+ ? e[STORE_OPTIMISTIC_OVERRIDE][t] !== $DELETED
1658
+ : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
1659
+ ? e[STORE_OVERRIDE][t] !== $DELETED
1660
+ : t in e[STORE_VALUE];
1661
+ getObserver() &&
1662
+ read(getNode(getNodes(e, STORE_HAS), t, n, e[STORE_FIREWALL], isEqual, e[STORE_OPTIMISTIC]));
1441
1663
  return n;
1442
1664
  },
1443
1665
  set(e, t, n) {
1444
1666
  const i = e[$PROXY];
1445
1667
  if (writeOnly(i)) {
1668
+ if (e[STORE_OPTIMISTIC]) {
1669
+ const t = e[STORE_FIREWALL];
1670
+ if (t?.X) {
1671
+ globalQueue.initTransition(t.X);
1672
+ }
1673
+ }
1446
1674
  untrack(() => {
1447
1675
  const r = e[STORE_VALUE];
1448
- const s = r[t];
1449
- const o = e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE] ? e[STORE_OVERRIDE][t] : s;
1450
- const u = n?.[$TARGET]?.[STORE_VALUE] ?? n;
1451
- if (o === u) return true;
1452
- const l = e[STORE_OVERRIDE]?.length || r.length;
1453
- if (u !== undefined && u === s) delete e[STORE_OVERRIDE][t];
1454
- else (e[STORE_OVERRIDE] || (e[STORE_OVERRIDE] = Object.create(null)))[t] = u;
1455
- const c = isWrappable(u);
1456
- if (isWrappable(o)) {
1457
- const e = PARENTS.get(o);
1458
- e && (e instanceof Set ? e.delete(i) : PARENTS.delete(o));
1676
+ const o = r[t];
1677
+ const s = e[STORE_OPTIMISTIC] && !projectionWriteActive;
1678
+ const u = s ? STORE_OPTIMISTIC_OVERRIDE : STORE_OVERRIDE;
1679
+ if (s) trackOptimisticStore(i);
1680
+ const l =
1681
+ e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
1682
+ ? e[STORE_OPTIMISTIC_OVERRIDE][t]
1683
+ : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
1684
+ ? e[STORE_OVERRIDE][t]
1685
+ : o;
1686
+ const c = n?.[$TARGET]?.[STORE_VALUE] ?? n;
1687
+ if (l === c) return true;
1688
+ const a = e[STORE_OPTIMISTIC_OVERRIDE]?.length || e[STORE_OVERRIDE]?.length || r.length;
1689
+ if (c !== undefined && c === o) delete e[u][t];
1690
+ else (e[u] || (e[u] = Object.create(null)))[t] = c;
1691
+ const f = isWrappable(c);
1692
+ if (isWrappable(l)) {
1693
+ const e = PARENTS.get(l);
1694
+ e && (e instanceof Set ? e.delete(i) : PARENTS.delete(l));
1459
1695
  }
1460
- if (recursivelyNotify(i, storeLookup) && c) recursivelyAddParent(u, i);
1696
+ if (recursivelyNotify(i, storeLookup) && f) recursivelyAddParent(c, i);
1461
1697
  e[STORE_HAS]?.[t] && setSignal(e[STORE_HAS][t], true);
1462
- const a = getNodes(e, STORE_NODE);
1463
- a[t] && setSignal(a[t], () => (c ? wrap(u, e) : u));
1698
+ const E = getNodes(e, STORE_NODE);
1699
+ E[t] && setSignal(E[t], () => (f ? wrap(c, e) : c));
1464
1700
  if (Array.isArray(r)) {
1465
- const e = parseInt(t) + 1;
1466
- if (e > l) a.length && setSignal(a.length, e);
1701
+ if (t === "length") {
1702
+ E.length && setSignal(E.length, c);
1703
+ } else {
1704
+ const e = parseInt(t) + 1;
1705
+ if (e > a) E.length && setSignal(E.length, e);
1706
+ }
1467
1707
  }
1468
- a[$TRACK] && setSignal(a[$TRACK], undefined);
1708
+ E[$TRACK] && setSignal(E[$TRACK], undefined);
1469
1709
  });
1470
1710
  }
1471
1711
  return true;
1472
1712
  },
1473
1713
  deleteProperty(e, t) {
1474
- if (writeOnly(e[$PROXY]) && e[STORE_OVERRIDE]?.[t] !== $DELETED) {
1714
+ const n = e[STORE_OPTIMISTIC_OVERRIDE]?.[t] === $DELETED;
1715
+ const i = e[STORE_OVERRIDE]?.[t] === $DELETED;
1716
+ if (writeOnly(e[$PROXY]) && !n && !i) {
1475
1717
  untrack(() => {
1476
- const n =
1477
- e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE] ? e[STORE_OVERRIDE][t] : e[STORE_VALUE][t];
1478
- if (t in e[STORE_VALUE]) {
1479
- (e[STORE_OVERRIDE] || (e[STORE_OVERRIDE] = Object.create(null)))[t] = $DELETED;
1480
- } else if (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]) {
1481
- delete e[STORE_OVERRIDE][t];
1718
+ const n = e[STORE_OPTIMISTIC] && !projectionWriteActive;
1719
+ const i = n ? STORE_OPTIMISTIC_OVERRIDE : STORE_OVERRIDE;
1720
+ if (n) trackOptimisticStore(e[$PROXY]);
1721
+ const r =
1722
+ e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
1723
+ ? e[STORE_OPTIMISTIC_OVERRIDE][t]
1724
+ : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
1725
+ ? e[STORE_OVERRIDE][t]
1726
+ : e[STORE_VALUE][t];
1727
+ if (t in e[STORE_VALUE] || (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE])) {
1728
+ (e[i] || (e[i] = Object.create(null)))[t] = $DELETED;
1729
+ } else if (e[i] && t in e[i]) {
1730
+ delete e[i][t];
1482
1731
  } else return true;
1483
- if (isWrappable(n)) {
1484
- const t = PARENTS.get(n);
1485
- t && (t instanceof Set ? t.delete(e) : PARENTS.delete(n));
1732
+ if (isWrappable(r)) {
1733
+ const t = PARENTS.get(r);
1734
+ t && (t instanceof Set ? t.delete(e) : PARENTS.delete(r));
1486
1735
  }
1487
1736
  if (e[STORE_HAS]?.[t]) setSignal(e[STORE_HAS][t], false);
1488
- const i = getNodes(e, STORE_NODE);
1489
- i[t] && setSignal(i[t], undefined);
1490
- i[$TRACK] && setSignal(i[$TRACK], undefined);
1737
+ const o = getNodes(e, STORE_NODE);
1738
+ o[t] && setSignal(o[t], undefined);
1739
+ o[$TRACK] && setSignal(o[$TRACK], undefined);
1491
1740
  });
1492
1741
  }
1493
1742
  return true;
1494
1743
  },
1495
1744
  ownKeys(e) {
1496
1745
  trackSelf(e);
1497
- return getKeys(e[STORE_VALUE], e[STORE_OVERRIDE], false);
1746
+ let t = getKeys(e[STORE_VALUE], e[STORE_OVERRIDE], false);
1747
+ if (e[STORE_OPTIMISTIC_OVERRIDE]) {
1748
+ const n = new Set(t);
1749
+ for (const t of Reflect.ownKeys(e[STORE_OPTIMISTIC_OVERRIDE])) {
1750
+ if (e[STORE_OPTIMISTIC_OVERRIDE][t] !== $DELETED) n.add(t);
1751
+ else n.delete(t);
1752
+ }
1753
+ t = Array.from(n);
1754
+ }
1755
+ return t;
1498
1756
  },
1499
1757
  getOwnPropertyDescriptor(e, t) {
1500
1758
  if (t === $PROXY) return { value: e[$PROXY], writable: true, configurable: true };
1759
+ if (e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]) {
1760
+ if (e[STORE_OPTIMISTIC_OVERRIDE][t] === $DELETED) return undefined;
1761
+ const n = getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
1762
+ if (n) {
1763
+ return { ...n, value: e[STORE_OPTIMISTIC_OVERRIDE][t] };
1764
+ }
1765
+ return {
1766
+ value: e[STORE_OPTIMISTIC_OVERRIDE][t],
1767
+ writable: true,
1768
+ enumerable: true,
1769
+ configurable: true
1770
+ };
1771
+ }
1501
1772
  return getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
1502
1773
  },
1503
1774
  getPrototypeOf(e) {
@@ -1576,8 +1847,8 @@ function recursivelyAddParent(e, t) {
1576
1847
  const t = getKeys(e, n);
1577
1848
  for (let i = 0; i < t.length; i++) {
1578
1849
  const r = t[i];
1579
- const s = n && r in n ? n[r] : e[r];
1580
- isWrappable(s) && recursivelyAddParent(s, e);
1850
+ const o = n && r in n ? n[r] : e[r];
1851
+ isWrappable(o) && recursivelyAddParent(o, e);
1581
1852
  }
1582
1853
  }
1583
1854
  }
@@ -1586,19 +1857,88 @@ function deep(e) {
1586
1857
  return e[$DEEP];
1587
1858
  }
1588
1859
  function createOptimisticStore(e, t, n) {
1589
- return [];
1860
+ GlobalQueue.Y ||= clearOptimisticStore;
1861
+ const i = typeof e === "function";
1862
+ const r = (i ? t : e) ?? {};
1863
+ const o = i ? e : undefined;
1864
+ const { store: s } = createOptimisticProjectionInternal(o, r, n);
1865
+ return [s, e => storeSetter(s, e)];
1866
+ }
1867
+ function clearOptimisticStore(e) {
1868
+ const t = e[$TARGET];
1869
+ if (!t || !t[STORE_OPTIMISTIC_OVERRIDE]) return;
1870
+ const n = t[STORE_OPTIMISTIC_OVERRIDE];
1871
+ const i = t[STORE_NODE];
1872
+ if (i) {
1873
+ for (const e of Reflect.ownKeys(n)) {
1874
+ if (i[e]) {
1875
+ const n =
1876
+ t[STORE_OVERRIDE] && e in t[STORE_OVERRIDE] ? t[STORE_OVERRIDE][e] : t[STORE_VALUE][e];
1877
+ const r = n === $DELETED ? undefined : n;
1878
+ setSignal(i[e], isWrappable(r) ? wrap(r, t) : r);
1879
+ }
1880
+ }
1881
+ i[$TRACK] && setSignal(i[$TRACK], undefined);
1882
+ }
1883
+ delete t[STORE_OPTIMISTIC_OVERRIDE];
1884
+ }
1885
+ function createOptimisticProjectionInternal(e, t = {}, n) {
1886
+ let i;
1887
+ const r = new WeakMap();
1888
+ const wrapper = e => {
1889
+ e[STORE_WRAP] = wrapProjection;
1890
+ e[STORE_LOOKUP] = r;
1891
+ e[STORE_OPTIMISTIC] = true;
1892
+ Object.defineProperty(e, STORE_FIREWALL, {
1893
+ get() {
1894
+ return i;
1895
+ },
1896
+ configurable: true
1897
+ });
1898
+ };
1899
+ const wrapProjection = e => {
1900
+ if (r.has(e)) return r.get(e);
1901
+ if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
1902
+ const t = createStoreProxy(e, storeTraps, wrapper);
1903
+ r.set(e, t);
1904
+ return t;
1905
+ };
1906
+ const o = wrapProjection(t);
1907
+ if (e) {
1908
+ i = computed(() => {
1909
+ const t = getOwner();
1910
+ setProjectionWriteActive(true);
1911
+ try {
1912
+ storeSetter(new Proxy(o, writeTraps), i => {
1913
+ const r = handleAsync(t, e(i), e => {
1914
+ setProjectionWriteActive(true);
1915
+ try {
1916
+ e !== i && e !== undefined && storeSetter(o, reconcile(e, n?.key || "id", n?.all));
1917
+ } finally {
1918
+ setProjectionWriteActive(false);
1919
+ }
1920
+ });
1921
+ r !== i && r !== undefined && reconcile(r, n?.key || "id", n?.all)(o);
1922
+ });
1923
+ } finally {
1924
+ setProjectionWriteActive(false);
1925
+ }
1926
+ });
1927
+ i.Se = true;
1928
+ }
1929
+ return { store: o, node: i };
1590
1930
  }
1591
1931
  function snapshot(e, t, n) {
1592
- let i, r, s, o, u, l;
1932
+ let i, r, o, s, u, l;
1593
1933
  if (!isWrappable(e)) return e;
1594
1934
  if (t && t.has(e)) return t.get(e);
1595
1935
  if (!t) t = new Map();
1596
1936
  if ((i = e[$TARGET] || n?.get(e)?.[$TARGET])) {
1597
- s = i[STORE_OVERRIDE];
1937
+ o = i[STORE_OVERRIDE];
1598
1938
  r = Array.isArray(i[STORE_VALUE]);
1599
1939
  t.set(
1600
1940
  e,
1601
- s ? (o = r ? [] : Object.create(Object.getPrototypeOf(i[STORE_VALUE]))) : i[STORE_VALUE]
1941
+ o ? (s = r ? [] : Object.create(Object.getPrototypeOf(i[STORE_VALUE]))) : i[STORE_VALUE]
1602
1942
  );
1603
1943
  e = i[STORE_VALUE];
1604
1944
  n = storeLookup;
@@ -1607,32 +1947,32 @@ function snapshot(e, t, n) {
1607
1947
  t.set(e, e);
1608
1948
  }
1609
1949
  if (r) {
1610
- const i = s?.length || e.length;
1950
+ const i = o?.length || e.length;
1611
1951
  for (let r = 0; r < i; r++) {
1612
- l = s && r in s ? s[r] : e[r];
1952
+ l = o && r in o ? o[r] : e[r];
1613
1953
  if (l === $DELETED) continue;
1614
- if ((u = snapshot(l, t, n)) !== l || o) {
1615
- if (!o) t.set(e, (o = [...e]));
1616
- o[r] = u;
1954
+ if ((u = snapshot(l, t, n)) !== l || s) {
1955
+ if (!s) t.set(e, (s = [...e]));
1956
+ s[r] = u;
1617
1957
  }
1618
1958
  }
1619
1959
  } else {
1620
- const i = getKeys(e, s);
1960
+ const i = getKeys(e, o);
1621
1961
  for (let r = 0, c = i.length; r < c; r++) {
1622
1962
  let c = i[r];
1623
- const a = getPropertyDescriptor(e, s, c);
1963
+ const a = getPropertyDescriptor(e, o, c);
1624
1964
  if (a.get) continue;
1625
- l = s && c in s ? s[c] : e[c];
1626
- if ((u = snapshot(l, t, n)) !== e[c] || o) {
1627
- if (!o) {
1628
- o = Object.create(Object.getPrototypeOf(e));
1629
- Object.assign(o, e);
1965
+ l = o && c in o ? o[c] : e[c];
1966
+ if ((u = snapshot(l, t, n)) !== e[c] || s) {
1967
+ if (!s) {
1968
+ s = Object.create(Object.getPrototypeOf(e));
1969
+ Object.assign(s, e);
1630
1970
  }
1631
- o[c] = u;
1971
+ s[c] = u;
1632
1972
  }
1633
1973
  }
1634
1974
  }
1635
- return o || e;
1975
+ return s || e;
1636
1976
  }
1637
1977
  function trueFn() {
1638
1978
  return true;
@@ -1674,8 +2014,8 @@ function merge(...e) {
1674
2014
  for (let i = 0; i < e.length; i++) {
1675
2015
  const r = e[i];
1676
2016
  t = t || (!!r && $PROXY in r);
1677
- const s = !!r && r[$SOURCES];
1678
- if (s) n.push(...s);
2017
+ const o = !!r && r[$SOURCES];
2018
+ if (o) n.push(...o);
1679
2019
  else n.push(typeof r === "function" ? ((t = true), createMemo(r)) : r);
1680
2020
  }
1681
2021
  if (SUPPORTS_PROXY && t) {
@@ -1705,35 +2045,35 @@ function merge(...e) {
1705
2045
  }
1706
2046
  const i = Object.create(null);
1707
2047
  let r = false;
1708
- let s = n.length - 1;
1709
- for (let e = s; e >= 0; e--) {
2048
+ let o = n.length - 1;
2049
+ for (let e = o; e >= 0; e--) {
1710
2050
  const t = n[e];
1711
2051
  if (!t) {
1712
- e === s && s--;
2052
+ e === o && o--;
1713
2053
  continue;
1714
2054
  }
1715
- const o = Object.getOwnPropertyNames(t);
1716
- for (let n = o.length - 1; n >= 0; n--) {
1717
- const u = o[n];
2055
+ const s = Object.getOwnPropertyNames(t);
2056
+ for (let n = s.length - 1; n >= 0; n--) {
2057
+ const u = s[n];
1718
2058
  if (u === "__proto__" || u === "constructor") continue;
1719
2059
  if (!i[u]) {
1720
- r = r || e !== s;
2060
+ r = r || e !== o;
1721
2061
  const n = Object.getOwnPropertyDescriptor(t, u);
1722
2062
  i[u] = n.get ? { enumerable: true, configurable: true, get: n.get.bind(t) } : n;
1723
2063
  }
1724
2064
  }
1725
2065
  }
1726
- if (!r) return n[s];
1727
- const o = {};
2066
+ if (!r) return n[o];
2067
+ const s = {};
1728
2068
  const u = Object.keys(i);
1729
2069
  for (let e = u.length - 1; e >= 0; e--) {
1730
2070
  const t = u[e],
1731
2071
  n = i[t];
1732
- if (n.get) Object.defineProperty(o, t, n);
1733
- else o[t] = n.value;
2072
+ if (n.get) Object.defineProperty(s, t, n);
2073
+ else s[t] = n.value;
1734
2074
  }
1735
- o[$SOURCES] = n;
1736
- return o;
2075
+ s[$SOURCES] = n;
2076
+ return s;
1737
2077
  }
1738
2078
  function omit(e, ...t) {
1739
2079
  const n = new Set(t);
@@ -1768,247 +2108,241 @@ function mapArray(e, t, n) {
1768
2108
  const i = typeof n?.keyed === "function" ? n.keyed : undefined;
1769
2109
  return createMemo(
1770
2110
  updateKeyedMap.bind({
1771
- ye: createOwner(),
1772
- Ce: 0,
1773
- De: e,
1774
- Pe: [],
1775
- we: t,
1776
- be: [],
1777
- Ve: [],
1778
- me: i,
1779
- Ue: i || n?.keyed === false ? [] : undefined,
1780
- ke: t.length > 1 ? [] : undefined,
1781
- ve: n?.fallback
2111
+ De: createOwner(),
2112
+ we: 0,
2113
+ be: e,
2114
+ ve: [],
2115
+ Ve: t,
2116
+ me: [],
2117
+ Ue: [],
2118
+ ke: i,
2119
+ We: i || n?.keyed === false ? [] : undefined,
2120
+ Qe: t.length > 1 ? [] : undefined,
2121
+ xe: n?.fallback
1782
2122
  })
1783
2123
  );
1784
2124
  }
1785
2125
  const pureOptions = { pureWrite: true };
1786
2126
  function updateKeyedMap() {
1787
- const e = this.De() || [],
2127
+ const e = this.be() || [],
1788
2128
  t = e.length;
1789
2129
  e[$TRACK];
1790
- runWithOwner(this.ye, () => {
2130
+ runWithOwner(this.De, () => {
1791
2131
  let n,
1792
2132
  i,
1793
- r = this.Ue
2133
+ r = this.We
1794
2134
  ? () => {
1795
- this.Ue[i] = signal(e[i], pureOptions);
1796
- this.ke && (this.ke[i] = signal(i, pureOptions));
1797
- return this.we(
1798
- read.bind(null, this.Ue[i]),
1799
- this.ke ? read.bind(null, this.ke[i]) : undefined
2135
+ this.We[i] = signal(e[i], pureOptions);
2136
+ this.Qe && (this.Qe[i] = signal(i, pureOptions));
2137
+ return this.Ve(
2138
+ read.bind(null, this.We[i]),
2139
+ this.Qe ? read.bind(null, this.Qe[i]) : undefined
1800
2140
  );
1801
2141
  }
1802
- : this.ke
2142
+ : this.Qe
1803
2143
  ? () => {
1804
2144
  const t = e[i];
1805
- this.ke[i] = signal(i, pureOptions);
1806
- return this.we(() => t, read.bind(null, this.ke[i]));
2145
+ this.Qe[i] = signal(i, pureOptions);
2146
+ return this.Ve(() => t, read.bind(null, this.Qe[i]));
1807
2147
  }
1808
2148
  : () => {
1809
2149
  const t = e[i];
1810
- return this.we(() => t);
2150
+ return this.Ve(() => t);
1811
2151
  };
1812
2152
  if (t === 0) {
1813
- if (this.Ce !== 0) {
1814
- this.ye.dispose(false);
1815
- this.Ve = [];
1816
- this.Pe = [];
1817
- this.be = [];
1818
- this.Ce = 0;
1819
- this.Ue && (this.Ue = []);
1820
- this.ke && (this.ke = []);
2153
+ if (this.we !== 0) {
2154
+ this.De.dispose(false);
2155
+ this.Ue = [];
2156
+ this.ve = [];
2157
+ this.me = [];
2158
+ this.we = 0;
2159
+ this.We && (this.We = []);
2160
+ this.Qe && (this.Qe = []);
1821
2161
  }
1822
- if (this.ve && !this.be[0]) {
1823
- this.be[0] = runWithOwner((this.Ve[0] = createOwner()), this.ve);
2162
+ if (this.xe && !this.me[0]) {
2163
+ this.me[0] = runWithOwner((this.Ue[0] = createOwner()), this.xe);
1824
2164
  }
1825
- } else if (this.Ce === 0) {
1826
- if (this.Ve[0]) this.Ve[0].dispose();
1827
- this.be = new Array(t);
2165
+ } else if (this.we === 0) {
2166
+ if (this.Ue[0]) this.Ue[0].dispose();
2167
+ this.me = new Array(t);
1828
2168
  for (i = 0; i < t; i++) {
1829
- this.Pe[i] = e[i];
1830
- this.be[i] = runWithOwner((this.Ve[i] = createOwner()), r);
2169
+ this.ve[i] = e[i];
2170
+ this.me[i] = runWithOwner((this.Ue[i] = createOwner()), r);
1831
2171
  }
1832
- this.Ce = t;
2172
+ this.we = t;
1833
2173
  } else {
1834
- let s,
1835
- o,
2174
+ let o,
2175
+ s,
1836
2176
  u,
1837
2177
  l,
1838
2178
  c,
1839
2179
  a,
1840
2180
  f,
1841
2181
  E = new Array(t),
1842
- d = new Array(t),
1843
- T = this.Ue ? new Array(t) : undefined,
1844
- R = this.ke ? new Array(t) : undefined;
2182
+ T = new Array(t),
2183
+ R = this.We ? new Array(t) : undefined,
2184
+ d = this.Qe ? new Array(t) : undefined;
1845
2185
  for (
1846
- s = 0, o = Math.min(this.Ce, t);
1847
- s < o && (this.Pe[s] === e[s] || (this.Ue && compare(this.me, this.Pe[s], e[s])));
1848
- s++
2186
+ o = 0, s = Math.min(this.we, t);
2187
+ o < s && (this.ve[o] === e[o] || (this.We && compare(this.ke, this.ve[o], e[o])));
2188
+ o++
1849
2189
  ) {
1850
- if (this.Ue) setSignal(this.Ue[s], e[s]);
2190
+ if (this.We) setSignal(this.We[o], e[o]);
1851
2191
  }
1852
2192
  for (
1853
- o = this.Ce - 1, u = t - 1;
1854
- o >= s &&
1855
- u >= s &&
1856
- (this.Pe[o] === e[u] || (this.Ue && compare(this.me, this.Pe[o], e[u])));
1857
- o--, u--
2193
+ s = this.we - 1, u = t - 1;
2194
+ s >= o &&
2195
+ u >= o &&
2196
+ (this.ve[s] === e[u] || (this.We && compare(this.ke, this.ve[s], e[u])));
2197
+ s--, u--
1858
2198
  ) {
1859
- E[u] = this.be[o];
1860
- d[u] = this.Ve[o];
1861
- T && (T[u] = this.Ue[o]);
1862
- R && (R[u] = this.ke[o]);
2199
+ E[u] = this.me[s];
2200
+ T[u] = this.Ue[s];
2201
+ R && (R[u] = this.We[s]);
2202
+ d && (d[u] = this.Qe[s]);
1863
2203
  }
1864
2204
  a = new Map();
1865
2205
  f = new Array(u + 1);
1866
- for (i = u; i >= s; i--) {
2206
+ for (i = u; i >= o; i--) {
1867
2207
  l = e[i];
1868
- c = this.me ? this.me(l) : l;
2208
+ c = this.ke ? this.ke(l) : l;
1869
2209
  n = a.get(c);
1870
2210
  f[i] = n === undefined ? -1 : n;
1871
2211
  a.set(c, i);
1872
2212
  }
1873
- for (n = s; n <= o; n++) {
1874
- l = this.Pe[n];
1875
- c = this.me ? this.me(l) : l;
2213
+ for (n = o; n <= s; n++) {
2214
+ l = this.ve[n];
2215
+ c = this.ke ? this.ke(l) : l;
1876
2216
  i = a.get(c);
1877
2217
  if (i !== undefined && i !== -1) {
1878
- E[i] = this.be[n];
1879
- d[i] = this.Ve[n];
1880
- T && (T[i] = this.Ue[n]);
1881
- R && (R[i] = this.ke[n]);
2218
+ E[i] = this.me[n];
2219
+ T[i] = this.Ue[n];
2220
+ R && (R[i] = this.We[n]);
2221
+ d && (d[i] = this.Qe[n]);
1882
2222
  i = f[i];
1883
2223
  a.set(c, i);
1884
- } else this.Ve[n].dispose();
2224
+ } else this.Ue[n].dispose();
1885
2225
  }
1886
- for (i = s; i < t; i++) {
2226
+ for (i = o; i < t; i++) {
1887
2227
  if (i in E) {
1888
- this.be[i] = E[i];
1889
- this.Ve[i] = d[i];
1890
- if (T) {
1891
- this.Ue[i] = T[i];
1892
- setSignal(this.Ue[i], e[i]);
1893
- }
2228
+ this.me[i] = E[i];
2229
+ this.Ue[i] = T[i];
1894
2230
  if (R) {
1895
- this.ke[i] = R[i];
1896
- setSignal(this.ke[i], i);
2231
+ this.We[i] = R[i];
2232
+ setSignal(this.We[i], e[i]);
2233
+ }
2234
+ if (d) {
2235
+ this.Qe[i] = d[i];
2236
+ setSignal(this.Qe[i], i);
1897
2237
  }
1898
2238
  } else {
1899
- this.be[i] = runWithOwner((this.Ve[i] = createOwner()), r);
2239
+ this.me[i] = runWithOwner((this.Ue[i] = createOwner()), r);
1900
2240
  }
1901
2241
  }
1902
- this.be = this.be.slice(0, (this.Ce = t));
1903
- this.Pe = e.slice(0);
2242
+ this.me = this.me.slice(0, (this.we = t));
2243
+ this.ve = e.slice(0);
1904
2244
  }
1905
2245
  });
1906
- return this.be;
2246
+ return this.me;
1907
2247
  }
1908
2248
  function repeat(e, t, n) {
1909
2249
  return updateRepeat.bind({
1910
- ye: createOwner(),
1911
- Ce: 0,
1912
- xe: 0,
1913
- Ge: e,
1914
- we: t,
1915
- Ve: [],
1916
- be: [],
1917
- He: n?.from,
1918
- ve: n?.fallback
2250
+ De: createOwner(),
2251
+ we: 0,
2252
+ Ge: 0,
2253
+ Me: e,
2254
+ Ve: t,
2255
+ Ue: [],
2256
+ me: [],
2257
+ $e: n?.from,
2258
+ xe: n?.fallback
1919
2259
  });
1920
2260
  }
1921
2261
  function updateRepeat() {
1922
- const e = this.Ge();
1923
- const t = this.He?.() || 0;
1924
- runWithOwner(this.ye, () => {
2262
+ const e = this.Me();
2263
+ const t = this.$e?.() || 0;
2264
+ runWithOwner(this.De, () => {
1925
2265
  if (e === 0) {
1926
- if (this.Ce !== 0) {
1927
- this.ye.dispose(false);
1928
- this.Ve = [];
1929
- this.be = [];
1930
- this.Ce = 0;
2266
+ if (this.we !== 0) {
2267
+ this.De.dispose(false);
2268
+ this.Ue = [];
2269
+ this.me = [];
2270
+ this.we = 0;
1931
2271
  }
1932
- if (this.ve && !this.be[0]) {
1933
- this.be[0] = runWithOwner((this.Ve[0] = createOwner()), this.ve);
2272
+ if (this.xe && !this.me[0]) {
2273
+ this.me[0] = runWithOwner((this.Ue[0] = createOwner()), this.xe);
1934
2274
  }
1935
2275
  return;
1936
2276
  }
1937
2277
  const n = t + e;
1938
- const i = this.xe + this.Ce;
1939
- if (this.Ce === 0 && this.Ve[0]) this.Ve[0].dispose();
1940
- for (let e = n; e < i; e++) this.Ve[e - this.xe].dispose();
1941
- if (this.xe < t) {
1942
- let e = this.xe;
1943
- while (e < t && e < this.Ce) this.Ve[e++].dispose();
1944
- this.Ve.splice(0, t - this.xe);
1945
- this.be.splice(0, t - this.xe);
1946
- } else if (this.xe > t) {
1947
- let n = i - this.xe - 1;
1948
- let r = this.xe - t;
1949
- this.Ve.length = this.be.length = e;
2278
+ const i = this.Ge + this.we;
2279
+ if (this.we === 0 && this.Ue[0]) this.Ue[0].dispose();
2280
+ for (let e = n; e < i; e++) this.Ue[e - this.Ge].dispose();
2281
+ if (this.Ge < t) {
2282
+ let e = this.Ge;
2283
+ while (e < t && e < this.we) this.Ue[e++].dispose();
2284
+ this.Ue.splice(0, t - this.Ge);
2285
+ this.me.splice(0, t - this.Ge);
2286
+ } else if (this.Ge > t) {
2287
+ let n = i - this.Ge - 1;
2288
+ let r = this.Ge - t;
2289
+ this.Ue.length = this.me.length = e;
1950
2290
  while (n >= r) {
1951
- this.Ve[n] = this.Ve[n - r];
1952
- this.be[n] = this.be[n - r];
2291
+ this.Ue[n] = this.Ue[n - r];
2292
+ this.me[n] = this.me[n - r];
1953
2293
  n--;
1954
2294
  }
1955
2295
  for (let e = 0; e < r; e++) {
1956
- this.be[e] = runWithOwner((this.Ve[e] = createOwner()), () => this.we(e + t));
2296
+ this.me[e] = runWithOwner((this.Ue[e] = createOwner()), () => this.Ve(e + t));
1957
2297
  }
1958
2298
  }
1959
2299
  for (let e = i; e < n; e++) {
1960
- this.be[e - t] = runWithOwner((this.Ve[e - t] = createOwner()), () => this.we(e));
2300
+ this.me[e - t] = runWithOwner((this.Ue[e - t] = createOwner()), () => this.Ve(e));
1961
2301
  }
1962
- this.be = this.be.slice(0, e);
1963
- this.xe = t;
1964
- this.Ce = e;
2302
+ this.me = this.me.slice(0, e);
2303
+ this.Ge = t;
2304
+ this.we = e;
1965
2305
  });
1966
- return this.be;
2306
+ return this.me;
1967
2307
  }
1968
2308
  function compare(e, t, n) {
1969
2309
  return e ? e(t) === e(n) : true;
1970
2310
  }
1971
2311
  function boundaryComputed(e, t) {
1972
- const n = computed(e, undefined, {
1973
- pe: {
1974
- le() {
1975
- let e = this.J;
1976
- this.J &= ~this.Qe;
1977
- if (this.Qe & STATUS_PENDING && !(this.J & STATUS_UNINITIALIZED)) {
1978
- e &= ~STATUS_PENDING;
1979
- }
1980
- this._e.notify(this, this.Qe, e);
1981
- },
1982
- Qe: t
1983
- }
1984
- });
1985
- n.Qe = t;
1986
- n.Te = true;
2312
+ const n = computed(e, undefined, { lazy: true });
2313
+ n.Te = () => {
2314
+ const e = n.ie;
2315
+ n.ie &= ~n.Le;
2316
+ n.J.notify(n, n.Le, e);
2317
+ };
2318
+ n.Le = t;
2319
+ n.Se = true;
2320
+ recompute(n, true);
1987
2321
  return n;
1988
2322
  }
1989
2323
  function createBoundChildren(e, t, n, i) {
1990
- const r = e._e;
1991
- r.addChild((e._e = n));
1992
- onCleanup(() => r.removeChild(e._e));
2324
+ const r = e.J;
2325
+ r.addChild((e.J = n));
2326
+ onCleanup(() => r.removeChild(e.J));
1993
2327
  return runWithOwner(e, () => {
1994
2328
  const e = computed(t);
1995
2329
  return boundaryComputed(() => staleValues(() => flatten(read(e))), i);
1996
2330
  });
1997
2331
  }
1998
2332
  class ConditionalQueue extends Queue {
1999
- Le;
2000
- $e = new Set();
2333
+ He;
2334
+ Fe = new Set();
2001
2335
  L = new Set();
2002
2336
  constructor(e) {
2003
2337
  super();
2004
- this.Le = e;
2338
+ this.He = e;
2005
2339
  }
2006
2340
  run(e) {
2007
- if (!e || read(this.Le)) return;
2341
+ if (!e || read(this.He)) return;
2008
2342
  return super.run(e);
2009
2343
  }
2010
2344
  notify(e, t, n) {
2011
- if (read(this.Le)) {
2345
+ if (read(this.He)) {
2012
2346
  if (t & STATUS_PENDING) {
2013
2347
  if (n & STATUS_PENDING) {
2014
2348
  this.L.add(e);
@@ -2017,37 +2351,37 @@ class ConditionalQueue extends Queue {
2017
2351
  }
2018
2352
  if (t & STATUS_ERROR) {
2019
2353
  if (n & STATUS_ERROR) {
2020
- this.$e.add(e);
2354
+ this.Fe.add(e);
2021
2355
  t &= ~STATUS_ERROR;
2022
- } else if (this.$e.delete(e)) t &= ~STATUS_ERROR;
2356
+ } else if (this.Fe.delete(e)) t &= ~STATUS_ERROR;
2023
2357
  }
2024
2358
  }
2025
2359
  return t ? super.notify(e, t, n) : true;
2026
2360
  }
2027
2361
  }
2028
2362
  class CollectionQueue extends Queue {
2029
- Fe;
2030
- Ve = new Set();
2031
- Le = signal(false, { pureWrite: true });
2032
- We = false;
2363
+ je;
2364
+ Ue = new Set();
2365
+ He = signal(false, { pureWrite: true });
2366
+ Ke = false;
2033
2367
  constructor(e) {
2034
2368
  super();
2035
- this.Fe = e;
2369
+ this.je = e;
2036
2370
  }
2037
2371
  run(e) {
2038
- if (!e || read(this.Le)) return;
2372
+ if (!e || read(this.He)) return;
2039
2373
  return super.run(e);
2040
2374
  }
2041
2375
  notify(e, t, n) {
2042
- if (!(t & this.Fe) || (this.Fe & STATUS_PENDING && this.We)) return super.notify(e, t, n);
2043
- if (n & this.Fe) {
2044
- this.Ve.add(e);
2045
- if (this.Ve.size === 1) setSignal(this.Le, true);
2046
- } else if (this.Ve.size > 0) {
2047
- this.Ve.delete(e);
2048
- if (this.Ve.size === 0) setSignal(this.Le, false);
2049
- }
2050
- t &= ~this.Fe;
2376
+ if (!(t & this.je) || (this.je & STATUS_PENDING && this.Ke)) return super.notify(e, t, n);
2377
+ if (n & this.je) {
2378
+ this.Ue.add(e);
2379
+ if (this.Ue.size === 1) setSignal(this.He, true);
2380
+ } else if (this.Ue.size > 0) {
2381
+ this.Ue.delete(e);
2382
+ if (this.Ue.size === 0) setSignal(this.He, false);
2383
+ }
2384
+ t &= ~this.je;
2051
2385
  return t ? super.notify(e, t, n) : true;
2052
2386
  }
2053
2387
  }
@@ -2061,53 +2395,55 @@ function createBoundary(e, t) {
2061
2395
  const i = new ConditionalQueue(computed(() => t() === BoundaryMode.HIDDEN));
2062
2396
  const r = createBoundChildren(n, e, i, 0);
2063
2397
  computed(() => {
2064
- const e = read(i.Le);
2065
- r.Qe = e ? STATUS_ERROR | STATUS_PENDING : 0;
2398
+ const e = read(i.He);
2399
+ r.Le = e ? STATUS_ERROR | STATUS_PENDING : 0;
2066
2400
  if (!e) {
2067
2401
  i.L.forEach(e => i.notify(e, STATUS_PENDING, STATUS_PENDING));
2068
- i.$e.forEach(e => i.notify(e, STATUS_ERROR, STATUS_ERROR));
2402
+ i.Fe.forEach(e => i.notify(e, STATUS_ERROR, STATUS_ERROR));
2069
2403
  i.L.clear();
2070
- i.$e.clear();
2404
+ i.Fe.clear();
2071
2405
  }
2072
2406
  });
2073
- return () => (read(i.Le) ? undefined : read(r));
2407
+ return () => (read(i.He) ? undefined : read(r));
2074
2408
  }
2075
2409
  function createCollectionBoundary(e, t, n) {
2076
2410
  const i = createOwner();
2077
2411
  const r = new CollectionQueue(e);
2078
- const s = createBoundChildren(i, t, r, e);
2079
- const o = computed(() => {
2080
- if (!read(r.Le)) {
2081
- const e = read(s);
2082
- if (!untrack(() => read(r.Le))) r.We = true;
2083
- return e;
2412
+ const o = createBoundChildren(i, t, r, e);
2413
+ const s = computed(() => {
2414
+ if (!read(r.He)) {
2415
+ const e = read(o);
2416
+ if (!untrack(() => read(r.He))) {
2417
+ r.Ke = true;
2418
+ return e;
2419
+ }
2084
2420
  }
2085
2421
  return n(r);
2086
2422
  });
2087
- return read.bind(null, o);
2423
+ return read.bind(null, s);
2088
2424
  }
2089
2425
  function createLoadBoundary(e, t) {
2090
2426
  return createCollectionBoundary(STATUS_PENDING, e, () => t());
2091
2427
  }
2092
2428
  function collectErrorSources(e, t) {
2093
2429
  let n = true;
2094
- let i = e.D;
2430
+ let i = e.C;
2095
2431
  while (i !== null) {
2096
2432
  const e = i.V;
2097
- if (e.D && e.J & STATUS_ERROR) {
2433
+ if (e.C && e.ie & STATUS_ERROR) {
2098
2434
  n = false;
2099
2435
  collectErrorSources(e, t);
2100
2436
  }
2101
- i = i.P;
2437
+ i = i.D;
2102
2438
  }
2103
2439
  n && t.push(e);
2104
2440
  }
2105
2441
  function createErrorBoundary(e, t) {
2106
2442
  return createCollectionBoundary(STATUS_ERROR, e, e => {
2107
- let n = e.Ve.values().next().value;
2108
- return t(n.j, () => {
2443
+ let n = e.Ue.values().next().value;
2444
+ return t(n.B, () => {
2109
2445
  const t = [];
2110
- for (const n of e.Ve) collectErrorSources(n, t);
2446
+ for (const n of e.Ue) collectErrorSources(n, t);
2111
2447
  for (const e of t) recompute(e);
2112
2448
  schedule();
2113
2449
  });
@@ -2137,9 +2473,9 @@ function flatten(e, t) {
2137
2473
  function flattenArray(e, t = [], n) {
2138
2474
  let i = null;
2139
2475
  let r = false;
2140
- for (let s = 0; s < e.length; s++) {
2476
+ for (let o = 0; o < e.length; o++) {
2141
2477
  try {
2142
- let i = e[s];
2478
+ let i = e[o];
2143
2479
  if (typeof i === "function" && !i.length) {
2144
2480
  if (n?.doNotUnwrap) {
2145
2481
  t.push(i);