@slimlib/store 2.2.3 → 2.2.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/README.md +2 -0
- package/index.mjs +211 -131
- package/package.json +1 -1
package/README.md
CHANGED
package/index.mjs
CHANGED
|
@@ -16,23 +16,24 @@ const [unwrap, propertyDepsSymbol, trackSymbol, childrenSymbol, parentSymbol,
|
|
|
16
16
|
|
|
17
17
|
] = Array.from([, , , , ,], Symbol);
|
|
18
18
|
|
|
19
|
+
/* v8 ignore next -- @preserve */
|
|
19
20
|
const noopGetter = () => undefined;
|
|
20
21
|
|
|
21
22
|
class DepsSet extends Set {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
c = 0;
|
|
24
|
+
d;
|
|
24
25
|
constructor(getter) {
|
|
25
26
|
super();
|
|
26
|
-
this.
|
|
27
|
+
this.d = getter;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
const createSourceEntry = (dependents, node, version, getter, storedValue) => ({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
f: dependents,
|
|
33
|
+
g: node,
|
|
34
|
+
c: version,
|
|
35
|
+
d: getter,
|
|
36
|
+
h: storedValue,
|
|
36
37
|
});
|
|
37
38
|
let flushScheduled = false;
|
|
38
39
|
|
|
@@ -49,7 +50,7 @@ const setTracked = (value) => {
|
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
const batchedAdd = (node) => {
|
|
52
|
-
const nodeId = node.
|
|
53
|
+
const nodeId = node.k;
|
|
53
54
|
|
|
54
55
|
if (nodeId < lastAddedId) {
|
|
55
56
|
needsSort = true;
|
|
@@ -70,7 +71,8 @@ const unwrapValue = (value) => (value !== null &&
|
|
|
70
71
|
|
|
71
72
|
const makeLive = (node) => {
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
|
|
75
|
+
if ((node.l & (1 | 2 | 4 )) === 0 && node.k !== globalVersion) {
|
|
74
76
|
const prevTracked = tracked;
|
|
75
77
|
tracked = false;
|
|
76
78
|
try {
|
|
@@ -78,60 +80,61 @@ const makeLive = (node) => {
|
|
|
78
80
|
}
|
|
79
81
|
catch {
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
|
|
84
|
+
if (node.k !== globalVersion)
|
|
85
|
+
node.l |= 1 ;
|
|
83
86
|
}
|
|
84
87
|
finally {
|
|
85
88
|
tracked = prevTracked;
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
|
-
node.
|
|
89
|
-
const nodeSources = node.
|
|
91
|
+
node.l |= 64 ;
|
|
92
|
+
const nodeSources = node.m;
|
|
90
93
|
for (let i = 0, len = nodeSources.length; i < len; ++i) {
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
if (sourceNode !== undefined && (sourceNode.
|
|
94
|
+
const { f: f, g: sourceNode } = nodeSources[i];
|
|
95
|
+
f.add(node);
|
|
96
|
+
if (sourceNode !== undefined && (sourceNode.l & (8 | 64 )) === 0) {
|
|
94
97
|
makeLive(sourceNode);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
};
|
|
98
101
|
|
|
99
102
|
const makeNonLive = (node) => {
|
|
100
|
-
node.
|
|
101
|
-
const nodeSources = node.
|
|
103
|
+
node.l &= -65 ;
|
|
104
|
+
const nodeSources = node.m;
|
|
102
105
|
for (let i = 0, len = nodeSources.length; i < len; ++i) {
|
|
103
|
-
const {
|
|
104
|
-
|
|
106
|
+
const { f: f, g: sourceNode } = nodeSources[i];
|
|
107
|
+
f.delete(node);
|
|
105
108
|
|
|
106
109
|
if (sourceNode !== undefined &&
|
|
107
|
-
(sourceNode.
|
|
108
|
-
sourceNode.
|
|
110
|
+
(sourceNode.l & (8 | 64 )) === 64 &&
|
|
111
|
+
sourceNode.n.size === 0) {
|
|
109
112
|
makeNonLive(sourceNode);
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
};
|
|
113
116
|
|
|
114
117
|
const clearSources = (node, fromIndex = 0) => {
|
|
115
|
-
const nodeSources = node.
|
|
118
|
+
const nodeSources = node.m;
|
|
116
119
|
|
|
117
|
-
if ((node.
|
|
120
|
+
if ((node.l & (8 | 64 )) === 0) {
|
|
118
121
|
nodeSources.length = fromIndex;
|
|
119
122
|
return;
|
|
120
123
|
}
|
|
121
124
|
for (let i = fromIndex, len = nodeSources.length; i < len; ++i) {
|
|
122
|
-
const {
|
|
125
|
+
const { f: f, g: sourceNode } = nodeSources[i];
|
|
123
126
|
|
|
124
127
|
let retained = false;
|
|
125
128
|
for (let j = 0; j < fromIndex && !retained; ++j) {
|
|
126
|
-
retained = nodeSources[j].
|
|
129
|
+
retained = nodeSources[j].f === f;
|
|
127
130
|
}
|
|
128
131
|
if (!retained) {
|
|
129
132
|
|
|
130
|
-
|
|
133
|
+
f.delete(node);
|
|
131
134
|
|
|
132
135
|
if (sourceNode !== undefined &&
|
|
133
|
-
(sourceNode.
|
|
134
|
-
sourceNode.
|
|
136
|
+
(sourceNode.l & (8 | 64 )) === 64 &&
|
|
137
|
+
sourceNode.n.size === 0) {
|
|
135
138
|
makeNonLive(sourceNode);
|
|
136
139
|
}
|
|
137
140
|
}
|
|
@@ -142,18 +145,20 @@ const clearSources = (node, fromIndex = 0) => {
|
|
|
142
145
|
const flushEffects = () => {
|
|
143
146
|
flushScheduled = false;
|
|
144
147
|
|
|
148
|
+
|
|
145
149
|
const nodes = batched.slice();
|
|
146
150
|
batched.length = 0;
|
|
147
151
|
if (needsSort) {
|
|
148
|
-
nodes.sort((a, b) => a.
|
|
152
|
+
nodes.sort((a, b) => a.k - b.k);
|
|
149
153
|
}
|
|
150
154
|
lastAddedId = 0;
|
|
151
155
|
needsSort = false;
|
|
152
156
|
|
|
157
|
+
|
|
153
158
|
for (let i = 0, len = nodes.length; i < len; ++i) {
|
|
154
159
|
const node = nodes[i];
|
|
155
160
|
try {
|
|
156
|
-
node.
|
|
161
|
+
node.o();
|
|
157
162
|
}
|
|
158
163
|
catch (e) {
|
|
159
164
|
console.error(e);
|
|
@@ -170,11 +175,11 @@ const scheduleFlush = () => {
|
|
|
170
175
|
|
|
171
176
|
const trackStateDependency = (deps, cachedValue) => {
|
|
172
177
|
|
|
173
|
-
const sourcesArray = currentComputing.
|
|
174
|
-
const skipIndex = currentComputing.
|
|
178
|
+
const sourcesArray = currentComputing.m;
|
|
179
|
+
const skipIndex = currentComputing.q;
|
|
175
180
|
const existing = sourcesArray[skipIndex];
|
|
176
181
|
const noSource = existing === undefined;
|
|
177
|
-
if (noSource || existing.
|
|
182
|
+
if (noSource || existing.f !== deps) {
|
|
178
183
|
const previous = skipIndex === 0 ? undefined : sourcesArray[skipIndex - 1];
|
|
179
184
|
|
|
180
185
|
if (!noSource) {
|
|
@@ -182,44 +187,49 @@ const trackStateDependency = (deps, cachedValue) => {
|
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
if (previous !== undefined &&
|
|
185
|
-
previous.
|
|
186
|
-
previous.
|
|
187
|
-
Object.is(previous.
|
|
190
|
+
previous.f === deps &&
|
|
191
|
+
previous.c === deps.c &&
|
|
192
|
+
Object.is(previous.h, cachedValue)) {
|
|
188
193
|
return;
|
|
189
194
|
}
|
|
190
195
|
|
|
191
|
-
sourcesArray.push(createSourceEntry(deps, undefined, deps.a, deps.b, cachedValue));
|
|
192
196
|
|
|
193
|
-
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
sourcesArray.push(createSourceEntry(deps, undefined, deps.c, deps.d, cachedValue));
|
|
200
|
+
|
|
201
|
+
if ((currentComputing.l & (8 | 64 )) !== 0) {
|
|
194
202
|
deps.add(currentComputing);
|
|
195
203
|
}
|
|
196
204
|
}
|
|
197
205
|
else {
|
|
198
206
|
|
|
199
207
|
const entry = sourcesArray[skipIndex];
|
|
200
|
-
entry.
|
|
201
|
-
entry.
|
|
208
|
+
entry.c = deps.c;
|
|
209
|
+
entry.h = cachedValue;
|
|
202
210
|
}
|
|
203
|
-
++currentComputing.
|
|
211
|
+
++currentComputing.q;
|
|
204
212
|
};
|
|
205
213
|
|
|
206
214
|
const markNeedsCheck = (node) => {
|
|
207
|
-
const flags = node.
|
|
215
|
+
const flags = node.l;
|
|
216
|
+
|
|
208
217
|
|
|
209
218
|
if ((flags & (4 | 1 | 2 )) !== 0) {
|
|
210
219
|
|
|
220
|
+
|
|
211
221
|
if ((flags & (4 | 8 | 1 )) === (4 | 8 )) {
|
|
212
|
-
node.
|
|
222
|
+
node.l = flags | 1 ;
|
|
213
223
|
batchedAdd(node);
|
|
214
224
|
}
|
|
215
225
|
return;
|
|
216
226
|
}
|
|
217
227
|
|
|
218
|
-
node.
|
|
228
|
+
node.l = flags | 2 ;
|
|
219
229
|
if ((flags & 8 ) !== 0) {
|
|
220
230
|
batchedAdd(node);
|
|
221
231
|
}
|
|
222
|
-
for (const dep of node.
|
|
232
|
+
for (const dep of node.n) {
|
|
223
233
|
markNeedsCheck(dep);
|
|
224
234
|
}
|
|
225
235
|
};
|
|
@@ -227,7 +237,7 @@ const markNeedsCheck = (node) => {
|
|
|
227
237
|
const markDependents = (deps, schedule = true) => {
|
|
228
238
|
++globalVersion;
|
|
229
239
|
|
|
230
|
-
++deps.
|
|
240
|
+
++deps.c;
|
|
231
241
|
for (const dep of deps) {
|
|
232
242
|
markNeedsCheck(dep);
|
|
233
243
|
}
|
|
@@ -238,8 +248,10 @@ const markDependents = (deps, schedule = true) => {
|
|
|
238
248
|
|
|
239
249
|
const runWithTracking = (node, getter) => {
|
|
240
250
|
|
|
241
|
-
|
|
242
|
-
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
node.l = (node.l & -132) | 4 ;
|
|
254
|
+
node.q = 0;
|
|
243
255
|
const prev = currentComputing;
|
|
244
256
|
const prevTracked = tracked;
|
|
245
257
|
currentComputing = node;
|
|
@@ -251,18 +263,18 @@ const runWithTracking = (node, getter) => {
|
|
|
251
263
|
currentComputing = prev;
|
|
252
264
|
tracked = prevTracked;
|
|
253
265
|
|
|
254
|
-
const flags = (node.
|
|
255
|
-
const nodeSources = node.
|
|
256
|
-
const skipped = node.
|
|
266
|
+
const flags = (node.l &= -5 );
|
|
267
|
+
const nodeSources = node.m;
|
|
268
|
+
const skipped = node.q;
|
|
257
269
|
const nodeSourcesLength = nodeSources.length;
|
|
258
270
|
|
|
259
271
|
if ((flags & 128 ) !== 0) {
|
|
260
272
|
const updateLen = Math.min(skipped, nodeSourcesLength);
|
|
261
273
|
for (let i = 0; i < updateLen; ++i) {
|
|
262
274
|
const entry = nodeSources[i];
|
|
263
|
-
const entryNode = entry.
|
|
275
|
+
const entryNode = entry.g;
|
|
264
276
|
if (entryNode !== undefined) {
|
|
265
|
-
entry.
|
|
277
|
+
entry.c = entryNode.c;
|
|
266
278
|
}
|
|
267
279
|
}
|
|
268
280
|
}
|
|
@@ -291,9 +303,9 @@ const checkSources = (sourcesArray) => {
|
|
|
291
303
|
const len = sourcesArray.length;
|
|
292
304
|
for (let i = 0; i < len; ++i) {
|
|
293
305
|
const sourceEntry = sourcesArray[i];
|
|
294
|
-
const sourceNode = sourceEntry.
|
|
306
|
+
const sourceNode = sourceEntry.g;
|
|
295
307
|
if (sourceNode === undefined) {
|
|
296
|
-
if (sourceEntry.
|
|
308
|
+
if (sourceEntry.c !== sourceEntry.f.c) {
|
|
297
309
|
tracked = prevTracked;
|
|
298
310
|
return true;
|
|
299
311
|
}
|
|
@@ -309,7 +321,8 @@ const checkSources = (sourcesArray) => {
|
|
|
309
321
|
return true;
|
|
310
322
|
}
|
|
311
323
|
|
|
312
|
-
|
|
324
|
+
|
|
325
|
+
if (sourceEntry.c !== sourceNode.c) {
|
|
313
326
|
tracked = prevTracked;
|
|
314
327
|
return true;
|
|
315
328
|
}
|
|
@@ -344,7 +357,7 @@ const safeForEach = (fns) => {
|
|
|
344
357
|
};
|
|
345
358
|
|
|
346
359
|
const warnIfWriteInComputed = (context) => {
|
|
347
|
-
if (DEV && (debugConfigFlags & WARN_ON_WRITE_IN_COMPUTED) !== 0 && currentComputing && (currentComputing.
|
|
360
|
+
if (DEV && (debugConfigFlags & WARN_ON_WRITE_IN_COMPUTED) !== 0 && currentComputing && (currentComputing.l & 8 ) === 0) {
|
|
348
361
|
console.warn(`[@slimlib/store] Writing to ${context} inside a computed is not recommended. The computed will not automatically re-run when this value changes, which may lead to stale values.`);
|
|
349
362
|
}
|
|
350
363
|
};
|
|
@@ -361,6 +374,7 @@ const registerEffect = DEV
|
|
|
361
374
|
? () => {
|
|
362
375
|
const token = {};
|
|
363
376
|
|
|
377
|
+
|
|
364
378
|
const relevantStack = String(new Error().stack).split('\n').slice(3).join('\n');
|
|
365
379
|
effectRegistry.register(token, relevantStack, token);
|
|
366
380
|
return token;
|
|
@@ -384,50 +398,55 @@ const cycleMessage = 'Detected cycle in computations.';
|
|
|
384
398
|
|
|
385
399
|
function computedRead(self) {
|
|
386
400
|
|
|
401
|
+
|
|
387
402
|
if (tracked && currentComputing !== undefined) {
|
|
388
403
|
|
|
389
|
-
const consumerSources = currentComputing.
|
|
390
|
-
const skipIndex = currentComputing.
|
|
391
|
-
const deps = self.
|
|
404
|
+
const consumerSources = currentComputing.m;
|
|
405
|
+
const skipIndex = currentComputing.q;
|
|
406
|
+
const deps = self.n;
|
|
392
407
|
const existing = consumerSources[skipIndex];
|
|
393
408
|
const noSource = existing === undefined;
|
|
394
|
-
if (noSource || existing.
|
|
409
|
+
if (noSource || existing.f !== deps) {
|
|
395
410
|
if (!noSource) {
|
|
396
411
|
clearSources(currentComputing, skipIndex);
|
|
397
412
|
}
|
|
398
413
|
|
|
414
|
+
|
|
399
415
|
consumerSources.push(createSourceEntry(deps, self, 0, undefined, undefined));
|
|
400
416
|
|
|
401
|
-
if ((currentComputing.
|
|
417
|
+
if ((currentComputing.l & (8 | 64 )) !== 0) {
|
|
402
418
|
deps.add(currentComputing);
|
|
403
419
|
|
|
404
|
-
if ((self.
|
|
420
|
+
if ((self.l & 64 ) === 0) {
|
|
405
421
|
makeLive(self);
|
|
406
422
|
}
|
|
407
423
|
}
|
|
408
424
|
}
|
|
409
425
|
|
|
410
|
-
currentComputing.
|
|
411
|
-
currentComputing.
|
|
426
|
+
currentComputing.l |= 128 ;
|
|
427
|
+
currentComputing.q = skipIndex + 1;
|
|
412
428
|
}
|
|
413
|
-
let flags = self.
|
|
414
|
-
const sourcesArray = self.
|
|
429
|
+
let flags = self.l;
|
|
430
|
+
const sourcesArray = self.m;
|
|
431
|
+
|
|
415
432
|
|
|
416
433
|
if ((flags & 4 ) !== 0) {
|
|
417
434
|
throw new Error(cycleMessage);
|
|
418
435
|
}
|
|
419
436
|
|
|
437
|
+
|
|
420
438
|
const hasCached = (flags & (16 | 32 )) !== 0;
|
|
421
439
|
|
|
422
440
|
checkCache: if ((flags & (1 | 2 )) === 0 && hasCached) {
|
|
423
441
|
|
|
424
|
-
if (self.
|
|
442
|
+
if (self.k === globalVersion) {
|
|
425
443
|
if ((flags & 32 ) !== 0) {
|
|
426
|
-
throw self.
|
|
444
|
+
throw self.r;
|
|
427
445
|
}
|
|
428
|
-
return self.
|
|
446
|
+
return self.r;
|
|
429
447
|
}
|
|
430
448
|
|
|
449
|
+
|
|
431
450
|
if ((flags & 64 ) === 0) {
|
|
432
451
|
let sourceChanged = false;
|
|
433
452
|
|
|
@@ -437,19 +456,19 @@ function computedRead(self) {
|
|
|
437
456
|
try {
|
|
438
457
|
for (let i = 0, len = sourcesArray.length; i < len; ++i) {
|
|
439
458
|
const source = sourcesArray[i];
|
|
440
|
-
const sourceNode = source.
|
|
459
|
+
const sourceNode = source.g;
|
|
441
460
|
if (sourceNode === undefined) {
|
|
442
461
|
|
|
443
|
-
const currentDepsVersion = source.c
|
|
444
|
-
if (source.
|
|
462
|
+
const currentDepsVersion = source.f.c;
|
|
463
|
+
if (source.c !== currentDepsVersion) {
|
|
445
464
|
|
|
446
|
-
const storedValue = source.
|
|
465
|
+
const storedValue = source.h;
|
|
447
466
|
const storedType = typeof storedValue;
|
|
448
467
|
if (storedValue === null || (storedType !== 'object' && storedType !== 'function')) {
|
|
449
|
-
const currentValue = source.
|
|
468
|
+
const currentValue = source.d();
|
|
450
469
|
if (Object.is(currentValue, storedValue)) {
|
|
451
470
|
|
|
452
|
-
source.
|
|
471
|
+
source.c = currentDepsVersion;
|
|
453
472
|
continue;
|
|
454
473
|
}
|
|
455
474
|
}
|
|
@@ -468,7 +487,7 @@ function computedRead(self) {
|
|
|
468
487
|
sourceChanged = true;
|
|
469
488
|
break;
|
|
470
489
|
}
|
|
471
|
-
if (source.
|
|
490
|
+
if (source.c !== sourceNode.c) {
|
|
472
491
|
sourceChanged = true;
|
|
473
492
|
break;
|
|
474
493
|
}
|
|
@@ -480,18 +499,21 @@ function computedRead(self) {
|
|
|
480
499
|
}
|
|
481
500
|
if (sourceChanged) {
|
|
482
501
|
|
|
483
|
-
self.
|
|
502
|
+
self.l = flags |= 1 ;
|
|
484
503
|
break checkCache;
|
|
485
504
|
}
|
|
486
505
|
|
|
487
|
-
self.
|
|
506
|
+
self.k = globalVersion;
|
|
488
507
|
if ((flags & 32 ) !== 0) {
|
|
489
|
-
throw self.
|
|
508
|
+
throw self.r;
|
|
490
509
|
}
|
|
491
|
-
return self.
|
|
510
|
+
return self.r;
|
|
492
511
|
}
|
|
493
512
|
}
|
|
494
513
|
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
495
517
|
if ((flags & (1 | 2 | 128 )) === (2 | 128 ) && hasCached) {
|
|
496
518
|
if (checkSources(sourcesArray)) {
|
|
497
519
|
|
|
@@ -499,69 +521,74 @@ function computedRead(self) {
|
|
|
499
521
|
}
|
|
500
522
|
else {
|
|
501
523
|
|
|
502
|
-
self.
|
|
524
|
+
self.l = flags & -3 ;
|
|
503
525
|
|
|
504
|
-
self.
|
|
526
|
+
self.k = globalVersion;
|
|
505
527
|
if ((flags & 32 ) !== 0) {
|
|
506
|
-
throw self.
|
|
528
|
+
throw self.r;
|
|
507
529
|
}
|
|
508
|
-
return self.
|
|
530
|
+
return self.r;
|
|
509
531
|
}
|
|
510
532
|
}
|
|
511
533
|
|
|
534
|
+
|
|
512
535
|
if ((flags & (1 | 2 )) !== 0) {
|
|
513
536
|
const wasDirty = (flags & 1 ) !== 0;
|
|
514
537
|
runWithTracking(self, () => {
|
|
515
538
|
try {
|
|
516
|
-
const newValue = self.
|
|
539
|
+
const newValue = self.o();
|
|
517
540
|
|
|
518
|
-
const changed = (flags & 16 ) === 0 || !self.
|
|
541
|
+
const changed = (flags & 16 ) === 0 || !self.s(self.r, newValue);
|
|
519
542
|
if (changed) {
|
|
520
|
-
self.
|
|
543
|
+
self.r = newValue;
|
|
544
|
+
|
|
545
|
+
++self.c;
|
|
546
|
+
self.l = (self.l | 16 ) & ~32 ;
|
|
521
547
|
|
|
522
|
-
++self.a;
|
|
523
|
-
self.g = (self.g | 16 ) & ~32 ;
|
|
524
548
|
|
|
525
|
-
for (const dep of self.
|
|
526
|
-
const depFlags = dep.
|
|
549
|
+
for (const dep of self.n) {
|
|
550
|
+
const depFlags = dep.l;
|
|
527
551
|
if ((depFlags & (4 | 1 | 2 )) === 2 ) {
|
|
528
|
-
dep.
|
|
552
|
+
dep.l = depFlags | 1 ;
|
|
529
553
|
}
|
|
530
554
|
}
|
|
531
555
|
}
|
|
532
556
|
else if (wasDirty) {
|
|
533
|
-
self.
|
|
557
|
+
self.l |= 16 ;
|
|
534
558
|
}
|
|
535
559
|
|
|
536
|
-
self.
|
|
560
|
+
self.k = globalVersion;
|
|
537
561
|
}
|
|
538
562
|
catch (e) {
|
|
539
563
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
self.
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
++self.c;
|
|
568
|
+
self.r = e;
|
|
569
|
+
self.l = (self.l & ~16 ) | 32 ;
|
|
570
|
+
self.k = globalVersion;
|
|
544
571
|
}
|
|
545
572
|
});
|
|
546
573
|
}
|
|
547
574
|
|
|
548
|
-
if ((self.
|
|
549
|
-
throw self.
|
|
575
|
+
if ((self.l & 32 ) !== 0) {
|
|
576
|
+
throw self.r;
|
|
550
577
|
}
|
|
551
|
-
return self.
|
|
578
|
+
return self.r;
|
|
552
579
|
}
|
|
553
580
|
|
|
554
581
|
const computed = (getter, equals = Object.is) => {
|
|
555
582
|
const node = {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
583
|
+
m: [],
|
|
584
|
+
n: new DepsSet(noopGetter),
|
|
585
|
+
l: 1 ,
|
|
586
|
+
q: 0,
|
|
587
|
+
c: 0,
|
|
588
|
+
r: undefined,
|
|
559
589
|
k: 0,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
f: 0,
|
|
563
|
-
j: getter,
|
|
564
|
-
m: equals,
|
|
590
|
+
o: getter,
|
|
591
|
+
s: equals,
|
|
565
592
|
};
|
|
566
593
|
return () => computedRead(node);
|
|
567
594
|
};
|
|
@@ -580,38 +607,51 @@ const effect = (callback, eager = 0 ) => {
|
|
|
580
607
|
|
|
581
608
|
warnIfNoActiveScope(activeScope);
|
|
582
609
|
|
|
610
|
+
|
|
583
611
|
let node;
|
|
584
612
|
const effectScope = activeScope;
|
|
585
613
|
|
|
614
|
+
|
|
615
|
+
|
|
586
616
|
const runner = () => {
|
|
587
617
|
|
|
588
618
|
if (disposed) {
|
|
589
619
|
return;
|
|
590
620
|
}
|
|
591
621
|
|
|
592
|
-
const flags = node.
|
|
622
|
+
const flags = node.l;
|
|
593
623
|
if ((flags & 4 ) !== 0) {
|
|
594
624
|
throw new Error(cycleMessage);
|
|
595
625
|
}
|
|
596
626
|
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
597
632
|
if ((flags & (1 | 2 | 128 )) === (2 | 128 )) {
|
|
598
633
|
|
|
599
|
-
|
|
600
|
-
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
if (!checkSources(node.m)) {
|
|
637
|
+
node.l = flags & -3 ;
|
|
601
638
|
return;
|
|
602
639
|
}
|
|
603
640
|
}
|
|
604
641
|
const previousScope = activeScope;
|
|
605
642
|
setActiveScope(effectScope);
|
|
606
643
|
|
|
644
|
+
|
|
645
|
+
|
|
607
646
|
try {
|
|
608
647
|
runWithTracking(node, () => {
|
|
609
648
|
|
|
610
|
-
if (typeof node.
|
|
611
|
-
node.
|
|
649
|
+
if (typeof node.r === 'function') {
|
|
650
|
+
node.r();
|
|
612
651
|
}
|
|
613
652
|
|
|
614
|
-
|
|
653
|
+
|
|
654
|
+
node.r = callback();
|
|
615
655
|
});
|
|
616
656
|
}
|
|
617
657
|
finally {
|
|
@@ -619,18 +659,25 @@ const effect = (callback, eager = 0 ) => {
|
|
|
619
659
|
}
|
|
620
660
|
};
|
|
621
661
|
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
622
669
|
node = {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
670
|
+
m: [],
|
|
671
|
+
n: new DepsSet(noopGetter),
|
|
672
|
+
l: 1 | 8 ,
|
|
673
|
+
q: 0,
|
|
674
|
+
c: 0,
|
|
675
|
+
r: undefined,
|
|
676
|
+
k: ++effectCreationCounter,
|
|
677
|
+
o: runner,
|
|
678
|
+
s: Object.is,
|
|
632
679
|
};
|
|
633
|
-
const effectId = node.
|
|
680
|
+
const effectId = node.k;
|
|
634
681
|
const dispose = () => {
|
|
635
682
|
|
|
636
683
|
if (!disposed) {
|
|
@@ -639,8 +686,8 @@ const effect = (callback, eager = 0 ) => {
|
|
|
639
686
|
|
|
640
687
|
unregisterEffect(gcToken);
|
|
641
688
|
|
|
642
|
-
if (typeof node.
|
|
643
|
-
node.
|
|
689
|
+
if (typeof node.r === 'function') {
|
|
690
|
+
node.r();
|
|
644
691
|
}
|
|
645
692
|
clearSources(node);
|
|
646
693
|
}
|
|
@@ -650,13 +697,31 @@ const effect = (callback, eager = 0 ) => {
|
|
|
650
697
|
effectScope[trackSymbol](dispose);
|
|
651
698
|
}
|
|
652
699
|
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
653
705
|
if (eager === 0 ) {
|
|
654
706
|
batchedAddNew(node, effectId);
|
|
655
707
|
scheduleFlush();
|
|
656
708
|
}
|
|
657
709
|
else {
|
|
658
710
|
|
|
659
|
-
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
try {
|
|
719
|
+
runner();
|
|
720
|
+
}
|
|
721
|
+
catch (error) {
|
|
722
|
+
dispose();
|
|
723
|
+
throw error;
|
|
724
|
+
}
|
|
660
725
|
}
|
|
661
726
|
return dispose;
|
|
662
727
|
};
|
|
@@ -668,6 +733,7 @@ const scope = (callback, parent = activeScope) => {
|
|
|
668
733
|
let disposed = false;
|
|
669
734
|
let myIndex = -1;
|
|
670
735
|
|
|
736
|
+
|
|
671
737
|
const onDispose = cleanup => {
|
|
672
738
|
if (disposed) {
|
|
673
739
|
return;
|
|
@@ -730,8 +796,11 @@ function signal(initialValue) {
|
|
|
730
796
|
let value = initialValue;
|
|
731
797
|
let deps;
|
|
732
798
|
|
|
799
|
+
|
|
733
800
|
const read = () => {
|
|
734
801
|
|
|
802
|
+
|
|
803
|
+
|
|
735
804
|
if (tracked && currentComputing !== undefined) {
|
|
736
805
|
|
|
737
806
|
trackStateDependency((deps ??= new DepsSet(read)), value);
|
|
@@ -740,8 +809,11 @@ function signal(initialValue) {
|
|
|
740
809
|
|
|
741
810
|
};
|
|
742
811
|
|
|
812
|
+
|
|
743
813
|
read.set = (newValue) => {
|
|
744
814
|
|
|
815
|
+
|
|
816
|
+
|
|
745
817
|
warnIfWriteInComputed('signal');
|
|
746
818
|
if (!Object.is(value, newValue)) {
|
|
747
819
|
value = newValue;
|
|
@@ -756,8 +828,11 @@ function signal(initialValue) {
|
|
|
756
828
|
|
|
757
829
|
function state(object = {}) {
|
|
758
830
|
|
|
831
|
+
|
|
832
|
+
|
|
759
833
|
const proxiesCache = new WeakMap();
|
|
760
834
|
|
|
835
|
+
|
|
761
836
|
const notifyPropertyDependents = (target, property) => {
|
|
762
837
|
const propsMap = target[propertyDepsSymbol];
|
|
763
838
|
if (!propsMap)
|
|
@@ -819,6 +894,8 @@ function state(object = {}) {
|
|
|
819
894
|
return propValue;
|
|
820
895
|
}
|
|
821
896
|
|
|
897
|
+
|
|
898
|
+
|
|
822
899
|
if (propertyType === 'function') {
|
|
823
900
|
|
|
824
901
|
if (methodCache === undefined) {
|
|
@@ -835,6 +912,8 @@ function state(object = {}) {
|
|
|
835
912
|
}
|
|
836
913
|
const result = method.apply(target, args);
|
|
837
914
|
|
|
915
|
+
|
|
916
|
+
|
|
838
917
|
if (currentComputing === undefined) {
|
|
839
918
|
const propsMap = target[propertyDepsSymbol];
|
|
840
919
|
if (propsMap === undefined)
|
|
@@ -844,6 +923,7 @@ function state(object = {}) {
|
|
|
844
923
|
markDependents(deps, false);
|
|
845
924
|
}
|
|
846
925
|
|
|
926
|
+
|
|
847
927
|
scheduleFlush();
|
|
848
928
|
}
|
|
849
929
|
return result;
|