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