@solidjs/signals 0.8.3 → 0.8.4

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/dev.js CHANGED
@@ -1,124 +1,116 @@
1
- // src/core/error.ts
2
- var NotReadyError = class extends Error {
1
+ class NotReadyError extends Error {
2
+ cause;
3
3
  constructor(cause) {
4
4
  super();
5
5
  this.cause = cause;
6
6
  }
7
- };
8
- var NoOwnerError = class extends Error {
7
+ }
8
+ class NoOwnerError extends Error {
9
9
  constructor() {
10
- super("Context can only be accessed under a reactive root." );
10
+ super("Context can only be accessed under a reactive root.");
11
11
  }
12
- };
13
- var ContextNotFoundError = class extends Error {
12
+ }
13
+ class ContextNotFoundError extends Error {
14
14
  constructor() {
15
15
  super(
16
- "Context must either be created with a default value or a value must be provided before accessing it."
16
+ "Context must either be created with a default value or a value must be provided before accessing it."
17
17
  );
18
18
  }
19
- };
20
-
21
- // src/core/constants.ts
22
- var NOT_PENDING = {};
23
- var SUPPORTS_PROXY = typeof Proxy === "function";
24
-
25
- // src/core/heap.ts
19
+ }
20
+ const REACTIVE_NONE = 0;
21
+ const REACTIVE_CHECK = 1 << 0;
22
+ const REACTIVE_DIRTY = 1 << 1;
23
+ const REACTIVE_RECOMPUTING_DEPS = 1 << 2;
24
+ const REACTIVE_IN_HEAP = 1 << 3;
25
+ const REACTIVE_IN_HEAP_HEIGHT = 1 << 4;
26
+ const REACTIVE_ZOMBIE = 1 << 5;
27
+ const REACTIVE_DISPOSED = 1 << 6;
28
+ const STATUS_NONE = 0;
29
+ const STATUS_PENDING = 1 << 0;
30
+ const STATUS_ERROR = 1 << 1;
31
+ const STATUS_UNINITIALIZED = 1 << 2;
32
+ const EFFECT_RENDER = 1;
33
+ const EFFECT_USER = 2;
34
+ const NOT_PENDING = {};
35
+ const SUPPORTS_PROXY = typeof Proxy === "function";
36
+ const defaultContext = {};
26
37
  function actualInsertIntoHeap(n, heap) {
27
- const parentHeight = (n._parent?._root ? n._parent._parentComputed?._height : n._parent?._height) ?? -1;
28
- if (parentHeight >= n._height)
29
- n._height = parentHeight + 1;
38
+ const parentHeight =
39
+ (n._parent?._root ? n._parent._parentComputed?._height : n._parent?._height) ?? -1;
40
+ if (parentHeight >= n._height) n._height = parentHeight + 1;
30
41
  const height = n._height;
31
42
  const heapAtHeight = heap._heap[height];
32
- if (heapAtHeight === void 0) {
33
- heap._heap[height] = n;
34
- } else {
43
+ if (heapAtHeight === undefined) heap._heap[height] = n;
44
+ else {
35
45
  const tail = heapAtHeight._prevHeap;
36
46
  tail._nextHeap = n;
37
47
  n._prevHeap = tail;
38
48
  heapAtHeight._prevHeap = n;
39
49
  }
40
- if (height > heap._max) {
41
- heap._max = height;
42
- }
50
+ if (height > heap._max) heap._max = height;
43
51
  }
44
52
  function insertIntoHeap(n, heap) {
45
53
  let flags = n._flags;
46
- if (flags & (8 /* InHeap */ | 4 /* RecomputingDeps */))
47
- return;
48
- if (flags & 1 /* Check */) {
49
- n._flags = flags & ~(1 /* Check */ | 2 /* Dirty */) | 2 /* Dirty */ | 8 /* InHeap */;
50
- } else
51
- n._flags = flags | 8 /* InHeap */;
52
- if (!(flags & 16 /* InHeapHeight */)) {
53
- actualInsertIntoHeap(n, heap);
54
- }
54
+ if (flags & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS)) return;
55
+ if (flags & REACTIVE_CHECK) {
56
+ n._flags = (flags & -4) | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
57
+ } else n._flags = flags | REACTIVE_IN_HEAP;
58
+ if (!(flags & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(n, heap);
55
59
  }
56
60
  function insertIntoHeapHeight(n, heap) {
57
61
  let flags = n._flags;
58
- if (flags & (8 /* InHeap */ | 4 /* RecomputingDeps */ | 16 /* InHeapHeight */))
59
- return;
60
- n._flags = flags | 16 /* InHeapHeight */;
62
+ if (flags & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT)) return;
63
+ n._flags = flags | REACTIVE_IN_HEAP_HEIGHT;
61
64
  actualInsertIntoHeap(n, heap);
62
65
  }
63
66
  function deleteFromHeap(n, heap) {
64
67
  const flags = n._flags;
65
- if (!(flags & (8 /* InHeap */ | 16 /* InHeapHeight */)))
66
- return;
67
- n._flags = flags & ~(8 /* InHeap */ | 16 /* InHeapHeight */);
68
+ if (!(flags & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
69
+ n._flags = flags & -25;
68
70
  const height = n._height;
69
- if (n._prevHeap === n) {
70
- heap._heap[height] = void 0;
71
- } else {
71
+ if (n._prevHeap === n) heap._heap[height] = undefined;
72
+ else {
72
73
  const next = n._nextHeap;
73
74
  const dhh = heap._heap[height];
74
75
  const end = next ?? dhh;
75
- if (n === dhh) {
76
- heap._heap[height] = next;
77
- } else {
78
- n._prevHeap._nextHeap = next;
79
- }
76
+ if (n === dhh) heap._heap[height] = next;
77
+ else n._prevHeap._nextHeap = next;
80
78
  end._prevHeap = n._prevHeap;
81
79
  }
82
80
  n._prevHeap = n;
83
- n._nextHeap = void 0;
81
+ n._nextHeap = undefined;
84
82
  }
85
83
  function markHeap(heap) {
86
- if (heap._marked)
87
- return;
84
+ if (heap._marked) return;
88
85
  heap._marked = true;
89
86
  for (let i = 0; i <= heap._max; i++) {
90
- for (let el = heap._heap[i]; el !== void 0; el = el._nextHeap) {
91
- if (el._flags & 8 /* InHeap */)
92
- markNode(el);
87
+ for (let el = heap._heap[i]; el !== undefined; el = el._nextHeap) {
88
+ if (el._flags & REACTIVE_IN_HEAP) markNode(el);
93
89
  }
94
90
  }
95
91
  }
96
- function markNode(el, newState = 2 /* Dirty */) {
92
+ function markNode(el, newState = REACTIVE_DIRTY) {
97
93
  const flags = el._flags;
98
- if ((flags & (1 /* Check */ | 2 /* Dirty */)) >= newState)
99
- return;
100
- el._flags = flags & ~(1 /* Check */ | 2 /* Dirty */) | newState;
101
- for (let link2 = el._subs; link2 !== null; link2 = link2._nextSub) {
102
- markNode(link2._sub, 1 /* Check */);
94
+ if ((flags & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= newState) return;
95
+ el._flags = (flags & -4) | newState;
96
+ for (let link = el._subs; link !== null; link = link._nextSub) {
97
+ markNode(link._sub, REACTIVE_CHECK);
103
98
  }
104
99
  if (el._child !== null) {
105
100
  for (let child = el._child; child !== null; child = child._nextChild) {
106
- for (let link2 = child._subs; link2 !== null; link2 = link2._nextSub) {
107
- markNode(link2._sub, 1 /* Check */);
101
+ for (let link = child._subs; link !== null; link = link._nextSub) {
102
+ markNode(link._sub, REACTIVE_CHECK);
108
103
  }
109
104
  }
110
105
  }
111
106
  }
112
- function runHeap(heap, recompute2) {
107
+ function runHeap(heap, recompute) {
113
108
  heap._marked = false;
114
109
  for (heap._min = 0; heap._min <= heap._max; heap._min++) {
115
110
  let el = heap._heap[heap._min];
116
- while (el !== void 0) {
117
- if (el._flags & 8 /* InHeap */)
118
- recompute2(el);
119
- else {
120
- adjustHeight(el, heap);
121
- }
111
+ while (el !== undefined) {
112
+ if (el._flags & REACTIVE_IN_HEAP) recompute(el);
113
+ else adjustHeight(el, heap);
122
114
  el = heap._heap[heap._min];
123
115
  }
124
116
  }
@@ -130,11 +122,7 @@ function adjustHeight(el, heap) {
130
122
  for (let d = el._deps; d; d = d._nextDep) {
131
123
  const dep1 = d._dep;
132
124
  const dep = dep1._firewall || dep1;
133
- if (dep._fn) {
134
- if (dep._height >= newHeight) {
135
- newHeight = dep._height + 1;
136
- }
137
- }
125
+ if (dep._fn && dep._height >= newHeight) newHeight = dep._height + 1;
138
126
  }
139
127
  if (el._height !== newHeight) {
140
128
  el._height = newHeight;
@@ -143,32 +131,18 @@ function adjustHeight(el, heap) {
143
131
  }
144
132
  }
145
133
  }
146
-
147
- // src/core/scheduler.ts
148
- var clock = 0;
149
- var activeTransition = null;
150
- var transitions = /* @__PURE__ */ new Set();
151
- var scheduled = false;
134
+ const transitions = new Set();
135
+ const dirtyQueue = { _heap: new Array(2e3).fill(undefined), _marked: false, _min: 0, _max: 0 };
136
+ const zombieQueue = { _heap: new Array(2e3).fill(undefined), _marked: false, _min: 0, _max: 0 };
137
+ let clock = 0;
138
+ let activeTransition = null;
139
+ let scheduled = false;
152
140
  function schedule() {
153
- if (scheduled)
154
- return;
141
+ if (scheduled) return;
155
142
  scheduled = true;
156
- if (!globalQueue._running)
157
- queueMicrotask(flush);
158
- }
159
- var dirtyQueue = {
160
- _heap: new Array(2e3).fill(void 0),
161
- _marked: false,
162
- _min: 0,
163
- _max: 0
164
- };
165
- var zombieQueue = {
166
- _heap: new Array(2e3).fill(void 0),
167
- _marked: false,
168
- _min: 0,
169
- _max: 0
170
- };
171
- var Queue = class {
143
+ if (!globalQueue._running) queueMicrotask(flush);
144
+ }
145
+ class Queue {
172
146
  _parent = null;
173
147
  _queues = [[], []];
174
148
  _children = [];
@@ -185,8 +159,7 @@ var Queue = class {
185
159
  }
186
160
  }
187
161
  notify(node, mask, flags) {
188
- if (this._parent)
189
- return this._parent.notify(node, mask, flags);
162
+ if (this._parent) return this._parent.notify(node, mask, flags);
190
163
  return false;
191
164
  }
192
165
  run(type) {
@@ -200,8 +173,7 @@ var Queue = class {
200
173
  }
201
174
  }
202
175
  enqueue(type, fn) {
203
- if (type)
204
- this._queues[type - 1].push(fn);
176
+ if (type) this._queues[type - 1].push(fn);
205
177
  schedule();
206
178
  }
207
179
  stashQueues(stub) {
@@ -224,62 +196,58 @@ var Queue = class {
224
196
  for (let i = 0; i < stub._children.length; i++) {
225
197
  const childStub = stub._children[i];
226
198
  let child = this._children[i];
227
- if (child)
228
- child.restoreQueues(childStub);
199
+ if (child) child.restoreQueues(childStub);
229
200
  }
230
201
  }
231
- };
232
- var GlobalQueue = class _GlobalQueue extends Queue {
202
+ }
203
+ class GlobalQueue extends Queue {
233
204
  _running = false;
234
205
  _pendingNodes = [];
235
206
  static _update;
236
207
  static _dispose;
237
208
  flush() {
238
- if (this._running)
239
- return;
209
+ if (this._running) return;
240
210
  this._running = true;
241
211
  try {
242
- runHeap(dirtyQueue, _GlobalQueue._update);
212
+ runHeap(dirtyQueue, GlobalQueue._update);
243
213
  if (activeTransition) {
244
214
  if (!transitionComplete(activeTransition)) {
245
- runHeap(zombieQueue, _GlobalQueue._update);
246
- globalQueue._pendingNodes = [];
247
- globalQueue.stashQueues(activeTransition.queueStash);
215
+ runHeap(zombieQueue, GlobalQueue._update);
216
+ this._pendingNodes = [];
217
+ this.stashQueues(activeTransition.queueStash);
248
218
  clock++;
249
219
  scheduled = false;
250
220
  runPending(activeTransition.pendingNodes, true);
251
221
  activeTransition = null;
252
222
  return;
253
223
  }
254
- globalQueue._pendingNodes.push(...activeTransition.pendingNodes);
255
- globalQueue.restoreQueues(activeTransition.queueStash);
224
+ this._pendingNodes.push(...activeTransition.pendingNodes);
225
+ this.restoreQueues(activeTransition.queueStash);
256
226
  transitions.delete(activeTransition);
257
227
  activeTransition = null;
258
- if (runPending(globalQueue._pendingNodes, false))
259
- runHeap(dirtyQueue, _GlobalQueue._update);
260
- } else if (transitions.size)
261
- runHeap(zombieQueue, _GlobalQueue._update);
262
- for (let i = 0; i < globalQueue._pendingNodes.length; i++) {
263
- const n = globalQueue._pendingNodes[i];
228
+ if (runPending(this._pendingNodes, false)) runHeap(dirtyQueue, GlobalQueue._update);
229
+ } else if (transitions.size) runHeap(zombieQueue, GlobalQueue._update);
230
+ for (let i = 0; i < this._pendingNodes.length; i++) {
231
+ const n = this._pendingNodes[i];
264
232
  if (n._pendingValue !== NOT_PENDING) {
265
233
  n._value = n._pendingValue;
266
234
  n._pendingValue = NOT_PENDING;
235
+ if (n._type) n._modified = true;
267
236
  }
268
- if (n._fn)
269
- _GlobalQueue._dispose(n, false, true);
237
+ if (n._fn) GlobalQueue._dispose(n, false, true);
270
238
  }
271
- globalQueue._pendingNodes.length = 0;
239
+ this._pendingNodes.length = 0;
272
240
  clock++;
273
241
  scheduled = false;
274
- this.run(1 /* Render */);
275
- this.run(2 /* User */);
242
+ this.run(EFFECT_RENDER);
243
+ this.run(EFFECT_USER);
276
244
  } finally {
277
245
  this._running = false;
278
246
  }
279
247
  }
280
248
  notify(node, mask, flags) {
281
- if (mask & 1 /* Pending */) {
282
- if (flags & 1 /* Pending */) {
249
+ if (mask & STATUS_PENDING) {
250
+ if (flags & STATUS_PENDING) {
283
251
  if (activeTransition && !activeTransition.asyncNodes.includes(node._error.cause))
284
252
  activeTransition.asyncNodes.push(node._error.cause);
285
253
  }
@@ -288,8 +256,7 @@ var GlobalQueue = class _GlobalQueue extends Queue {
288
256
  return false;
289
257
  }
290
258
  initTransition(node) {
291
- if (activeTransition && activeTransition.time === clock)
292
- return;
259
+ if (activeTransition && activeTransition.time === clock) return;
293
260
  if (!activeTransition) {
294
261
  activeTransition = node._transition ?? {
295
262
  time: clock,
@@ -300,14 +267,14 @@ var GlobalQueue = class _GlobalQueue extends Queue {
300
267
  }
301
268
  transitions.add(activeTransition);
302
269
  activeTransition.time = clock;
303
- for (let i = 0; i < globalQueue._pendingNodes.length; i++) {
304
- const n = globalQueue._pendingNodes[i];
270
+ for (let i = 0; i < this._pendingNodes.length; i++) {
271
+ const n = this._pendingNodes[i];
305
272
  n._transition = activeTransition;
306
273
  activeTransition.pendingNodes.push(n);
307
274
  }
308
- globalQueue._pendingNodes = activeTransition.pendingNodes;
275
+ this._pendingNodes = activeTransition.pendingNodes;
309
276
  }
310
- };
277
+ }
311
278
  function runPending(pendingNodes, value) {
312
279
  let needsReset = false;
313
280
  const p = pendingNodes.slice();
@@ -318,52 +285,57 @@ function runPending(pendingNodes, value) {
318
285
  n._pendingCheck._set(value);
319
286
  needsReset = true;
320
287
  }
288
+ if (n._pendingSignal && n._pendingSignal._pendingValue !== NOT_PENDING) {
289
+ n._pendingSignal._set(n._pendingSignal._pendingValue);
290
+ n._pendingSignal._pendingValue = NOT_PENDING;
291
+ needsReset = true;
292
+ }
321
293
  }
322
294
  return needsReset;
323
295
  }
324
- var globalQueue = new GlobalQueue();
296
+ const globalQueue = new GlobalQueue();
325
297
  function flush() {
326
298
  let count = 0;
327
299
  while (scheduled) {
328
- if (++count === 1e5)
329
- throw new Error("Potential Infinite Loop Detected.");
300
+ if (++count === 1e5) throw new Error("Potential Infinite Loop Detected.");
330
301
  globalQueue.flush();
331
302
  }
332
303
  }
333
304
  function runQueue(queue, type) {
334
- for (let i = 0; i < queue.length; i++)
335
- queue[i](type);
305
+ for (let i = 0; i < queue.length; i++) queue[i](type);
336
306
  }
337
307
  function transitionComplete(transition) {
338
308
  let done = true;
339
309
  for (let i = 0; i < transition.asyncNodes.length; i++) {
340
- if (transition.asyncNodes[i]._statusFlags & 1 /* Pending */) {
310
+ if (transition.asyncNodes[i]._statusFlags & STATUS_PENDING) {
341
311
  done = false;
342
312
  break;
343
313
  }
344
314
  }
345
315
  return done;
346
316
  }
347
-
348
- // src/core/core.ts
317
+ function runInTransition(el, recompute) {
318
+ const prevTransition = activeTransition;
319
+ activeTransition = el._transition;
320
+ recompute(el);
321
+ activeTransition = prevTransition;
322
+ }
349
323
  GlobalQueue._update = recompute;
350
324
  GlobalQueue._dispose = disposeChildren;
351
- var tracking = false;
352
- var stale = false;
353
- var pendingValueCheck = false;
354
- var pendingCheck = null;
355
- var context = null;
356
- var defaultContext = {};
325
+ let tracking = false;
326
+ let stale = false;
327
+ let pendingValueCheck = false;
328
+ let pendingCheck = null;
329
+ let context = null;
357
330
  function notifySubs(node) {
358
331
  for (let s = node._subs; s !== null; s = s._nextSub) {
359
- const queue = s._sub._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue;
360
- if (queue._min > s._sub._height)
361
- queue._min = s._sub._height;
332
+ const queue = s._sub._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
333
+ if (queue._min > s._sub._height) queue._min = s._sub._height;
362
334
  insertIntoHeap(s._sub, queue);
363
335
  }
364
336
  }
365
337
  function recompute(el, create = false) {
366
- deleteFromHeap(el, el._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
338
+ deleteFromHeap(el, el._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
367
339
  if (el._pendingValue !== NOT_PENDING || el._pendingFirstChild || el._pendingDisposal)
368
340
  disposeChildren(el);
369
341
  else {
@@ -377,29 +349,27 @@ function recompute(el, create = false) {
377
349
  const oldcontext = context;
378
350
  context = el;
379
351
  el._depsTail = null;
380
- el._flags = 4 /* RecomputingDeps */;
352
+ el._flags = REACTIVE_RECOMPUTING_DEPS;
381
353
  el._time = clock;
382
354
  let value = el._pendingValue === NOT_PENDING ? el._value : el._pendingValue;
383
355
  let oldHeight = el._height;
384
356
  let prevStatusFlags = el._statusFlags;
385
357
  let prevError = el._error;
386
358
  let prevTracking = tracking;
387
- clearStatusFlags(el);
359
+ setStatusFlags(el, STATUS_NONE | (prevStatusFlags & STATUS_UNINITIALIZED));
388
360
  tracking = true;
389
361
  try {
390
362
  value = el._fn(value);
363
+ el._statusFlags &= ~STATUS_UNINITIALIZED;
391
364
  } catch (e) {
392
365
  if (e instanceof NotReadyError) {
393
- if (e.cause !== el)
394
- link(e.cause, el);
395
- setStatusFlags(el, prevStatusFlags & ~2 /* Error */ | 1 /* Pending */, e);
396
- } else {
397
- setError(el, e);
398
- }
366
+ if (e.cause !== el) link(e.cause, el);
367
+ setStatusFlags(el, (prevStatusFlags & ~STATUS_ERROR) | STATUS_PENDING, e);
368
+ } else setStatusFlags(el, STATUS_ERROR, e);
399
369
  } finally {
400
370
  tracking = prevTracking;
401
371
  }
402
- el._flags = 0 /* None */;
372
+ el._flags = REACTIVE_NONE;
403
373
  context = oldcontext;
404
374
  const depsTail = el._depsTail;
405
375
  let toRemove = depsTail !== null ? depsTail._nextDep : el._deps;
@@ -407,70 +377,67 @@ function recompute(el, create = false) {
407
377
  do {
408
378
  toRemove = unlinkSubs(toRemove);
409
379
  } while (toRemove !== null);
410
- if (depsTail !== null) {
411
- depsTail._nextDep = null;
412
- } else {
413
- el._deps = null;
414
- }
415
- }
416
- const valueChanged = !el._equals || !el._equals(el._pendingValue === NOT_PENDING ? el._value : el._pendingValue, value);
380
+ if (depsTail !== null) depsTail._nextDep = null;
381
+ else el._deps = null;
382
+ }
383
+ const valueChanged =
384
+ !el._equals ||
385
+ !el._equals(
386
+ el._pendingValue === NOT_PENDING || el._optimistic ? el._value : el._pendingValue,
387
+ value
388
+ );
417
389
  const statusFlagsChanged = el._statusFlags !== prevStatusFlags || el._error !== prevError;
418
390
  el._notifyQueue?.(statusFlagsChanged, prevStatusFlags);
419
391
  if (valueChanged || statusFlagsChanged) {
420
392
  if (valueChanged) {
421
- if (create || el._optimistic || el._type)
393
+ if (create || el._optimistic || (el._type && el._transition != activeTransition))
422
394
  el._value = value;
423
395
  else {
424
- if (el._pendingValue === NOT_PENDING)
425
- globalQueue._pendingNodes.push(el);
396
+ if (el._pendingValue === NOT_PENDING) globalQueue._pendingNodes.push(el);
426
397
  el._pendingValue = value;
427
398
  }
428
- if (el._pendingSignal)
429
- el._pendingSignal._set(value);
399
+ if (el._pendingSignal) el._pendingSignal._set(value);
430
400
  }
431
401
  for (let s = el._subs; s !== null; s = s._nextSub) {
432
- const queue = s._sub._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue;
433
- if (s._sub._height < el._height && queue._min > s._sub._height)
434
- queue._min = s._sub._height;
402
+ const queue = s._sub._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
403
+ if (s._sub._height < el._height && queue._min > s._sub._height) queue._min = s._sub._height;
435
404
  insertIntoHeap(s._sub, queue);
436
405
  }
437
406
  } else if (el._height != oldHeight) {
438
407
  for (let s = el._subs; s !== null; s = s._nextSub) {
439
- insertIntoHeapHeight(s._sub, s._sub._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
408
+ insertIntoHeapHeight(s._sub, s._sub._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
440
409
  }
441
410
  }
411
+ if (el._type && el._transition && activeTransition !== el._transition)
412
+ runInTransition(el, recompute);
442
413
  }
443
414
  function updateIfNecessary(el) {
444
- if (el._flags & 1 /* Check */) {
415
+ if (el._flags & REACTIVE_CHECK) {
445
416
  for (let d = el._deps; d; d = d._nextDep) {
446
417
  const dep1 = d._dep;
447
418
  const dep = dep1._firewall || dep1;
448
419
  if (dep._fn) {
449
420
  updateIfNecessary(dep);
450
421
  }
451
- if (el._flags & 2 /* Dirty */) {
422
+ if (el._flags & REACTIVE_DIRTY) {
452
423
  break;
453
424
  }
454
425
  }
455
426
  }
456
- if (el._flags & 2 /* Dirty */) {
427
+ if (el._flags & REACTIVE_DIRTY) {
457
428
  recompute(el);
458
429
  }
459
- el._flags = 0 /* None */;
430
+ el._flags = REACTIVE_NONE;
460
431
  }
461
- function unlinkSubs(link2) {
462
- const dep = link2._dep;
463
- const nextDep = link2._nextDep;
464
- const nextSub = link2._nextSub;
465
- const prevSub = link2._prevSub;
466
- if (nextSub !== null) {
467
- nextSub._prevSub = prevSub;
468
- } else {
469
- dep._subsTail = prevSub;
470
- }
471
- if (prevSub !== null) {
472
- prevSub._nextSub = nextSub;
473
- } else {
432
+ function unlinkSubs(link) {
433
+ const dep = link._dep;
434
+ const nextDep = link._nextDep;
435
+ const nextSub = link._nextSub;
436
+ const prevSub = link._prevSub;
437
+ if (nextSub !== null) nextSub._prevSub = prevSub;
438
+ else dep._subsTail = prevSub;
439
+ if (prevSub !== null) prevSub._nextSub = nextSub;
440
+ else {
474
441
  dep._subs = nextSub;
475
442
  if (nextSub === null) {
476
443
  dep._unobserved?.();
@@ -480,7 +447,7 @@ function unlinkSubs(link2) {
480
447
  return nextDep;
481
448
  }
482
449
  function unobserved(el) {
483
- deleteFromHeap(el, el._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
450
+ deleteFromHeap(el, el._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
484
451
  let dep = el._deps;
485
452
  while (dep !== null) {
486
453
  dep = unlinkSubs(dep);
@@ -490,11 +457,9 @@ function unobserved(el) {
490
457
  }
491
458
  function link(dep, sub) {
492
459
  const prevDep = sub._depsTail;
493
- if (prevDep !== null && prevDep._dep === dep) {
494
- return;
495
- }
460
+ if (prevDep !== null && prevDep._dep === dep) return;
496
461
  let nextDep = null;
497
- const isRecomputing = sub._flags & 4 /* RecomputingDeps */;
462
+ const isRecomputing = sub._flags & REACTIVE_RECOMPUTING_DEPS;
498
463
  if (isRecomputing) {
499
464
  nextDep = prevDep !== null ? prevDep._nextDep : sub._deps;
500
465
  if (nextDep !== null && nextDep._dep === dep) {
@@ -503,59 +468,38 @@ function link(dep, sub) {
503
468
  }
504
469
  }
505
470
  const prevSub = dep._subsTail;
506
- if (prevSub !== null && prevSub._sub === sub && (!isRecomputing || isValidLink(prevSub, sub))) {
471
+ if (prevSub !== null && prevSub._sub === sub && (!isRecomputing || isValidLink(prevSub, sub)))
507
472
  return;
508
- }
509
- const newLink = sub._depsTail = dep._subsTail = {
510
- _dep: dep,
511
- _sub: sub,
512
- _nextDep: nextDep,
513
- _prevSub: prevSub,
514
- _nextSub: null
515
- };
516
- if (prevDep !== null) {
517
- prevDep._nextDep = newLink;
518
- } else {
519
- sub._deps = newLink;
520
- }
521
- if (prevSub !== null) {
522
- prevSub._nextSub = newLink;
523
- } else {
524
- dep._subs = newLink;
525
- }
473
+ const newLink =
474
+ (sub._depsTail =
475
+ dep._subsTail =
476
+ { _dep: dep, _sub: sub, _nextDep: nextDep, _prevSub: prevSub, _nextSub: null });
477
+ if (prevDep !== null) prevDep._nextDep = newLink;
478
+ else sub._deps = newLink;
479
+ if (prevSub !== null) prevSub._nextSub = newLink;
480
+ else dep._subs = newLink;
526
481
  }
527
482
  function isValidLink(checkLink, sub) {
528
483
  const depsTail = sub._depsTail;
529
484
  if (depsTail !== null) {
530
- let link2 = sub._deps;
485
+ let link = sub._deps;
531
486
  do {
532
- if (link2 === checkLink) {
533
- return true;
534
- }
535
- if (link2 === depsTail) {
536
- break;
537
- }
538
- link2 = link2._nextDep;
539
- } while (link2 !== null);
487
+ if (link === checkLink) return true;
488
+ if (link === depsTail) break;
489
+ link = link._nextDep;
490
+ } while (link !== null);
540
491
  }
541
492
  return false;
542
493
  }
543
- function setStatusFlags(signal2, flags, error = null) {
544
- signal2._statusFlags = flags;
545
- signal2._error = error;
546
- }
547
- function setError(signal2, error) {
548
- setStatusFlags(signal2, 2 /* Error */, error);
549
- }
550
- function clearStatusFlags(signal2) {
551
- setStatusFlags(signal2, 0 /* None */);
494
+ function setStatusFlags(signal, flags, error = null) {
495
+ signal._statusFlags = flags;
496
+ signal._error = error;
552
497
  }
553
498
  function markDisposal(el) {
554
499
  let child = el._firstChild;
555
500
  while (child) {
556
- child._flags |= 32 /* Zombie */;
557
- const inHeap = child._flags & 8 /* InHeap */;
558
- if (inHeap) {
501
+ child._flags |= REACTIVE_ZOMBIE;
502
+ if (child._flags & REACTIVE_IN_HEAP) {
559
503
  deleteFromHeap(child, dirtyQueue);
560
504
  insertIntoHeap(child, zombieQueue);
561
505
  }
@@ -573,16 +517,14 @@ function dispose(node) {
573
517
  disposeChildren(node, true);
574
518
  }
575
519
  function disposeChildren(node, self = false, zombie) {
576
- if (node._flags & 64 /* Disposed */)
577
- return;
578
- if (self)
579
- node._flags = 64 /* Disposed */;
520
+ if (node._flags & REACTIVE_DISPOSED) return;
521
+ if (self) node._flags = REACTIVE_DISPOSED;
580
522
  let child = zombie ? node._pendingFirstChild : node._firstChild;
581
523
  while (child) {
582
524
  const nextChild = child._nextSibling;
583
525
  if (child._deps) {
584
526
  const n = child;
585
- deleteFromHeap(n, n._flags & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
527
+ deleteFromHeap(n, n._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
586
528
  let toRemove = n._deps;
587
529
  do {
588
530
  toRemove = unlinkSubs(toRemove);
@@ -603,8 +545,7 @@ function disposeChildren(node, self = false, zombie) {
603
545
  }
604
546
  function runDisposal(node, zombie) {
605
547
  let disposal = zombie ? node._pendingDisposal : node._disposal;
606
- if (!disposal)
607
- return;
548
+ if (!disposal) return;
608
549
  if (Array.isArray(disposal)) {
609
550
  for (let i = 0; i < disposal.length; i++) {
610
551
  const callable = disposal[i];
@@ -613,61 +554,52 @@ function runDisposal(node, zombie) {
613
554
  } else {
614
555
  disposal.call(disposal);
615
556
  }
616
- zombie ? node._pendingDisposal = null : node._disposal = null;
617
- }
618
- function withOptions(obj, options) {
619
- obj._name = options?.name ?? (obj._fn ? "computed" : "signal");
620
- obj.id = options?.id ?? (context?.id != null ? getNextChildId(context) : void 0);
621
- obj._equals = options?.equals != null ? options.equals : isEqual;
622
- obj._pureWrite = !!options?.pureWrite;
623
- obj._unobserved = options?.unobserved;
624
- if (options?._internal)
625
- Object.assign(obj, options._internal);
626
- return obj;
557
+ zombie ? (node._pendingDisposal = null) : (node._disposal = null);
627
558
  }
628
559
  function getNextChildId(owner) {
629
- if (owner.id != null)
630
- return formatId(owner.id, owner._childCount++);
560
+ if (owner.id != null) return formatId(owner.id, owner._childCount++);
631
561
  throw new Error("Cannot get child id from owner without an id");
632
562
  }
633
563
  function formatId(prefix, id) {
634
- const num = id.toString(36), len = num.length - 1;
564
+ const num = id.toString(36),
565
+ len = num.length - 1;
635
566
  return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
636
567
  }
637
568
  function computed(fn, initialValue, options) {
638
- const self = withOptions(
639
- {
640
- _disposal: null,
641
- _queue: globalQueue,
642
- _context: defaultContext,
643
- _childCount: 0,
644
- _fn: fn,
645
- _value: initialValue,
646
- _height: 0,
647
- _child: null,
648
- _nextHeap: void 0,
649
- _prevHeap: null,
650
- _deps: null,
651
- _depsTail: null,
652
- _subs: null,
653
- _subsTail: null,
654
- _parent: context,
655
- _nextSibling: null,
656
- _firstChild: null,
657
- _flags: 0 /* None */,
658
- _statusFlags: 4 /* Uninitialized */,
659
- _time: clock,
660
- _pendingValue: NOT_PENDING,
661
- _pendingDisposal: null,
662
- _pendingFirstChild: null
663
- },
664
- options
665
- );
569
+ const self = {
570
+ id: options?.id ?? (context?.id != null ? getNextChildId(context) : undefined),
571
+ _equals: options?.equals != null ? options.equals : isEqual,
572
+ _pureWrite: !!options?.pureWrite,
573
+ _unobserved: options?.unobserved,
574
+ _disposal: null,
575
+ _queue: context?._queue ?? globalQueue,
576
+ _context: context?._context ?? defaultContext,
577
+ _childCount: 0,
578
+ _fn: fn,
579
+ _value: initialValue,
580
+ _height: 0,
581
+ _child: null,
582
+ _nextHeap: undefined,
583
+ _prevHeap: null,
584
+ _deps: null,
585
+ _depsTail: null,
586
+ _subs: null,
587
+ _subsTail: null,
588
+ _parent: context,
589
+ _nextSibling: null,
590
+ _firstChild: null,
591
+ _flags: REACTIVE_NONE,
592
+ _statusFlags: STATUS_UNINITIALIZED,
593
+ _time: clock,
594
+ _pendingValue: NOT_PENDING,
595
+ _pendingDisposal: null,
596
+ _pendingFirstChild: null
597
+ };
598
+ if (options?._internal) Object.assign(self, options._internal);
599
+ self._name = options?.name ?? "computed";
666
600
  self._prevHeap = self;
667
601
  const parent = context?._root ? context._parentComputed : context;
668
602
  if (context) {
669
- context._queue && (self._queue = context._queue);
670
- context._context && (self._context = context._context);
671
603
  const lastChild = context._firstChild;
672
604
  if (lastChild === null) {
673
605
  context._firstChild = self;
@@ -676,15 +608,14 @@ function computed(fn, initialValue, options) {
676
608
  context._firstChild = self;
677
609
  }
678
610
  }
679
- if (parent)
680
- self._height = parent._height + 1;
611
+ if (parent) self._height = parent._height + 1;
681
612
  recompute(self, true);
682
613
  return self;
683
614
  }
684
615
  function asyncComputed(asyncFn, initialValue, options) {
685
- let lastResult = void 0;
616
+ let lastResult = undefined;
686
617
  let refreshing = false;
687
- const fn = (prev) => {
618
+ const fn = prev => {
688
619
  const result = asyncFn(prev, refreshing);
689
620
  refreshing = false;
690
621
  lastResult = result;
@@ -694,37 +625,35 @@ function asyncComputed(asyncFn, initialValue, options) {
694
625
  return result;
695
626
  }
696
627
  if (isPromise) {
697
- result.then((v) => {
698
- if (lastResult !== result)
699
- return;
700
- globalQueue.initTransition(self);
701
- setSignal(self, () => v);
702
- flush();
703
- }).catch((e) => {
704
- if (lastResult !== result)
705
- return;
706
- globalQueue.initTransition(self);
707
- setError(self, e);
708
- self._time = clock;
709
- notifySubs(self);
710
- schedule();
711
- flush();
712
- });
628
+ result
629
+ .then(v => {
630
+ if (lastResult !== result) return;
631
+ globalQueue.initTransition(self);
632
+ setSignal(self, () => v);
633
+ flush();
634
+ })
635
+ .catch(e => {
636
+ if (lastResult !== result) return;
637
+ globalQueue.initTransition(self);
638
+ setStatusFlags(self, STATUS_ERROR, e);
639
+ self._time = clock;
640
+ notifySubs(self);
641
+ schedule();
642
+ flush();
643
+ });
713
644
  } else {
714
645
  (async () => {
715
646
  try {
716
647
  for await (let value of result) {
717
- if (lastResult !== result)
718
- return;
648
+ if (lastResult !== result) return;
719
649
  globalQueue.initTransition(self);
720
650
  setSignal(self, () => value);
721
651
  flush();
722
652
  }
723
653
  } catch (error) {
724
- if (lastResult !== result)
725
- return;
654
+ if (lastResult !== result) return;
726
655
  globalQueue.initTransition(self);
727
- setError(self, error);
656
+ setStatusFlags(self, STATUS_ERROR, error);
728
657
  self._time = clock;
729
658
  notifySubs(self);
730
659
  schedule();
@@ -739,45 +668,35 @@ function asyncComputed(asyncFn, initialValue, options) {
739
668
  self._refresh = () => {
740
669
  refreshing = true;
741
670
  recompute(self);
671
+ schedule();
742
672
  flush();
743
673
  };
744
674
  return self;
745
675
  }
746
676
  function signal(v, options, firewall = null) {
747
- if (firewall !== null) {
748
- return firewall._child = withOptions(
749
- {
750
- _value: v,
751
- _subs: null,
752
- _subsTail: null,
753
- _firewall: firewall,
754
- _nextChild: firewall._child,
755
- _statusFlags: 0 /* None */,
756
- _time: clock,
757
- _pendingValue: NOT_PENDING
758
- },
759
- options
760
- );
761
- } else {
762
- return withOptions(
763
- {
764
- _value: v,
765
- _subs: null,
766
- _subsTail: null,
767
- _statusFlags: 0 /* None */,
768
- _time: clock,
769
- _pendingValue: NOT_PENDING
770
- },
771
- options
772
- );
773
- }
677
+ const s = {
678
+ id: options?.id ?? (context?.id != null ? getNextChildId(context) : undefined),
679
+ _equals: options?.equals != null ? options.equals : isEqual,
680
+ _pureWrite: !!options?.pureWrite,
681
+ _unobserved: options?.unobserved,
682
+ _value: v,
683
+ _subs: null,
684
+ _subsTail: null,
685
+ _statusFlags: STATUS_NONE,
686
+ _time: clock,
687
+ _firewall: firewall,
688
+ _nextChild: firewall?._child || null,
689
+ _pendingValue: NOT_PENDING
690
+ };
691
+ s._name = options?.name ?? "signal";
692
+ firewall && (firewall._child = s);
693
+ return s;
774
694
  }
775
695
  function isEqual(a, b) {
776
696
  return a === b;
777
697
  }
778
698
  function untrack(fn) {
779
- if (!tracking)
780
- return fn();
699
+ if (!tracking) return fn();
781
700
  tracking = false;
782
701
  try {
783
702
  return fn();
@@ -787,13 +706,12 @@ function untrack(fn) {
787
706
  }
788
707
  function read(el) {
789
708
  let c = context;
790
- if (c?._root)
791
- c = c._parentComputed;
792
- if (c && tracking) {
709
+ if (c?._root) c = c._parentComputed;
710
+ if (c && tracking && !pendingCheck && !pendingValueCheck) {
793
711
  link(el, c);
794
712
  const owner = el._firewall || el;
795
713
  if (owner._fn) {
796
- const isZombie = el._flags & 32 /* Zombie */;
714
+ const isZombie = el._flags & REACTIVE_ZOMBIE;
797
715
  if (owner._height >= (isZombie ? zombieQueue._min : dirtyQueue._min)) {
798
716
  markNode(c);
799
717
  markHeap(isZombie ? zombieQueue : dirtyQueue);
@@ -806,25 +724,21 @@ function read(el) {
806
724
  }
807
725
  }
808
726
  if (pendingCheck) {
809
- const pendingResult = (el._statusFlags & 1 /* Pending */) !== 0 || !!el._transition || false;
810
727
  if (!el._pendingCheck) {
811
- el._pendingCheck = signal(pendingResult);
728
+ el._pendingCheck = signal(false);
812
729
  el._pendingCheck._optimistic = true;
813
- el._pendingCheck._set = (v) => setSignal(el._pendingCheck, v);
730
+ el._pendingCheck._set = v => setSignal(el._pendingCheck, v);
814
731
  }
815
732
  const prev = pendingCheck;
816
733
  pendingCheck = null;
817
- read(el._pendingCheck);
734
+ prev._value = read(el._pendingCheck) || prev._value;
818
735
  pendingCheck = prev;
819
- prev._value = pendingResult || prev._value;
820
736
  }
821
737
  if (pendingValueCheck) {
822
738
  if (!el._pendingSignal) {
823
- el._pendingSignal = signal(
824
- el._pendingValue === NOT_PENDING ? el._value : el._pendingValue
825
- );
739
+ el._pendingSignal = signal(el._value);
826
740
  el._pendingSignal._optimistic = true;
827
- el._pendingSignal._set = (v) => queueMicrotask(() => queueMicrotask(() => setSignal(el._pendingSignal, v)));
741
+ el._pendingSignal._set = v => setSignal(el._pendingSignal, v);
828
742
  }
829
743
  pendingValueCheck = false;
830
744
  try {
@@ -833,18 +747,13 @@ function read(el) {
833
747
  pendingValueCheck = true;
834
748
  }
835
749
  }
836
- if (el._statusFlags & 1 /* Pending */) {
837
- if (c && !stale || el._statusFlags & 4 /* Uninitialized */)
838
- throw el._error;
750
+ if (el._statusFlags & STATUS_PENDING) {
751
+ if ((c && !stale) || el._statusFlags & STATUS_UNINITIALIZED) throw el._error;
839
752
  else if (c && stale && !pendingCheck) {
840
- setStatusFlags(
841
- c,
842
- c._statusFlags | 1,
843
- el._error
844
- );
753
+ setStatusFlags(c, c._statusFlags | 1, el._error);
845
754
  }
846
755
  }
847
- if (el._statusFlags & 2 /* Error */) {
756
+ if (el._statusFlags & STATUS_ERROR) {
848
757
  if (el._time < clock) {
849
758
  recompute(el, true);
850
759
  return read(el);
@@ -852,31 +761,35 @@ function read(el) {
852
761
  throw el._error;
853
762
  }
854
763
  }
855
- return !c || el._pendingValue === NOT_PENDING || stale && !pendingCheck && el._transition && activeTransition !== el._transition ? el._value : el._pendingValue;
764
+ return !c ||
765
+ el._optimistic ||
766
+ el._pendingValue === NOT_PENDING ||
767
+ (stale && !pendingCheck && el._transition && activeTransition !== el._transition)
768
+ ? el._value
769
+ : el._pendingValue;
856
770
  }
857
771
  function setSignal(el, v) {
858
772
  if (!el._pureWrite && context && el._firewall !== context)
859
773
  console.warn("A Signal was written to in an owned scope.");
860
774
  if (typeof v === "function") {
861
- v = v(
862
- el._pendingValue === NOT_PENDING ? el._value : el._pendingValue
863
- );
775
+ v = v(el._pendingValue === NOT_PENDING ? el._value : el._pendingValue);
864
776
  }
865
- const valueChanged = !el._equals || !el._equals(el._pendingValue === NOT_PENDING ? el._value : el._pendingValue, v);
866
- if (!valueChanged && !el._statusFlags)
867
- return v;
777
+ const valueChanged =
778
+ !el._equals ||
779
+ !el._equals(
780
+ el._pendingValue === NOT_PENDING || el._optimistic ? el._value : el._pendingValue,
781
+ v
782
+ );
783
+ if (!valueChanged && !el._statusFlags) return v;
868
784
  if (valueChanged) {
869
- if (el._optimistic)
870
- el._value = v;
785
+ if (el._optimistic) el._value = v;
871
786
  else {
872
- if (el._pendingValue === NOT_PENDING)
873
- globalQueue._pendingNodes.push(el);
787
+ if (el._pendingValue === NOT_PENDING) globalQueue._pendingNodes.push(el);
874
788
  el._pendingValue = v;
875
789
  }
876
- if (el._pendingSignal)
877
- el._pendingSignal._set(v);
790
+ if (el._pendingSignal) el._pendingSignal._pendingValue = v;
878
791
  }
879
- clearStatusFlags(el);
792
+ setStatusFlags(el, STATUS_NONE);
880
793
  el._time = clock;
881
794
  notifySubs(el);
882
795
  schedule();
@@ -889,8 +802,7 @@ function getOwner() {
889
802
  return context;
890
803
  }
891
804
  function onCleanup(fn) {
892
- if (!context)
893
- return fn;
805
+ if (!context) return fn;
894
806
  const node = context;
895
807
  if (!node._disposal) {
896
808
  node._disposal = fn;
@@ -909,7 +821,7 @@ function createOwner(options) {
909
821
  _firstChild: null,
910
822
  _nextSibling: null,
911
823
  _disposal: null,
912
- id: options?.id ?? (parent?.id != null ? getNextChildId(parent) : void 0),
824
+ id: options?.id ?? (parent?.id != null ? getNextChildId(parent) : undefined),
913
825
  _queue: parent?._queue ?? globalQueue,
914
826
  _context: parent?._context || defaultContext,
915
827
  _childCount: 0,
@@ -969,134 +881,117 @@ function isPending(fn, loadingValue) {
969
881
  staleValues(fn);
970
882
  return pendingCheck._value;
971
883
  } catch (err) {
972
- if (!(err instanceof NotReadyError))
973
- return false;
974
- if (loadingValue !== void 0)
975
- return loadingValue;
884
+ if (!(err instanceof NotReadyError)) return false;
885
+ if (loadingValue !== undefined) return loadingValue;
976
886
  throw err;
977
887
  } finally {
978
888
  pendingCheck = current;
979
889
  }
980
890
  }
981
-
982
- // src/core/context.ts
983
891
  function createContext(defaultValue, description) {
984
- return { id: Symbol(description), defaultValue };
892
+ return { id: Symbol(description), defaultValue: defaultValue };
985
893
  }
986
- function getContext(context2, owner = getOwner()) {
894
+ function getContext(context, owner = getOwner()) {
987
895
  if (!owner) {
988
896
  throw new NoOwnerError();
989
897
  }
990
- const value = hasContext(context2, owner) ? owner._context[context2.id] : context2.defaultValue;
898
+ const value = hasContext(context, owner) ? owner._context[context.id] : context.defaultValue;
991
899
  if (isUndefined(value)) {
992
900
  throw new ContextNotFoundError();
993
901
  }
994
902
  return value;
995
903
  }
996
- function setContext(context2, value, owner = getOwner()) {
904
+ function setContext(context, value, owner = getOwner()) {
997
905
  if (!owner) {
998
906
  throw new NoOwnerError();
999
907
  }
1000
908
  owner._context = {
1001
909
  ...owner._context,
1002
- [context2.id]: isUndefined(value) ? context2.defaultValue : value
910
+ [context.id]: isUndefined(value) ? context.defaultValue : value
1003
911
  };
1004
912
  }
1005
- function hasContext(context2, owner) {
1006
- return !isUndefined(owner?._context[context2.id]);
913
+ function hasContext(context, owner) {
914
+ return !isUndefined(owner?._context[context.id]);
1007
915
  }
1008
916
  function isUndefined(value) {
1009
917
  return typeof value === "undefined";
1010
918
  }
1011
-
1012
- // src/core/effect.ts
1013
- function effect(compute, effect2, error, initialValue, options) {
919
+ function effect(compute, effect, error, initialValue, options) {
1014
920
  let initialized = false;
1015
921
  const node = computed(compute, initialValue, {
1016
922
  ...options,
1017
923
  _internal: {
1018
924
  _modified: true,
1019
925
  _prevValue: initialValue,
1020
- _effectFn: effect2,
926
+ _effectFn: effect,
1021
927
  _errorFn: error,
1022
- _cleanup: void 0,
1023
- _queue: getOwner()?._queue ?? globalQueue,
1024
- _type: options?.render ? 1 /* Render */ : 2 /* User */,
928
+ _cleanup: undefined,
929
+ _type: options?.render ? EFFECT_RENDER : EFFECT_USER,
1025
930
  _notifyQueue(statusFlagsChanged, prevStatusFlags) {
1026
931
  if (initialized) {
1027
- const errorChanged = this._statusFlags && this._statusFlags === prevStatusFlags && statusFlagsChanged;
1028
- this._modified = !(this._statusFlags & 2 /* Error */) && !(this._statusFlags & 1 /* Pending */ & ~prevStatusFlags) && !errorChanged;
1029
- if (this._modified)
1030
- this._queue.enqueue(this._type, runEffect.bind(this));
932
+ const errorChanged =
933
+ this._statusFlags && this._statusFlags === prevStatusFlags && statusFlagsChanged;
934
+ this._modified =
935
+ !(this._statusFlags & STATUS_ERROR) &&
936
+ !(this._statusFlags & STATUS_PENDING & ~prevStatusFlags) &&
937
+ !errorChanged;
938
+ if (this._modified) this._queue.enqueue(this._type, runEffect.bind(this));
1031
939
  }
1032
- if (this._statusFlags & 2 /* Error */) {
1033
- let error2 = this._error;
1034
- this._queue.notify(this, 1 /* Pending */, 0);
1035
- if (this._type === 2 /* User */) {
940
+ if (this._statusFlags & STATUS_ERROR) {
941
+ let error = this._error;
942
+ this._queue.notify(this, STATUS_PENDING, 0);
943
+ if (this._type === EFFECT_USER) {
1036
944
  try {
1037
- return this._errorFn ? this._errorFn(error2, () => {
1038
- this._cleanup?.();
1039
- this._cleanup = void 0;
1040
- }) : console.error(error2);
945
+ return this._errorFn
946
+ ? this._errorFn(error, () => {
947
+ this._cleanup?.();
948
+ this._cleanup = undefined;
949
+ })
950
+ : console.error(error);
1041
951
  } catch (e) {
1042
- error2 = e;
952
+ error = e;
1043
953
  }
1044
954
  }
1045
- if (!this._queue.notify(this, 2 /* Error */, 2 /* Error */))
1046
- throw error2;
1047
- } else if (this._type === 1 /* Render */) {
1048
- this._queue.notify(
1049
- this,
1050
- 1 /* Pending */ | 2 /* Error */,
1051
- this._statusFlags
1052
- );
955
+ if (!this._queue.notify(this, STATUS_ERROR, STATUS_ERROR)) throw error;
956
+ } else if (this._type === EFFECT_RENDER) {
957
+ this._queue.notify(this, STATUS_PENDING | STATUS_ERROR, this._statusFlags);
1053
958
  }
1054
959
  }
1055
960
  }
1056
961
  });
1057
962
  initialized = true;
1058
- if (node._type === 1 /* Render */)
1059
- node._fn = (p) => staleValues(() => compute(p));
1060
- !options?.defer && !(node._statusFlags & (2 /* Error */ | 1 /* Pending */)) && (node._type === 2 /* User */ ? node._queue.enqueue(node._type, runEffect.bind(node)) : runEffect.call(node));
963
+ if (node._type === EFFECT_RENDER) node._fn = p => staleValues(() => compute(p));
964
+ !options?.defer &&
965
+ !(node._statusFlags & (STATUS_ERROR | STATUS_PENDING)) &&
966
+ (node._type === EFFECT_USER
967
+ ? node._queue.enqueue(node._type, runEffect.bind(node))
968
+ : runEffect.call(node));
1061
969
  onCleanup(() => node._cleanup?.());
1062
970
  if (!node._parent)
1063
971
  console.warn("Effects created outside a reactive context will never be disposed");
1064
972
  }
1065
973
  function runEffect() {
1066
- if (!this._modified || this._flags & 64 /* Disposed */)
1067
- return;
974
+ if (!this._modified || this._flags & REACTIVE_DISPOSED) return;
1068
975
  this._cleanup?.();
1069
- this._cleanup = void 0;
976
+ this._cleanup = undefined;
1070
977
  try {
1071
978
  this._cleanup = this._effectFn(this._value, this._prevValue);
1072
979
  } catch (error) {
1073
- if (!this._queue.notify(this, 2 /* Error */, 2 /* Error */))
1074
- throw error;
980
+ if (!this._queue.notify(this, STATUS_ERROR, STATUS_ERROR)) throw error;
1075
981
  } finally {
1076
982
  this._prevValue = this._value;
1077
983
  this._modified = false;
1078
984
  }
1079
985
  }
1080
-
1081
- // src/signals.ts
1082
986
  function createSignal(first, second, third) {
1083
987
  if (typeof first === "function") {
1084
- const node2 = computed(first, second, third);
1085
- return [
1086
- read.bind(null, node2),
1087
- setSignal.bind(null, node2)
1088
- ];
988
+ const node = computed(first, second, third);
989
+ return [read.bind(null, node), setSignal.bind(null, node)];
1089
990
  }
1090
991
  const o = getOwner();
1091
992
  const needsId = o?.id != null;
1092
- const node = signal(
1093
- first,
1094
- needsId ? { id: getNextChildId(o), ...second } : second
1095
- );
1096
- return [
1097
- read.bind(null, node),
1098
- setSignal.bind(null, node)
1099
- ];
993
+ const node = signal(first, needsId ? { id: getNextChildId(o), ...second } : second);
994
+ return [read.bind(null, node), setSignal.bind(null, node)];
1100
995
  }
1101
996
  function createMemo(compute, value, options) {
1102
997
  let node = computed(compute, value, options);
@@ -1109,54 +1004,49 @@ function createAsync(compute, value, options) {
1109
1004
  return ret;
1110
1005
  }
1111
1006
  function createEffect(compute, effectFn, value, options) {
1112
- void effect(
1113
- compute,
1114
- effectFn.effect || effectFn,
1115
- effectFn.error,
1116
- value,
1117
- { ...options, name: options?.name ?? "effect" }
1118
- );
1007
+ void effect(compute, effectFn.effect || effectFn, effectFn.error, value, {
1008
+ ...options,
1009
+ name: options?.name ?? "effect"
1010
+ });
1119
1011
  }
1120
1012
  function createRenderEffect(compute, effectFn, value, options) {
1121
- void effect(compute, effectFn, void 0, value, {
1013
+ void effect(compute, effectFn, undefined, value, {
1122
1014
  render: true,
1123
- ...{ ...options, name: options?.name ?? "effect" }
1015
+ ...{ ...options, name: options?.name ?? "effect" }
1124
1016
  });
1125
1017
  }
1126
- function createTrackedEffect(compute, options) {
1127
- }
1018
+ function createTrackedEffect(compute, options) {}
1128
1019
  function createReaction(effectFn, options) {
1129
- let cleanup = void 0;
1020
+ let cleanup = undefined;
1130
1021
  onCleanup(() => cleanup?.());
1131
- return (tracking2) => {
1132
- effect(
1133
- () => (tracking2(), getOwner()),
1134
- (node) => {
1135
- cleanup?.();
1136
- cleanup = (effectFn.effect || effectFn)?.();
1137
- dispose(node);
1138
- },
1139
- effectFn.error,
1140
- void 0,
1141
- {
1142
- defer: true,
1143
- ...{ ...options, name: options?.name ?? "effect" }
1144
- }
1145
- );
1022
+ const owner = getOwner();
1023
+ return tracking => {
1024
+ runWithOwner(owner, () => {
1025
+ effect(
1026
+ () => (tracking(), getOwner()),
1027
+ node => {
1028
+ cleanup?.();
1029
+ cleanup = (effectFn.effect || effectFn)?.();
1030
+ dispose(node);
1031
+ },
1032
+ effectFn.error,
1033
+ undefined,
1034
+ { defer: true, ...(true ? { ...options, name: options?.name ?? "effect" } : options) }
1035
+ );
1036
+ });
1146
1037
  };
1147
1038
  }
1148
1039
  function resolve(fn) {
1149
1040
  return new Promise((res, rej) => {
1150
- createRoot((dispose2) => {
1041
+ createRoot(dispose => {
1151
1042
  computed(() => {
1152
1043
  try {
1153
1044
  res(fn());
1154
1045
  } catch (err) {
1155
- if (err instanceof NotReadyError)
1156
- throw err;
1046
+ if (err instanceof NotReadyError) throw err;
1157
1047
  rej(err);
1158
1048
  }
1159
- dispose2();
1049
+ dispose();
1160
1050
  });
1161
1051
  });
1162
1052
  });
@@ -1167,48 +1057,61 @@ function createOptimistic(first, second, third) {
1167
1057
  function onSettled(callback) {
1168
1058
  let cleanup;
1169
1059
  const o = getOwner();
1170
- if (o)
1171
- onCleanup(() => cleanup?.());
1172
- globalQueue.enqueue(2 /* User */, () => {
1060
+ if (o) onCleanup(() => cleanup?.());
1061
+ globalQueue.enqueue(EFFECT_USER, () => {
1173
1062
  cleanup = callback();
1174
1063
  !o && cleanup?.();
1175
1064
  });
1176
1065
  }
1177
-
1178
- // src/store/reconcile.ts
1179
1066
  function unwrap(value) {
1180
1067
  return value?.[$TARGET]?.[STORE_NODE] ?? value;
1181
1068
  }
1182
1069
  function getOverrideValue(value, override, nodes, key) {
1183
- return nodes && key in nodes ? read(nodes[key]) : override && key in override ? override[key] : value[key];
1070
+ return nodes && key in nodes
1071
+ ? read(nodes[key])
1072
+ : override && key in override
1073
+ ? override[key]
1074
+ : value[key];
1184
1075
  }
1185
1076
  function getAllKeys(value, override, next) {
1186
1077
  const keys = getKeys(value, override);
1187
1078
  const nextKeys = Object.keys(next);
1188
- return Array.from(/* @__PURE__ */ new Set([...keys, ...nextKeys]));
1079
+ return Array.from(new Set([...keys, ...nextKeys]));
1189
1080
  }
1190
1081
  function applyState(next, state, keyFn, all) {
1191
1082
  const target = state?.[$TARGET];
1192
- if (!target)
1193
- return;
1083
+ if (!target) return;
1194
1084
  const previous = target[STORE_VALUE];
1195
1085
  const override = target[STORE_OVERRIDE];
1196
1086
  let nodes = target[STORE_NODE];
1197
- if (next === previous && !override)
1198
- return;
1087
+ if (next === previous && !override) return;
1199
1088
  (target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
1200
1089
  target[STORE_VALUE] = next;
1201
- target[STORE_OVERRIDE] = void 0;
1090
+ target[STORE_OVERRIDE] = undefined;
1202
1091
  if (Array.isArray(previous)) {
1203
1092
  let changed = false;
1204
1093
  const prevLength = getOverrideValue(previous, override, nodes, "length");
1205
1094
  if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
1206
1095
  let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1207
- for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, nodes, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
1096
+ for (
1097
+ start = 0, end = Math.min(prevLength, next.length);
1098
+ start < end &&
1099
+ ((item = getOverrideValue(previous, override, nodes, start)) === next[start] ||
1100
+ (item && next[start] && keyFn(item) === keyFn(next[start])));
1101
+ start++
1102
+ ) {
1208
1103
  applyState(next[start], wrap(item, target), keyFn, all);
1209
1104
  }
1210
- const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1211
- for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, nodes, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
1105
+ const temp = new Array(next.length),
1106
+ newIndices = new Map();
1107
+ for (
1108
+ end = prevLength - 1, newEnd = next.length - 1;
1109
+ end >= start &&
1110
+ newEnd >= start &&
1111
+ ((item = getOverrideValue(previous, override, nodes, end)) === next[newEnd] ||
1112
+ (item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])));
1113
+ end--, newEnd--
1114
+ ) {
1212
1115
  temp[newEnd] = item;
1213
1116
  }
1214
1117
  if (start > newEnd || start > end) {
@@ -1223,7 +1126,9 @@ function applyState(next, state, keyFn, all) {
1223
1126
  applyState(next[j], wrapped, keyFn, all);
1224
1127
  }
1225
1128
  changed && target[STORE_NODE][$TRACK] && setSignal(target[STORE_NODE][$TRACK], void 0);
1226
- prevLength !== next.length && target[STORE_NODE].length && setSignal(target[STORE_NODE].length, next.length);
1129
+ prevLength !== next.length &&
1130
+ target[STORE_NODE].length &&
1131
+ setSignal(target[STORE_NODE].length, next.length);
1227
1132
  return;
1228
1133
  }
1229
1134
  newIndicesNext = new Array(newEnd + 1);
@@ -1231,14 +1136,14 @@ function applyState(next, state, keyFn, all) {
1231
1136
  item = next[j];
1232
1137
  keyVal = item ? keyFn(item) : item;
1233
1138
  i = newIndices.get(keyVal);
1234
- newIndicesNext[j] = i === void 0 ? -1 : i;
1139
+ newIndicesNext[j] = i === undefined ? -1 : i;
1235
1140
  newIndices.set(keyVal, j);
1236
1141
  }
1237
1142
  for (i = start; i <= end; i++) {
1238
1143
  item = getOverrideValue(previous, override, nodes, i);
1239
1144
  keyVal = item ? keyFn(item) : item;
1240
1145
  j = newIndices.get(keyVal);
1241
- if (j !== void 0 && j !== -1) {
1146
+ if (j !== undefined && j !== -1) {
1242
1147
  temp[j] = item;
1243
1148
  j = newIndicesNext[j];
1244
1149
  newIndices.set(keyVal, j);
@@ -1249,11 +1154,9 @@ function applyState(next, state, keyFn, all) {
1249
1154
  const wrapped = wrap(temp[j], target);
1250
1155
  target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrapped);
1251
1156
  applyState(next[j], wrapped, keyFn, all);
1252
- } else
1253
- target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrap(next[j], target));
1157
+ } else target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrap(next[j], target));
1254
1158
  }
1255
- if (start < next.length)
1256
- changed = true;
1159
+ if (start < next.length) changed = true;
1257
1160
  } else if (prevLength && next.length) {
1258
1161
  for (let i = 0, len = next.length; i < len; i++) {
1259
1162
  const item = getOverrideValue(previous, override, nodes, i);
@@ -1275,16 +1178,18 @@ function applyState(next, state, keyFn, all) {
1275
1178
  const node = nodes[key];
1276
1179
  const previousValue = unwrap(getOverrideValue(previous, override, nodes, key));
1277
1180
  let nextValue = unwrap(next[key]);
1278
- if (previousValue === nextValue)
1279
- continue;
1280
- if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue)) {
1181
+ if (previousValue === nextValue) continue;
1182
+ if (
1183
+ !previousValue ||
1184
+ !isWrappable(previousValue) ||
1185
+ (keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
1186
+ ) {
1281
1187
  tracked && setSignal(tracked, void 0);
1282
1188
  node && setSignal(node, isWrappable(nextValue) ? wrap(nextValue, target) : nextValue);
1283
- } else
1284
- applyState(nextValue, wrap(previousValue, target), keyFn, all);
1189
+ } else applyState(nextValue, wrap(previousValue, target), keyFn, all);
1285
1190
  }
1286
1191
  }
1287
- if (nodes = target[STORE_HAS]) {
1192
+ if ((nodes = target[STORE_HAS])) {
1288
1193
  const keys = Object.keys(nodes);
1289
1194
  for (let i = 0, len = keys.length; i < len; i++) {
1290
1195
  const key = keys[i];
@@ -1293,26 +1198,21 @@ function applyState(next, state, keyFn, all) {
1293
1198
  }
1294
1199
  }
1295
1200
  function reconcile(value, key, all = false) {
1296
- return (state) => {
1297
- if (state == null)
1298
- throw new Error("Cannot reconcile null or undefined state");
1299
- const keyFn = typeof key === "string" ? (item) => item[key] : key;
1201
+ return state => {
1202
+ if (state == null) throw new Error("Cannot reconcile null or undefined state");
1203
+ const keyFn = typeof key === "string" ? item => item[key] : key;
1300
1204
  const eq = keyFn(state);
1301
- if (eq !== void 0 && keyFn(value) !== keyFn(state))
1205
+ if (eq !== undefined && keyFn(value) !== keyFn(state))
1302
1206
  throw new Error("Cannot reconcile states with different identity");
1303
1207
  applyState(value, state, keyFn, all);
1304
1208
  };
1305
1209
  }
1306
-
1307
- // src/store/projection.ts
1308
1210
  function createProjectionInternal(fn, initialValue = {}, options) {
1309
1211
  let node;
1310
- const wrappedMap = /* @__PURE__ */ new WeakMap();
1311
- const wrapProjection = (source) => {
1312
- if (wrappedMap.has(source))
1313
- return wrappedMap.get(source);
1314
- if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
1315
- return source;
1212
+ const wrappedMap = new WeakMap();
1213
+ const wrapProjection = source => {
1214
+ if (wrappedMap.has(source)) return wrappedMap.get(source);
1215
+ if (source[$TARGET]?.[STORE_WRAP] === wrapProjection) return source;
1316
1216
  const wrapped = createStoreProxy(source, storeTraps, {
1317
1217
  [STORE_WRAP]: wrapProjection,
1318
1218
  [STORE_LOOKUP]: wrappedMap,
@@ -1325,50 +1225,45 @@ function createProjectionInternal(fn, initialValue = {}, options) {
1325
1225
  };
1326
1226
  const wrappedStore = wrapProjection(initialValue);
1327
1227
  node = computed(() => {
1328
- storeSetter(wrappedStore, (s) => {
1228
+ storeSetter(wrappedStore, s => {
1329
1229
  const value = fn(s);
1330
- if (value !== s && value !== void 0) {
1230
+ if (value !== s && value !== undefined) {
1331
1231
  reconcile(value, options?.key || "id", options?.all)(s);
1332
1232
  }
1333
1233
  });
1334
1234
  });
1335
- return { store: wrappedStore, node };
1235
+ return { store: wrappedStore, node: node };
1336
1236
  }
1337
1237
  function createProjection(fn, initialValue = {}, options) {
1338
1238
  return createProjectionInternal(fn, initialValue, options).store;
1339
1239
  }
1340
-
1341
- // src/store/store.ts
1342
- var $TRACK = Symbol("STORE_TRACK" );
1343
- var $DEEP = Symbol("STORE_DEEP" );
1344
- var $TARGET = Symbol("STORE_TARGET" );
1345
- var $PROXY = Symbol("STORE_PROXY" );
1346
- var $DELETED = Symbol("STORE_DELETED" );
1347
- var PARENTS = /* @__PURE__ */ new WeakMap();
1348
- var STORE_VALUE = "v";
1349
- var STORE_OVERRIDE = "o";
1350
- var STORE_NODE = "n";
1351
- var STORE_HAS = "h";
1352
- var STORE_WRAP = "w";
1353
- var STORE_LOOKUP = "l";
1354
- var STORE_FIREWALL = "f";
1240
+ const $TRACK = Symbol("STORE_TRACK"),
1241
+ $DEEP = Symbol("STORE_DEEP"),
1242
+ $TARGET = Symbol("STORE_TARGET"),
1243
+ $PROXY = Symbol("STORE_PROXY"),
1244
+ $DELETED = Symbol("STORE_DELETED");
1245
+ const PARENTS = new WeakMap();
1246
+ const STORE_VALUE = "v",
1247
+ STORE_OVERRIDE = "o",
1248
+ STORE_NODE = "n",
1249
+ STORE_HAS = "h",
1250
+ STORE_WRAP = "w",
1251
+ STORE_LOOKUP = "l",
1252
+ STORE_FIREWALL = "f";
1355
1253
  function createStoreProxy(value, traps = storeTraps, extend) {
1356
1254
  let newTarget;
1357
1255
  if (Array.isArray(value)) {
1358
1256
  newTarget = [];
1359
1257
  newTarget.v = value;
1360
- } else
1361
- newTarget = { v: value };
1258
+ } else newTarget = { v: value };
1362
1259
  extend && Object.assign(newTarget, extend);
1363
- return newTarget[$PROXY] = new Proxy(newTarget, traps);
1260
+ return (newTarget[$PROXY] = new Proxy(newTarget, traps));
1364
1261
  }
1365
- var storeLookup = /* @__PURE__ */ new WeakMap();
1262
+ const storeLookup = new WeakMap();
1366
1263
  function wrap(value, target) {
1367
- if (target?.[STORE_WRAP])
1368
- return target[STORE_WRAP](value, target);
1264
+ if (target?.[STORE_WRAP]) return target[STORE_WRAP](value, target);
1369
1265
  let p = value[$PROXY] || storeLookup.get(value);
1370
- if (!p)
1371
- storeLookup.set(value, p = createStoreProxy(value));
1266
+ if (!p) storeLookup.set(value, (p = createStoreProxy(value)));
1372
1267
  return p;
1373
1268
  }
1374
1269
  function isWrappable(obj) {
@@ -1376,60 +1271,52 @@ function isWrappable(obj) {
1376
1271
  }
1377
1272
  function getNodes(target, type) {
1378
1273
  let nodes = target[type];
1379
- if (!nodes)
1380
- target[type] = nodes = /* @__PURE__ */ Object.create(null);
1274
+ if (!nodes) target[type] = nodes = Object.create(null);
1381
1275
  return nodes;
1382
1276
  }
1383
1277
  function getNode(nodes, property, value, firewall, equals = isEqual) {
1384
- if (nodes[property])
1385
- return nodes[property];
1386
- return nodes[property] = signal(
1278
+ if (nodes[property]) return nodes[property];
1279
+ return (nodes[property] = signal(
1387
1280
  value,
1388
1281
  {
1389
- equals,
1282
+ equals: equals,
1390
1283
  unobserved() {
1391
1284
  delete nodes[property];
1392
1285
  }
1393
1286
  },
1394
1287
  firewall
1395
- );
1288
+ ));
1396
1289
  }
1397
1290
  function trackSelf(target, symbol = $TRACK) {
1398
- getObserver() && read(
1399
- getNode(getNodes(target, STORE_NODE), symbol, void 0, target[STORE_FIREWALL]?.(), false)
1400
- );
1291
+ getObserver() &&
1292
+ read(
1293
+ getNode(getNodes(target, STORE_NODE), symbol, undefined, target[STORE_FIREWALL]?.(), false)
1294
+ );
1401
1295
  }
1402
1296
  function getKeys(source, override, enumerable = true) {
1403
- const baseKeys = untrack(() => enumerable ? Object.keys(source) : Reflect.ownKeys(source));
1404
- if (!override)
1405
- return baseKeys;
1297
+ const baseKeys = untrack(() => (enumerable ? Object.keys(source) : Reflect.ownKeys(source)));
1298
+ if (!override) return baseKeys;
1406
1299
  const keys = new Set(baseKeys);
1407
1300
  const overrides = Reflect.ownKeys(override);
1408
1301
  for (const key of overrides) {
1409
- if (override[key] !== $DELETED)
1410
- keys.add(key);
1411
- else
1412
- keys.delete(key);
1302
+ if (override[key] !== $DELETED) keys.add(key);
1303
+ else keys.delete(key);
1413
1304
  }
1414
1305
  return Array.from(keys);
1415
1306
  }
1416
1307
  function getPropertyDescriptor(source, override, property) {
1417
1308
  let value = source;
1418
1309
  if (override && property in override) {
1419
- if (value[property] === $DELETED)
1420
- return void 0;
1421
- if (!(property in value))
1422
- value = override;
1310
+ if (value[property] === $DELETED) return void 0;
1311
+ if (!(property in value)) value = override;
1423
1312
  }
1424
1313
  return Reflect.getOwnPropertyDescriptor(value, property);
1425
1314
  }
1426
- var Writing = null;
1427
- var storeTraps = {
1315
+ let Writing = null;
1316
+ const storeTraps = {
1428
1317
  get(target, property, receiver) {
1429
- if (property === $TARGET)
1430
- return target;
1431
- if (property === $PROXY)
1432
- return receiver;
1318
+ if (property === $TARGET) return target;
1319
+ if (property === $PROXY) return receiver;
1433
1320
  if (property === $TRACK || property === $DEEP) {
1434
1321
  trackSelf(target, property);
1435
1322
  return receiver;
@@ -1441,24 +1328,35 @@ var storeTraps = {
1441
1328
  const storeValue = overridden ? target[STORE_OVERRIDE] : target[STORE_VALUE];
1442
1329
  if (!tracked) {
1443
1330
  const desc = Object.getOwnPropertyDescriptor(storeValue, property);
1444
- if (desc && desc.get)
1445
- return desc.get.call(receiver);
1331
+ if (desc && desc.get) return desc.get.call(receiver);
1446
1332
  }
1447
1333
  if (Writing?.has(receiver)) {
1448
- let value2 = tracked && (overridden || !proxySource) ? tracked._pendingValue !== NOT_PENDING ? tracked._pendingValue : tracked._value : storeValue[property];
1449
- value2 === $DELETED && (value2 = void 0);
1450
- if (!isWrappable(value2))
1451
- return value2;
1452
- const wrapped = wrap(value2, target);
1334
+ let value =
1335
+ tracked && (overridden || !proxySource)
1336
+ ? tracked._pendingValue !== NOT_PENDING
1337
+ ? tracked._pendingValue
1338
+ : tracked._value
1339
+ : storeValue[property];
1340
+ value === $DELETED && (value = undefined);
1341
+ if (!isWrappable(value)) return value;
1342
+ const wrapped = wrap(value, target);
1453
1343
  Writing.add(wrapped);
1454
1344
  return wrapped;
1455
1345
  }
1456
- let value = tracked ? overridden || !proxySource ? read(nodes[property]) : (read(nodes[property]), storeValue[property]) : storeValue[property];
1457
- value === $DELETED && (value = void 0);
1346
+ let value = tracked
1347
+ ? overridden || !proxySource
1348
+ ? read(nodes[property])
1349
+ : (read(nodes[property]), storeValue[property])
1350
+ : storeValue[property];
1351
+ value === $DELETED && (value = undefined);
1458
1352
  if (!tracked) {
1459
1353
  if (!overridden && typeof value === "function" && !storeValue.hasOwnProperty(property)) {
1460
1354
  let proto;
1461
- return !Array.isArray(target[STORE_VALUE]) && (proto = Object.getPrototypeOf(target[STORE_VALUE])) && proto !== Object.prototype ? value.bind(storeValue) : value;
1355
+ return !Array.isArray(target[STORE_VALUE]) &&
1356
+ (proto = Object.getPrototypeOf(target[STORE_VALUE])) &&
1357
+ proto !== Object.prototype
1358
+ ? value.bind(storeValue)
1359
+ : value;
1462
1360
  } else if (getObserver()) {
1463
1361
  return read(
1464
1362
  getNode(
@@ -1473,10 +1371,13 @@ var storeTraps = {
1473
1371
  return isWrappable(value) ? wrap(value, target) : value;
1474
1372
  },
1475
1373
  has(target, property) {
1476
- if (property === $PROXY || property === $TRACK || property === "__proto__")
1477
- return true;
1478
- const has = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] !== $DELETED : property in target[STORE_VALUE];
1479
- getObserver() && read(getNode(getNodes(target, STORE_HAS), property, has, target[STORE_FIREWALL]?.()));
1374
+ if (property === $PROXY || property === $TRACK || property === "__proto__") return true;
1375
+ const has =
1376
+ target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]
1377
+ ? target[STORE_OVERRIDE][property] !== $DELETED
1378
+ : property in target[STORE_VALUE];
1379
+ getObserver() &&
1380
+ read(getNode(getNodes(target, STORE_HAS), property, has, target[STORE_FIREWALL]?.()));
1480
1381
  return has;
1481
1382
  },
1482
1383
  set(target, property, rawValue) {
@@ -1485,31 +1386,32 @@ var storeTraps = {
1485
1386
  untrack(() => {
1486
1387
  const state = target[STORE_VALUE];
1487
1388
  const base = state[property];
1488
- const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : base;
1389
+ const prev =
1390
+ target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]
1391
+ ? target[STORE_OVERRIDE][property]
1392
+ : base;
1489
1393
  const value = rawValue?.[$TARGET]?.[STORE_VALUE] ?? rawValue;
1490
- if (prev === value)
1491
- return true;
1394
+ if (prev === value) return true;
1492
1395
  const len = target[STORE_OVERRIDE]?.length || state.length;
1493
- if (value !== void 0 && value === base)
1494
- delete target[STORE_OVERRIDE][property];
1396
+ if (value !== undefined && value === base) delete target[STORE_OVERRIDE][property];
1495
1397
  else
1496
- (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = value;
1398
+ (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = Object.create(null)))[property] =
1399
+ value;
1497
1400
  const wrappable = isWrappable(value);
1498
1401
  if (isWrappable(prev)) {
1499
1402
  const parents = PARENTS.get(prev);
1500
1403
  parents && (parents instanceof Set ? parents.delete(store) : PARENTS.delete(prev));
1501
1404
  }
1502
- if (recursivelyNotify(store, storeLookup) && wrappable)
1503
- recursivelyAddParent(value, store);
1405
+ if (recursivelyNotify(store, storeLookup) && wrappable) recursivelyAddParent(value, store);
1504
1406
  target[STORE_HAS]?.[property] && setSignal(target[STORE_HAS][property], true);
1505
1407
  const nodes = getNodes(target, STORE_NODE);
1506
- nodes[property] && setSignal(nodes[property], () => wrappable ? wrap(value, target) : value);
1408
+ nodes[property] &&
1409
+ setSignal(nodes[property], () => (wrappable ? wrap(value, target) : value));
1507
1410
  if (Array.isArray(state)) {
1508
1411
  const index = parseInt(property) + 1;
1509
- if (index > len)
1510
- nodes.length && setSignal(nodes.length, index);
1412
+ if (index > len) nodes.length && setSignal(nodes.length, index);
1511
1413
  }
1512
- nodes[$TRACK] && setSignal(nodes[$TRACK], void 0);
1414
+ nodes[$TRACK] && setSignal(nodes[$TRACK], undefined);
1513
1415
  });
1514
1416
  }
1515
1417
  return true;
@@ -1517,22 +1419,24 @@ var storeTraps = {
1517
1419
  deleteProperty(target, property) {
1518
1420
  if (Writing?.has(target[$PROXY]) && target[STORE_OVERRIDE]?.[property] !== $DELETED) {
1519
1421
  untrack(() => {
1520
- const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : target[STORE_VALUE][property];
1422
+ const prev =
1423
+ target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]
1424
+ ? target[STORE_OVERRIDE][property]
1425
+ : target[STORE_VALUE][property];
1521
1426
  if (property in target[STORE_VALUE]) {
1522
- (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
1427
+ (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = Object.create(null)))[property] =
1428
+ $DELETED;
1523
1429
  } else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
1524
1430
  delete target[STORE_OVERRIDE][property];
1525
- } else
1526
- return true;
1431
+ } else return true;
1527
1432
  if (isWrappable(prev)) {
1528
1433
  const parents = PARENTS.get(prev);
1529
1434
  parents && (parents instanceof Set ? parents.delete(target) : PARENTS.delete(prev));
1530
1435
  }
1531
- if (target[STORE_HAS]?.[property])
1532
- setSignal(target[STORE_HAS][property], false);
1436
+ if (target[STORE_HAS]?.[property]) setSignal(target[STORE_HAS][property], false);
1533
1437
  const nodes = getNodes(target, STORE_NODE);
1534
- nodes[property] && setSignal(nodes[property], void 0);
1535
- nodes[$TRACK] && setSignal(nodes[$TRACK], void 0);
1438
+ nodes[property] && setSignal(nodes[property], undefined);
1439
+ nodes[$TRACK] && setSignal(nodes[$TRACK], undefined);
1536
1440
  });
1537
1441
  }
1538
1442
  return true;
@@ -1542,8 +1446,7 @@ var storeTraps = {
1542
1446
  return getKeys(target[STORE_VALUE], target[STORE_OVERRIDE], false);
1543
1447
  },
1544
1448
  getOwnPropertyDescriptor(target, property) {
1545
- if (property === $PROXY)
1546
- return { value: target[$PROXY], writable: true, configurable: true };
1449
+ if (property === $PROXY) return { value: target[$PROXY], writable: true, configurable: true };
1547
1450
  return getPropertyDescriptor(target[STORE_VALUE], target[STORE_OVERRIDE], property);
1548
1451
  },
1549
1452
  getPrototypeOf(target) {
@@ -1552,22 +1455,19 @@ var storeTraps = {
1552
1455
  };
1553
1456
  function storeSetter(store, fn) {
1554
1457
  const prevWriting = Writing;
1555
- Writing = /* @__PURE__ */ new Set();
1458
+ Writing = new Set();
1556
1459
  Writing.add(store);
1557
1460
  try {
1558
1461
  const value = fn(store);
1559
- if (value !== store && value !== void 0) {
1462
+ if (value !== store && value !== undefined) {
1560
1463
  if (Array.isArray(value)) {
1561
- for (let i = 0, len = value.length; i < len; i++)
1562
- store[i] = value[i];
1464
+ for (let i = 0, len = value.length; i < len; i++) store[i] = value[i];
1563
1465
  store.length = value.length;
1564
1466
  } else {
1565
- const keys = /* @__PURE__ */ new Set([...Object.keys(store), ...Object.keys(value)]);
1566
- keys.forEach((key) => {
1567
- if (key in value)
1568
- store[key] = value[key];
1569
- else
1570
- delete store[key];
1467
+ const keys = new Set([...Object.keys(store), ...Object.keys(value)]);
1468
+ keys.forEach(key => {
1469
+ if (key in value) store[key] = value[key];
1470
+ else delete store[key];
1571
1471
  });
1572
1472
  }
1573
1473
  }
@@ -1577,28 +1477,26 @@ function storeSetter(store, fn) {
1577
1477
  }
1578
1478
  }
1579
1479
  function createStore(first, second, options) {
1580
- const derived = typeof first === "function", wrappedStore = derived ? createProjectionInternal(first, second, options).store : wrap(first);
1581
- return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
1480
+ const derived = typeof first === "function",
1481
+ wrappedStore = derived ? createProjectionInternal(first, second, options).store : wrap(first);
1482
+ return [wrappedStore, fn => storeSetter(wrappedStore, fn)];
1582
1483
  }
1583
1484
  function recursivelyNotify(state, lookup) {
1584
1485
  let target = state[$TARGET] || lookup?.get(state)?.[$TARGET];
1585
1486
  let notified = false;
1586
1487
  if (target) {
1587
- const deep2 = getNodes(target, STORE_NODE)[$DEEP];
1588
- if (deep2) {
1589
- setSignal(deep2, void 0);
1488
+ const deep = getNodes(target, STORE_NODE)[$DEEP];
1489
+ if (deep) {
1490
+ setSignal(deep, undefined);
1590
1491
  notified = true;
1591
1492
  }
1592
1493
  lookup = target[STORE_LOOKUP] || lookup;
1593
1494
  }
1594
1495
  const parents = PARENTS.get(target?.[STORE_VALUE] || state);
1595
- if (!parents)
1596
- return notified;
1496
+ if (!parents) return notified;
1597
1497
  if (parents instanceof Set) {
1598
- for (let parent of parents)
1599
- notified = recursivelyNotify(parent, lookup) || notified;
1600
- } else
1601
- notified = recursivelyNotify(parents, lookup) || notified;
1498
+ for (let parent of parents) notified = recursivelyNotify(parent, lookup) || notified;
1499
+ } else notified = recursivelyNotify(parents, lookup) || notified;
1602
1500
  return notified;
1603
1501
  }
1604
1502
  function recursivelyAddParent(state, parent) {
@@ -1610,16 +1508,12 @@ function recursivelyAddParent(state, parent) {
1610
1508
  }
1611
1509
  if (parent) {
1612
1510
  let parents = PARENTS.get(state);
1613
- if (!parents)
1614
- PARENTS.set(state, parent);
1511
+ if (!parents) PARENTS.set(state, parent);
1615
1512
  else if (parents !== parent) {
1616
- if (!(parents instanceof Set))
1617
- PARENTS.set(state, parents = /* @__PURE__ */ new Set([parents]));
1618
- else if (parents.has(parent))
1619
- return;
1513
+ if (!(parents instanceof Set)) PARENTS.set(state, (parents = new Set([parents])));
1514
+ else if (parents.has(parent)) return;
1620
1515
  parents.add(parent);
1621
- } else
1622
- return;
1516
+ } else return;
1623
1517
  }
1624
1518
  if (Array.isArray(state)) {
1625
1519
  const len = override?.length || state.length;
@@ -1640,27 +1534,22 @@ function deep(store) {
1640
1534
  recursivelyAddParent(store);
1641
1535
  return store[$DEEP];
1642
1536
  }
1643
-
1644
- // src/store/optimistic.ts
1645
1537
  function createOptimisticStore(first, second, options) {
1646
1538
  return [];
1647
1539
  }
1648
-
1649
- // src/store/utils.ts
1650
1540
  function snapshot(item, map, lookup) {
1651
1541
  let target, isArray, override, result, unwrapped, v;
1652
- if (!isWrappable(item))
1653
- return item;
1654
- if (map && map.has(item))
1655
- return map.get(item);
1656
- if (!map)
1657
- map = /* @__PURE__ */ new Map();
1658
- if (target = item[$TARGET] || lookup?.get(item)?.[$TARGET]) {
1542
+ if (!isWrappable(item)) return item;
1543
+ if (map && map.has(item)) return map.get(item);
1544
+ if (!map) map = new Map();
1545
+ if ((target = item[$TARGET] || lookup?.get(item)?.[$TARGET])) {
1659
1546
  override = target[STORE_OVERRIDE];
1660
1547
  isArray = Array.isArray(target[STORE_VALUE]);
1661
1548
  map.set(
1662
1549
  item,
1663
- override ? result = isArray ? [] : Object.create(Object.getPrototypeOf(target[STORE_VALUE])) : target[STORE_VALUE]
1550
+ override
1551
+ ? (result = isArray ? [] : Object.create(Object.getPrototypeOf(target[STORE_VALUE])))
1552
+ : target[STORE_VALUE]
1664
1553
  );
1665
1554
  item = target[STORE_VALUE];
1666
1555
  lookup = storeLookup;
@@ -1672,11 +1561,9 @@ function snapshot(item, map, lookup) {
1672
1561
  const len = override?.length || item.length;
1673
1562
  for (let i = 0; i < len; i++) {
1674
1563
  v = override && i in override ? override[i] : item[i];
1675
- if (v === $DELETED)
1676
- continue;
1564
+ if (v === $DELETED) continue;
1677
1565
  if ((unwrapped = snapshot(v, map, lookup)) !== v || result) {
1678
- if (!result)
1679
- map.set(item, result = [...item]);
1566
+ if (!result) map.set(item, (result = [...item]));
1680
1567
  result[i] = unwrapped;
1681
1568
  }
1682
1569
  }
@@ -1685,8 +1572,7 @@ function snapshot(item, map, lookup) {
1685
1572
  for (let i = 0, l = keys.length; i < l; i++) {
1686
1573
  let prop = keys[i];
1687
1574
  const desc = getPropertyDescriptor(item, override, prop);
1688
- if (desc.get)
1689
- continue;
1575
+ if (desc.get) continue;
1690
1576
  v = override && prop in override ? override[prop] : item[prop];
1691
1577
  if ((unwrapped = snapshot(v, map, lookup)) !== item[prop] || result) {
1692
1578
  if (!result) {
@@ -1702,15 +1588,13 @@ function snapshot(item, map, lookup) {
1702
1588
  function trueFn() {
1703
1589
  return true;
1704
1590
  }
1705
- var propTraps = {
1591
+ const propTraps = {
1706
1592
  get(_, property, receiver) {
1707
- if (property === $PROXY)
1708
- return receiver;
1593
+ if (property === $PROXY) return receiver;
1709
1594
  return _.get(property);
1710
1595
  },
1711
1596
  has(_, property) {
1712
- if (property === $PROXY)
1713
- return true;
1597
+ if (property === $PROXY) return true;
1714
1598
  return _.has(property);
1715
1599
  },
1716
1600
  set: trueFn,
@@ -1733,39 +1617,31 @@ var propTraps = {
1733
1617
  function resolveSource(s) {
1734
1618
  return !(s = typeof s === "function" ? s() : s) ? {} : s;
1735
1619
  }
1736
- var $SOURCES = Symbol("MERGE_SOURCE" );
1620
+ const $SOURCES = Symbol("MERGE_SOURCE");
1737
1621
  function merge(...sources) {
1738
- if (sources.length === 1 && typeof sources[0] !== "function")
1739
- return sources[0];
1622
+ if (sources.length === 1 && typeof sources[0] !== "function") return sources[0];
1740
1623
  let proxy = false;
1741
1624
  const flattened = [];
1742
1625
  for (let i = 0; i < sources.length; i++) {
1743
1626
  const s = sources[i];
1744
- proxy = proxy || !!s && $PROXY in s;
1627
+ proxy = proxy || (!!s && $PROXY in s);
1745
1628
  const childSources = !!s && s[$SOURCES];
1746
- if (childSources)
1747
- flattened.push(...childSources);
1748
- else
1749
- flattened.push(
1750
- typeof s === "function" ? (proxy = true, createMemo(s)) : s
1751
- );
1629
+ if (childSources) flattened.push(...childSources);
1630
+ else flattened.push(typeof s === "function" ? ((proxy = true), createMemo(s)) : s);
1752
1631
  }
1753
1632
  if (SUPPORTS_PROXY && proxy) {
1754
1633
  return new Proxy(
1755
1634
  {
1756
1635
  get(property) {
1757
- if (property === $SOURCES)
1758
- return flattened;
1636
+ if (property === $SOURCES) return flattened;
1759
1637
  for (let i = flattened.length - 1; i >= 0; i--) {
1760
1638
  const s = resolveSource(flattened[i]);
1761
- if (property in s)
1762
- return s[property];
1639
+ if (property in s) return s[property];
1763
1640
  }
1764
1641
  },
1765
1642
  has(property) {
1766
1643
  for (let i = flattened.length - 1; i >= 0; i--) {
1767
- if (property in resolveSource(flattened[i]))
1768
- return true;
1644
+ if (property in resolveSource(flattened[i])) return true;
1769
1645
  }
1770
1646
  return false;
1771
1647
  },
@@ -1779,7 +1655,7 @@ function merge(...sources) {
1779
1655
  propTraps
1780
1656
  );
1781
1657
  }
1782
- const defined = /* @__PURE__ */ Object.create(null);
1658
+ const defined = Object.create(null);
1783
1659
  let nonTargetKey = false;
1784
1660
  let lastIndex = flattened.length - 1;
1785
1661
  for (let i = lastIndex; i >= 0; i--) {
@@ -1791,29 +1667,24 @@ function merge(...sources) {
1791
1667
  const sourceKeys = Object.getOwnPropertyNames(source);
1792
1668
  for (let j = sourceKeys.length - 1; j >= 0; j--) {
1793
1669
  const key = sourceKeys[j];
1794
- if (key === "__proto__" || key === "constructor")
1795
- continue;
1670
+ if (key === "__proto__" || key === "constructor") continue;
1796
1671
  if (!defined[key]) {
1797
1672
  nonTargetKey = nonTargetKey || i !== lastIndex;
1798
1673
  const desc = Object.getOwnPropertyDescriptor(source, key);
1799
- defined[key] = desc.get ? {
1800
- enumerable: true,
1801
- configurable: true,
1802
- get: desc.get.bind(source)
1803
- } : desc;
1674
+ defined[key] = desc.get
1675
+ ? { enumerable: true, configurable: true, get: desc.get.bind(source) }
1676
+ : desc;
1804
1677
  }
1805
1678
  }
1806
1679
  }
1807
- if (!nonTargetKey)
1808
- return flattened[lastIndex];
1680
+ if (!nonTargetKey) return flattened[lastIndex];
1809
1681
  const target = {};
1810
1682
  const definedKeys = Object.keys(defined);
1811
1683
  for (let i = definedKeys.length - 1; i >= 0; i--) {
1812
- const key = definedKeys[i], desc = defined[key];
1813
- if (desc.get)
1814
- Object.defineProperty(target, key, desc);
1815
- else
1816
- target[key] = desc.value;
1684
+ const key = definedKeys[i],
1685
+ desc = defined[key];
1686
+ if (desc.get) Object.defineProperty(target, key, desc);
1687
+ else target[key] = desc.value;
1817
1688
  }
1818
1689
  target[$SOURCES] = flattened;
1819
1690
  return target;
@@ -1824,13 +1695,13 @@ function omit(props, ...keys) {
1824
1695
  return new Proxy(
1825
1696
  {
1826
1697
  get(property) {
1827
- return blocked.has(property) ? void 0 : props[property];
1698
+ return blocked.has(property) ? undefined : props[property];
1828
1699
  },
1829
1700
  has(property) {
1830
1701
  return !blocked.has(property) && property in props;
1831
1702
  },
1832
1703
  keys() {
1833
- return Object.keys(props).filter((k) => !blocked.has(k));
1704
+ return Object.keys(props).filter(k => !blocked.has(k));
1834
1705
  }
1835
1706
  },
1836
1707
  propTraps
@@ -1840,15 +1711,15 @@ function omit(props, ...keys) {
1840
1711
  for (const propName of Object.getOwnPropertyNames(props)) {
1841
1712
  if (!blocked.has(propName)) {
1842
1713
  const desc = Object.getOwnPropertyDescriptor(props, propName);
1843
- !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable ? result[propName] = desc.value : Object.defineProperty(result, propName, desc);
1714
+ !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable
1715
+ ? (result[propName] = desc.value)
1716
+ : Object.defineProperty(result, propName, desc);
1844
1717
  }
1845
1718
  }
1846
1719
  return result;
1847
1720
  }
1848
-
1849
- // src/map.ts
1850
1721
  function mapArray(list, map, options) {
1851
- const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1722
+ const keyFn = typeof options?.keyed === "function" ? options.keyed : undefined;
1852
1723
  return createMemo(
1853
1724
  updateKeyedMap.bind({
1854
1725
  _owner: createOwner(),
@@ -1859,35 +1730,39 @@ function mapArray(list, map, options) {
1859
1730
  _mappings: [],
1860
1731
  _nodes: [],
1861
1732
  _key: keyFn,
1862
- _rows: keyFn || options?.keyed === false ? [] : void 0,
1863
- _indexes: map.length > 1 ? [] : void 0,
1733
+ _rows: keyFn || options?.keyed === false ? [] : undefined,
1734
+ _indexes: map.length > 1 ? [] : undefined,
1864
1735
  _fallback: options?.fallback
1865
1736
  })
1866
1737
  );
1867
1738
  }
1868
- var pureOptions = { pureWrite: true };
1739
+ const pureOptions = { pureWrite: true };
1869
1740
  function updateKeyedMap() {
1870
- const newItems = this._list() || [], newLen = newItems.length;
1741
+ const newItems = this._list() || [],
1742
+ newLen = newItems.length;
1871
1743
  newItems[$TRACK];
1872
1744
  runWithOwner(this._owner, () => {
1873
- let i, j, mapper = this._rows ? () => {
1874
- this._rows[j] = signal(newItems[j], pureOptions);
1875
- this._indexes && (this._indexes[j] = signal(j, pureOptions));
1876
- return this._map(
1877
- read.bind(null, this._rows[j]),
1878
- this._indexes ? read.bind(null, this._indexes[j]) : void 0
1879
- );
1880
- } : this._indexes ? () => {
1881
- const item = newItems[j];
1882
- this._indexes[j] = signal(j, pureOptions);
1883
- return this._map(
1884
- () => item,
1885
- read.bind(null, this._indexes[j])
1886
- );
1887
- } : () => {
1888
- const item = newItems[j];
1889
- return this._map(() => item);
1890
- };
1745
+ let i,
1746
+ j,
1747
+ mapper = this._rows
1748
+ ? () => {
1749
+ this._rows[j] = signal(newItems[j], pureOptions);
1750
+ this._indexes && (this._indexes[j] = signal(j, pureOptions));
1751
+ return this._map(
1752
+ read.bind(null, this._rows[j]),
1753
+ this._indexes ? read.bind(null, this._indexes[j]) : undefined
1754
+ );
1755
+ }
1756
+ : this._indexes
1757
+ ? () => {
1758
+ const item = newItems[j];
1759
+ this._indexes[j] = signal(j, pureOptions);
1760
+ return this._map(() => item, read.bind(null, this._indexes[j]));
1761
+ }
1762
+ : () => {
1763
+ const item = newItems[j];
1764
+ return this._map(() => item);
1765
+ };
1891
1766
  if (newLen === 0) {
1892
1767
  if (this._len !== 0) {
1893
1768
  this._owner.dispose(false);
@@ -1899,54 +1774,71 @@ function updateKeyedMap() {
1899
1774
  this._indexes && (this._indexes = []);
1900
1775
  }
1901
1776
  if (this._fallback && !this._mappings[0]) {
1902
- this._mappings[0] = runWithOwner(
1903
- this._nodes[0] = createOwner(),
1904
- this._fallback
1905
- );
1777
+ this._mappings[0] = runWithOwner((this._nodes[0] = createOwner()), this._fallback);
1906
1778
  }
1907
1779
  } else if (this._len === 0) {
1908
- if (this._nodes[0])
1909
- this._nodes[0].dispose();
1780
+ if (this._nodes[0]) this._nodes[0].dispose();
1910
1781
  this._mappings = new Array(newLen);
1911
1782
  for (j = 0; j < newLen; j++) {
1912
1783
  this._items[j] = newItems[j];
1913
- this._mappings[j] = runWithOwner(this._nodes[j] = createOwner(), mapper);
1784
+ this._mappings[j] = runWithOwner((this._nodes[j] = createOwner()), mapper);
1914
1785
  }
1915
1786
  this._len = newLen;
1916
1787
  } else {
1917
- let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this._rows ? new Array(newLen) : void 0, tempIndexes = this._indexes ? new Array(newLen) : void 0;
1918
- for (start = 0, end = Math.min(this._len, newLen); start < end && (this._items[start] === newItems[start] || this._rows && compare(this._key, this._items[start], newItems[start])); start++) {
1919
- if (this._rows)
1920
- setSignal(this._rows[start], newItems[start]);
1788
+ let start,
1789
+ end,
1790
+ newEnd,
1791
+ item,
1792
+ key,
1793
+ newIndices,
1794
+ newIndicesNext,
1795
+ temp = new Array(newLen),
1796
+ tempNodes = new Array(newLen),
1797
+ tempRows = this._rows ? new Array(newLen) : undefined,
1798
+ tempIndexes = this._indexes ? new Array(newLen) : undefined;
1799
+ for (
1800
+ start = 0, end = Math.min(this._len, newLen);
1801
+ start < end &&
1802
+ (this._items[start] === newItems[start] ||
1803
+ (this._rows && compare(this._key, this._items[start], newItems[start])));
1804
+ start++
1805
+ ) {
1806
+ if (this._rows) setSignal(this._rows[start], newItems[start]);
1921
1807
  }
1922
- for (end = this._len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this._items[end] === newItems[newEnd] || this._rows && compare(this._key, this._items[end], newItems[newEnd])); end--, newEnd--) {
1808
+ for (
1809
+ end = this._len - 1, newEnd = newLen - 1;
1810
+ end >= start &&
1811
+ newEnd >= start &&
1812
+ (this._items[end] === newItems[newEnd] ||
1813
+ (this._rows && compare(this._key, this._items[end], newItems[newEnd])));
1814
+ end--, newEnd--
1815
+ ) {
1923
1816
  temp[newEnd] = this._mappings[end];
1924
1817
  tempNodes[newEnd] = this._nodes[end];
1925
1818
  tempRows && (tempRows[newEnd] = this._rows[end]);
1926
1819
  tempIndexes && (tempIndexes[newEnd] = this._indexes[end]);
1927
1820
  }
1928
- newIndices = /* @__PURE__ */ new Map();
1821
+ newIndices = new Map();
1929
1822
  newIndicesNext = new Array(newEnd + 1);
1930
1823
  for (j = newEnd; j >= start; j--) {
1931
1824
  item = newItems[j];
1932
1825
  key = this._key ? this._key(item) : item;
1933
1826
  i = newIndices.get(key);
1934
- newIndicesNext[j] = i === void 0 ? -1 : i;
1827
+ newIndicesNext[j] = i === undefined ? -1 : i;
1935
1828
  newIndices.set(key, j);
1936
1829
  }
1937
1830
  for (i = start; i <= end; i++) {
1938
1831
  item = this._items[i];
1939
1832
  key = this._key ? this._key(item) : item;
1940
1833
  j = newIndices.get(key);
1941
- if (j !== void 0 && j !== -1) {
1834
+ if (j !== undefined && j !== -1) {
1942
1835
  temp[j] = this._mappings[i];
1943
1836
  tempNodes[j] = this._nodes[i];
1944
1837
  tempRows && (tempRows[j] = this._rows[i]);
1945
1838
  tempIndexes && (tempIndexes[j] = this._indexes[i]);
1946
1839
  j = newIndicesNext[j];
1947
1840
  newIndices.set(key, j);
1948
- } else
1949
- this._nodes[i].dispose();
1841
+ } else this._nodes[i].dispose();
1950
1842
  }
1951
1843
  for (j = start; j < newLen; j++) {
1952
1844
  if (j in temp) {
@@ -1961,10 +1853,10 @@ function updateKeyedMap() {
1961
1853
  setSignal(this._indexes[j], j);
1962
1854
  }
1963
1855
  } else {
1964
- this._mappings[j] = runWithOwner(this._nodes[j] = createOwner(), mapper);
1856
+ this._mappings[j] = runWithOwner((this._nodes[j] = createOwner()), mapper);
1965
1857
  }
1966
1858
  }
1967
- this._mappings = this._mappings.slice(0, this._len = newLen);
1859
+ this._mappings = this._mappings.slice(0, (this._len = newLen));
1968
1860
  this._items = newItems.slice(0);
1969
1861
  }
1970
1862
  });
@@ -1995,23 +1887,17 @@ function updateRepeat() {
1995
1887
  this._len = 0;
1996
1888
  }
1997
1889
  if (this._fallback && !this._mappings[0]) {
1998
- this._mappings[0] = runWithOwner(
1999
- this._nodes[0] = createOwner(),
2000
- this._fallback
2001
- );
1890
+ this._mappings[0] = runWithOwner((this._nodes[0] = createOwner()), this._fallback);
2002
1891
  }
2003
1892
  return;
2004
1893
  }
2005
1894
  const to = from + newLen;
2006
1895
  const prevTo = this._offset + this._len;
2007
- if (this._len === 0 && this._nodes[0])
2008
- this._nodes[0].dispose();
2009
- for (let i = to; i < prevTo; i++)
2010
- this._nodes[i - this._offset].dispose();
1896
+ if (this._len === 0 && this._nodes[0]) this._nodes[0].dispose();
1897
+ for (let i = to; i < prevTo; i++) this._nodes[i - this._offset].dispose();
2011
1898
  if (this._offset < from) {
2012
1899
  let i = this._offset;
2013
- while (i < from && i < this._len)
2014
- this._nodes[i++].dispose();
1900
+ while (i < from && i < this._len) this._nodes[i++].dispose();
2015
1901
  this._nodes.splice(0, from - this._offset);
2016
1902
  this._mappings.splice(0, from - this._offset);
2017
1903
  } else if (this._offset > from) {
@@ -2023,17 +1909,15 @@ function updateRepeat() {
2023
1909
  this._mappings[i] = this._mappings[i - difference];
2024
1910
  i--;
2025
1911
  }
2026
- for (let i2 = 0; i2 < difference; i2++) {
2027
- this._mappings[i2] = runWithOwner(
2028
- this._nodes[i2] = createOwner(),
2029
- () => this._map(i2 + from)
1912
+ for (let i = 0; i < difference; i++) {
1913
+ this._mappings[i] = runWithOwner((this._nodes[i] = createOwner()), () =>
1914
+ this._map(i + from)
2030
1915
  );
2031
1916
  }
2032
1917
  }
2033
1918
  for (let i = prevTo; i < to; i++) {
2034
- this._mappings[i - from] = runWithOwner(
2035
- this._nodes[i - from] = createOwner(),
2036
- () => this._map(i)
1919
+ this._mappings[i - from] = runWithOwner((this._nodes[i - from] = createOwner()), () =>
1920
+ this._map(i)
2037
1921
  );
2038
1922
  }
2039
1923
  this._mappings = this._mappings.slice(0, newLen);
@@ -2045,16 +1929,14 @@ function updateRepeat() {
2045
1929
  function compare(key, a, b) {
2046
1930
  return key ? key(a) === key(b) : true;
2047
1931
  }
2048
-
2049
- // src/boundaries.ts
2050
1932
  function boundaryComputed(fn, propagationMask) {
2051
- const node = computed(fn, void 0, {
1933
+ const node = computed(fn, undefined, {
2052
1934
  _internal: {
2053
1935
  _notifyQueue() {
2054
1936
  let flags = this._statusFlags;
2055
1937
  this._statusFlags &= ~this._propagationMask;
2056
- if (this._propagationMask & 1 /* Pending */ && !(this._statusFlags & 4 /* Uninitialized */)) {
2057
- flags &= ~1 /* Pending */;
1938
+ if (this._propagationMask & STATUS_PENDING && !(this._statusFlags & STATUS_UNINITIALIZED)) {
1939
+ flags &= ~STATUS_PENDING;
2058
1940
  }
2059
1941
  this._queue.notify(this, this._propagationMask, flags);
2060
1942
  },
@@ -2066,49 +1948,46 @@ function boundaryComputed(fn, propagationMask) {
2066
1948
  }
2067
1949
  function createBoundChildren(owner, fn, queue, mask) {
2068
1950
  const parentQueue = owner._queue;
2069
- parentQueue.addChild(owner._queue = queue);
1951
+ parentQueue.addChild((owner._queue = queue));
2070
1952
  onCleanup(() => parentQueue.removeChild(owner._queue));
2071
1953
  return runWithOwner(owner, () => {
2072
1954
  const c = computed(fn);
2073
1955
  return boundaryComputed(() => staleValues(() => flatten(read(c))), mask);
2074
1956
  });
2075
1957
  }
2076
- var ConditionalQueue = class extends Queue {
1958
+ class ConditionalQueue extends Queue {
2077
1959
  _disabled;
2078
- _errorNodes = /* @__PURE__ */ new Set();
2079
- _pendingNodes = /* @__PURE__ */ new Set();
1960
+ _errorNodes = new Set();
1961
+ _pendingNodes = new Set();
2080
1962
  constructor(disabled) {
2081
1963
  super();
2082
1964
  this._disabled = disabled;
2083
1965
  }
2084
1966
  run(type) {
2085
- if (!type || read(this._disabled))
2086
- return;
1967
+ if (!type || read(this._disabled)) return;
2087
1968
  return super.run(type);
2088
1969
  }
2089
1970
  notify(node, type, flags) {
2090
1971
  if (read(this._disabled)) {
2091
- if (type & 1 /* Pending */) {
2092
- if (flags & 1 /* Pending */) {
1972
+ if (type & STATUS_PENDING) {
1973
+ if (flags & STATUS_PENDING) {
2093
1974
  this._pendingNodes.add(node);
2094
- type &= ~1 /* Pending */;
2095
- } else if (this._pendingNodes.delete(node))
2096
- type &= ~1 /* Pending */;
1975
+ type &= ~STATUS_PENDING;
1976
+ } else if (this._pendingNodes.delete(node)) type &= ~STATUS_PENDING;
2097
1977
  }
2098
- if (type & 2 /* Error */) {
2099
- if (flags & 2 /* Error */) {
1978
+ if (type & STATUS_ERROR) {
1979
+ if (flags & STATUS_ERROR) {
2100
1980
  this._errorNodes.add(node);
2101
- type &= ~2 /* Error */;
2102
- } else if (this._errorNodes.delete(node))
2103
- type &= ~2 /* Error */;
1981
+ type &= ~STATUS_ERROR;
1982
+ } else if (this._errorNodes.delete(node)) type &= ~STATUS_ERROR;
2104
1983
  }
2105
1984
  }
2106
1985
  return type ? super.notify(node, type, flags) : true;
2107
1986
  }
2108
- };
2109
- var CollectionQueue = class extends Queue {
1987
+ }
1988
+ class CollectionQueue extends Queue {
2110
1989
  _collectionType;
2111
- _nodes = /* @__PURE__ */ new Set();
1990
+ _nodes = new Set();
2112
1991
  _disabled = signal(false, { pureWrite: true });
2113
1992
  _initialized = false;
2114
1993
  constructor(type) {
@@ -2116,43 +1995,46 @@ var CollectionQueue = class extends Queue {
2116
1995
  this._collectionType = type;
2117
1996
  }
2118
1997
  run(type) {
2119
- if (!type || read(this._disabled))
2120
- return;
1998
+ if (!type || read(this._disabled)) return;
2121
1999
  return super.run(type);
2122
2000
  }
2123
2001
  notify(node, type, flags) {
2124
- if (!(type & this._collectionType) || this._collectionType & 1 /* Pending */ && this._initialized)
2002
+ if (
2003
+ !(type & this._collectionType) ||
2004
+ (this._collectionType & STATUS_PENDING && this._initialized)
2005
+ )
2125
2006
  return super.notify(node, type, flags);
2126
2007
  if (flags & this._collectionType) {
2127
2008
  this._nodes.add(node);
2128
- if (this._nodes.size === 1)
2129
- setSignal(this._disabled, true);
2009
+ if (this._nodes.size === 1) setSignal(this._disabled, true);
2130
2010
  } else if (this._nodes.size > 0) {
2131
2011
  this._nodes.delete(node);
2132
- if (this._nodes.size === 0)
2133
- setSignal(this._disabled, false);
2012
+ if (this._nodes.size === 0) setSignal(this._disabled, false);
2134
2013
  }
2135
2014
  type &= ~this._collectionType;
2136
2015
  return type ? super.notify(node, type, flags) : true;
2137
2016
  }
2138
- };
2017
+ }
2018
+ var BoundaryMode;
2019
+ (function (BoundaryMode) {
2020
+ BoundaryMode["VISIBLE"] = "visible";
2021
+ BoundaryMode["HIDDEN"] = "hidden";
2022
+ })(BoundaryMode || (BoundaryMode = {}));
2139
2023
  function createBoundary(fn, condition) {
2140
2024
  const owner = createOwner();
2141
- const queue = new ConditionalQueue(computed(() => condition() === "hidden" /* HIDDEN */));
2025
+ const queue = new ConditionalQueue(computed(() => condition() === BoundaryMode.HIDDEN));
2142
2026
  const tree = createBoundChildren(owner, fn, queue, 0);
2143
2027
  computed(() => {
2144
2028
  const disabled = read(queue._disabled);
2145
- tree._propagationMask = disabled ? 2 /* Error */ | 1 /* Pending */ : 0;
2029
+ tree._propagationMask = disabled ? STATUS_ERROR | STATUS_PENDING : 0;
2146
2030
  if (!disabled) {
2147
- queue._pendingNodes.forEach(
2148
- (node) => queue.notify(node, 1 /* Pending */, 1 /* Pending */)
2149
- );
2150
- queue._errorNodes.forEach((node) => queue.notify(node, 2 /* Error */, 2 /* Error */));
2031
+ queue._pendingNodes.forEach(node => queue.notify(node, STATUS_PENDING, STATUS_PENDING));
2032
+ queue._errorNodes.forEach(node => queue.notify(node, STATUS_ERROR, STATUS_ERROR));
2151
2033
  queue._pendingNodes.clear();
2152
2034
  queue._errorNodes.clear();
2153
2035
  }
2154
2036
  });
2155
- return () => read(queue._disabled) ? void 0 : read(tree);
2037
+ return () => (read(queue._disabled) ? undefined : read(tree));
2156
2038
  }
2157
2039
  function createCollectionBoundary(type, fn, fallback) {
2158
2040
  const owner = createOwner();
@@ -2161,8 +2043,7 @@ function createCollectionBoundary(type, fn, fallback) {
2161
2043
  const decision = computed(() => {
2162
2044
  if (!read(queue._disabled)) {
2163
2045
  const resolved = read(tree);
2164
- if (!untrack(() => read(queue._disabled)))
2165
- queue._initialized = true;
2046
+ if (!untrack(() => read(queue._disabled))) queue._initialized = true;
2166
2047
  return resolved;
2167
2048
  }
2168
2049
  return fallback(queue);
@@ -2170,27 +2051,43 @@ function createCollectionBoundary(type, fn, fallback) {
2170
2051
  return read.bind(null, decision);
2171
2052
  }
2172
2053
  function createLoadBoundary(fn, fallback) {
2173
- return createCollectionBoundary(1 /* Pending */, fn, () => fallback());
2054
+ return createCollectionBoundary(STATUS_PENDING, fn, () => fallback());
2055
+ }
2056
+ function collectErrorSources(node, sources) {
2057
+ let root = true;
2058
+ let dep = node._deps;
2059
+ while (dep !== null) {
2060
+ const source = dep._dep;
2061
+ if (source._deps && source._statusFlags & STATUS_ERROR) {
2062
+ root = false;
2063
+ collectErrorSources(source, sources);
2064
+ }
2065
+ dep = dep._nextDep;
2066
+ }
2067
+ root && sources.push(node);
2174
2068
  }
2175
2069
  function createErrorBoundary(fn, fallback) {
2176
- return createCollectionBoundary(2 /* Error */, fn, (queue) => {
2070
+ return createCollectionBoundary(STATUS_ERROR, fn, queue => {
2177
2071
  let node = queue._nodes.values().next().value;
2178
2072
  return fallback(node._error, () => {
2179
- for (let node2 of queue._nodes) {
2180
- recompute(node2, true);
2181
- }
2073
+ const sources = [];
2074
+ for (const node of queue._nodes) collectErrorSources(node, sources);
2075
+ for (const source of sources) recompute(source);
2076
+ schedule();
2182
2077
  });
2183
2078
  });
2184
2079
  }
2185
2080
  function flatten(children, options) {
2186
2081
  if (typeof children === "function" && !children.length) {
2187
- if (options?.doNotUnwrap)
2188
- return children;
2082
+ if (options?.doNotUnwrap) return children;
2189
2083
  do {
2190
2084
  children = children();
2191
2085
  } while (typeof children === "function" && !children.length);
2192
2086
  }
2193
- if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
2087
+ if (
2088
+ options?.skipNonRendered &&
2089
+ (children == null || children === true || children === false || children === "")
2090
+ )
2194
2091
  return;
2195
2092
  if (Array.isArray(children)) {
2196
2093
  let results = [];
@@ -2223,18 +2120,64 @@ function flattenArray(children, results = [], options) {
2223
2120
  }
2224
2121
  if (Array.isArray(child)) {
2225
2122
  needsUnwrap = flattenArray(child, results, options);
2226
- } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
2227
- } else
2228
- results.push(child);
2123
+ } else if (
2124
+ options?.skipNonRendered &&
2125
+ (child == null || child === true || child === false || child === "")
2126
+ ) {
2127
+ } else results.push(child);
2229
2128
  } catch (e) {
2230
- if (!(e instanceof NotReadyError))
2231
- throw e;
2129
+ if (!(e instanceof NotReadyError)) throw e;
2232
2130
  notReady = e;
2233
2131
  }
2234
2132
  }
2235
- if (notReady)
2236
- throw notReady;
2133
+ if (notReady) throw notReady;
2237
2134
  return needsUnwrap;
2238
2135
  }
2239
-
2240
- export { $PROXY, $TARGET, $TRACK, ContextNotFoundError, NoOwnerError, NotReadyError, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createLoadBoundary, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createTrackedEffect, deep, flatten, flush, getContext, getNextChildId, getObserver, getOwner, isEqual, isPending, isWrappable, mapArray, merge, omit, onCleanup, onSettled, pending, reconcile, repeat, resolve, runWithOwner, setContext, snapshot, untrack };
2136
+ export {
2137
+ $PROXY,
2138
+ $TARGET,
2139
+ $TRACK,
2140
+ ContextNotFoundError,
2141
+ NoOwnerError,
2142
+ NotReadyError,
2143
+ SUPPORTS_PROXY,
2144
+ createAsync,
2145
+ createBoundary,
2146
+ createContext,
2147
+ createEffect,
2148
+ createErrorBoundary,
2149
+ createLoadBoundary,
2150
+ createMemo,
2151
+ createOptimistic,
2152
+ createOptimisticStore,
2153
+ createProjection,
2154
+ createReaction,
2155
+ createRenderEffect,
2156
+ createRoot,
2157
+ createSignal,
2158
+ createStore,
2159
+ createTrackedEffect,
2160
+ deep,
2161
+ flatten,
2162
+ flush,
2163
+ getContext,
2164
+ getNextChildId,
2165
+ getObserver,
2166
+ getOwner,
2167
+ isEqual,
2168
+ isPending,
2169
+ isWrappable,
2170
+ mapArray,
2171
+ merge,
2172
+ omit,
2173
+ onCleanup,
2174
+ onSettled,
2175
+ pending,
2176
+ reconcile,
2177
+ repeat,
2178
+ resolve,
2179
+ runWithOwner,
2180
+ setContext,
2181
+ snapshot,
2182
+ untrack
2183
+ };