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