@solidjs/signals 0.9.2 → 0.9.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 +142 -59
- package/dist/node.cjs +511 -430
- package/dist/prod.js +185 -102
- package/dist/types/core/constants.d.ts +1 -0
- package/dist/types/core/core.d.ts +4 -2
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +5 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/store/projection.d.ts +8 -3
- package/dist/types/store/store.d.ts +10 -6
- package/package.json +3 -3
package/dist/prod.js
CHANGED
|
@@ -32,6 +32,7 @@ const EFFECT_USER = 2;
|
|
|
32
32
|
const NOT_PENDING = {};
|
|
33
33
|
const SUPPORTS_PROXY = typeof Proxy === "function";
|
|
34
34
|
const defaultContext = {};
|
|
35
|
+
const $REFRESH = Symbol("refresh");
|
|
35
36
|
function actualInsertIntoHeap(e, t) {
|
|
36
37
|
const n = (e.i?.t ? e.i.u?.o : e.i?.o) ?? -1;
|
|
37
38
|
if (n >= e.o) e.o = n + 1;
|
|
@@ -138,7 +139,7 @@ let scheduled = false;
|
|
|
138
139
|
function schedule() {
|
|
139
140
|
if (scheduled) return;
|
|
140
141
|
scheduled = true;
|
|
141
|
-
if (!globalQueue.k) queueMicrotask(flush);
|
|
142
|
+
if (!globalQueue.k) Promise.resolve().then(() => queueMicrotask(flush));
|
|
142
143
|
}
|
|
143
144
|
class Queue {
|
|
144
145
|
i = null;
|
|
@@ -200,8 +201,8 @@ class Queue {
|
|
|
200
201
|
}
|
|
201
202
|
class GlobalQueue extends Queue {
|
|
202
203
|
k = false;
|
|
203
|
-
$ = [];
|
|
204
204
|
L = [];
|
|
205
|
+
$ = [];
|
|
205
206
|
static F;
|
|
206
207
|
static W;
|
|
207
208
|
flush() {
|
|
@@ -213,7 +214,7 @@ class GlobalQueue extends Queue {
|
|
|
213
214
|
if (!transitionComplete(activeTransition)) {
|
|
214
215
|
let e = activeTransition;
|
|
215
216
|
runHeap(zombieQueue, GlobalQueue.F);
|
|
216
|
-
this
|
|
217
|
+
this.L = [];
|
|
217
218
|
this.stashQueues(activeTransition.queueStash);
|
|
218
219
|
clock++;
|
|
219
220
|
scheduled = false;
|
|
@@ -222,11 +223,13 @@ class GlobalQueue extends Queue {
|
|
|
222
223
|
runOptimistic(e);
|
|
223
224
|
return;
|
|
224
225
|
}
|
|
225
|
-
this
|
|
226
|
+
this.L.push(...activeTransition.pendingNodes);
|
|
227
|
+
this.$ !== activeTransition.optimisticNodes &&
|
|
228
|
+
this.$.push(...activeTransition.optimisticNodes);
|
|
226
229
|
this.restoreQueues(activeTransition.queueStash);
|
|
227
230
|
transitions.delete(activeTransition);
|
|
228
231
|
activeTransition = null;
|
|
229
|
-
runTransitionPending(this
|
|
232
|
+
runTransitionPending(this.L, false);
|
|
230
233
|
} else if (transitions.size) runHeap(zombieQueue, GlobalQueue.F);
|
|
231
234
|
runOptimistic();
|
|
232
235
|
clock++;
|
|
@@ -252,29 +255,30 @@ class GlobalQueue extends Queue {
|
|
|
252
255
|
initTransition(e) {
|
|
253
256
|
if (activeTransition && activeTransition.time === clock) return;
|
|
254
257
|
if (!activeTransition) {
|
|
255
|
-
activeTransition = e
|
|
258
|
+
activeTransition = e?.K ?? {
|
|
256
259
|
time: clock,
|
|
257
260
|
pendingNodes: [],
|
|
258
261
|
asyncNodes: [],
|
|
259
262
|
optimisticNodes: [],
|
|
263
|
+
actions: [],
|
|
260
264
|
queueStash: { G: [[], []], H: [] },
|
|
261
265
|
done: false
|
|
262
266
|
};
|
|
263
267
|
}
|
|
264
268
|
transitions.add(activeTransition);
|
|
265
269
|
activeTransition.time = clock;
|
|
266
|
-
for (let e = 0; e < this
|
|
267
|
-
const t = this
|
|
270
|
+
for (let e = 0; e < this.L.length; e++) {
|
|
271
|
+
const t = this.L[e];
|
|
268
272
|
t.K = activeTransition;
|
|
269
273
|
activeTransition.pendingNodes.push(t);
|
|
270
274
|
}
|
|
271
|
-
for (let e = 0; e < this
|
|
272
|
-
const t = this
|
|
275
|
+
for (let e = 0; e < this.$.length; e++) {
|
|
276
|
+
const t = this.$[e];
|
|
273
277
|
t.K = activeTransition;
|
|
274
278
|
activeTransition.optimisticNodes.push(t);
|
|
275
279
|
}
|
|
276
|
-
this
|
|
277
|
-
this
|
|
280
|
+
this.L = activeTransition.pendingNodes;
|
|
281
|
+
this.$ = activeTransition.optimisticNodes;
|
|
278
282
|
}
|
|
279
283
|
}
|
|
280
284
|
function notifySubs(e) {
|
|
@@ -286,7 +290,7 @@ function notifySubs(e) {
|
|
|
286
290
|
}
|
|
287
291
|
function runOptimistic(e = null) {
|
|
288
292
|
let t = !e;
|
|
289
|
-
const n = globalQueue
|
|
293
|
+
const n = globalQueue.$;
|
|
290
294
|
optimisticRun = true;
|
|
291
295
|
for (let t = 0; t < n.length; t++) {
|
|
292
296
|
const i = n[t];
|
|
@@ -297,13 +301,13 @@ function runOptimistic(e = null) {
|
|
|
297
301
|
i.K = e;
|
|
298
302
|
notifySubs(i);
|
|
299
303
|
}
|
|
300
|
-
globalQueue
|
|
304
|
+
globalQueue.$ = [];
|
|
301
305
|
if (dirtyQueue.h >= dirtyQueue.C) {
|
|
302
306
|
t = true;
|
|
303
307
|
runHeap(dirtyQueue, GlobalQueue.F);
|
|
304
308
|
}
|
|
305
309
|
optimisticRun = false;
|
|
306
|
-
t && runPending(globalQueue
|
|
310
|
+
t && runPending(globalQueue.L);
|
|
307
311
|
}
|
|
308
312
|
function runPending(e) {
|
|
309
313
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -336,6 +340,7 @@ function runQueue(e, t) {
|
|
|
336
340
|
}
|
|
337
341
|
function transitionComplete(e) {
|
|
338
342
|
if (e.done) return true;
|
|
343
|
+
if (e.actions.length) return false;
|
|
339
344
|
let t = true;
|
|
340
345
|
for (let n = 0; n < e.asyncNodes.length; n++) {
|
|
341
346
|
if (e.asyncNodes[n].J & STATUS_PENDING) {
|
|
@@ -348,9 +353,38 @@ function transitionComplete(e) {
|
|
|
348
353
|
}
|
|
349
354
|
function runInTransition(e, t) {
|
|
350
355
|
const n = activeTransition;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
356
|
+
try {
|
|
357
|
+
activeTransition = e;
|
|
358
|
+
return t();
|
|
359
|
+
} finally {
|
|
360
|
+
activeTransition = n;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function action(e) {
|
|
364
|
+
return (...t) => {
|
|
365
|
+
const n = e(...t);
|
|
366
|
+
globalQueue.initTransition();
|
|
367
|
+
let i = activeTransition;
|
|
368
|
+
i.actions.push(n);
|
|
369
|
+
const step = e => {
|
|
370
|
+
let t = n.next(e);
|
|
371
|
+
if (t instanceof Promise) return t.then(process);
|
|
372
|
+
process(t);
|
|
373
|
+
};
|
|
374
|
+
const process = e => {
|
|
375
|
+
if (e.done) {
|
|
376
|
+
i.actions.splice(i.actions.indexOf(n), 1);
|
|
377
|
+
activeTransition = i;
|
|
378
|
+
schedule();
|
|
379
|
+
flush();
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const t = e.value;
|
|
383
|
+
if (t instanceof Promise) return t.then(step);
|
|
384
|
+
runInTransition(i, () => step(t));
|
|
385
|
+
};
|
|
386
|
+
runInTransition(i, () => step());
|
|
387
|
+
};
|
|
354
388
|
}
|
|
355
389
|
GlobalQueue.F = recompute;
|
|
356
390
|
GlobalQueue.W = disposeChildren;
|
|
@@ -410,7 +444,7 @@ function recompute(e, t = false) {
|
|
|
410
444
|
else e.D = null;
|
|
411
445
|
}
|
|
412
446
|
}
|
|
413
|
-
const c = !e.ue || !e.ue(e.M === NOT_PENDING || e.oe || n ? e.Y : e.M, r);
|
|
447
|
+
const c = !e.ue || !e.ue(e.M === NOT_PENDING || (e.oe && e.K) || n ? e.Y : e.M, r);
|
|
414
448
|
const a = e.J !== o || e.j !== u;
|
|
415
449
|
e.le?.(a, o);
|
|
416
450
|
if (c || a) {
|
|
@@ -425,9 +459,9 @@ function recompute(e, t = false) {
|
|
|
425
459
|
insertIntoHeapHeight(t.A, t.A.S & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
|
|
426
460
|
}
|
|
427
461
|
}
|
|
428
|
-
e.oe && !optimisticRun && globalQueue
|
|
429
|
-
(!t || e.J & STATUS_PENDING) && !e.K && globalQueue
|
|
430
|
-
e.K && n && runInTransition(e, recompute);
|
|
462
|
+
e.oe && !optimisticRun && globalQueue.$.push(e);
|
|
463
|
+
(!t || e.J & STATUS_PENDING) && !e.K && globalQueue.L.push(e);
|
|
464
|
+
e.K && n && runInTransition(e.K, () => recompute(e));
|
|
431
465
|
}
|
|
432
466
|
function handleAsync(e, t, n) {
|
|
433
467
|
const i = typeof t === "object" && t !== null;
|
|
@@ -725,17 +759,6 @@ function read(e) {
|
|
|
725
759
|
}
|
|
726
760
|
}
|
|
727
761
|
}
|
|
728
|
-
if (pendingCheck) {
|
|
729
|
-
if (!e.q) {
|
|
730
|
-
e.q = signal(false);
|
|
731
|
-
e.q.oe = true;
|
|
732
|
-
e.q.Z = t => setSignal(e.q, t);
|
|
733
|
-
}
|
|
734
|
-
const t = pendingCheck;
|
|
735
|
-
pendingCheck = null;
|
|
736
|
-
t.Y = read(e.q) || t.Y;
|
|
737
|
-
pendingCheck = t;
|
|
738
|
-
}
|
|
739
762
|
if (pendingValueCheck) {
|
|
740
763
|
if (!e.ce) {
|
|
741
764
|
e.ce = signal(e.Y);
|
|
@@ -748,10 +771,22 @@ function read(e) {
|
|
|
748
771
|
pendingValueCheck = true;
|
|
749
772
|
}
|
|
750
773
|
}
|
|
751
|
-
|
|
752
|
-
|
|
774
|
+
const n = e.m || e;
|
|
775
|
+
if (pendingCheck) {
|
|
776
|
+
if (!n.q) {
|
|
777
|
+
n.q = signal(false);
|
|
778
|
+
n.q.oe = true;
|
|
779
|
+
n.q.Z = e => setSignal(n.q, e);
|
|
780
|
+
}
|
|
781
|
+
const e = pendingCheck;
|
|
782
|
+
pendingCheck = null;
|
|
783
|
+
e.Y = read(n.q) || e.Y;
|
|
784
|
+
pendingCheck = e;
|
|
785
|
+
}
|
|
786
|
+
if (!pendingCheck && n.J & STATUS_PENDING) {
|
|
787
|
+
if ((t && !stale) || n.J & STATUS_UNINITIALIZED || e.m) throw n.j;
|
|
753
788
|
else if (t && stale) {
|
|
754
|
-
setStatusFlags(t, t.J |
|
|
789
|
+
setStatusFlags(t, t.J | STATUS_PENDING, n.j);
|
|
755
790
|
}
|
|
756
791
|
}
|
|
757
792
|
if (e.J & STATUS_ERROR) {
|
|
@@ -773,19 +808,19 @@ function setSignal(e, t) {
|
|
|
773
808
|
if (typeof t === "function") {
|
|
774
809
|
t = t(e.M === NOT_PENDING || (e.oe && e.K) ? e.Y : e.M);
|
|
775
810
|
}
|
|
776
|
-
const n = !e.ue || !e.ue(e.M === NOT_PENDING || e.oe ? e.Y : e.M, t);
|
|
811
|
+
const n = !e.ue || !e.ue(e.M === NOT_PENDING || (e.oe && e.K) ? e.Y : e.M, t);
|
|
777
812
|
if (!n && !e.J) return t;
|
|
778
813
|
if (n) {
|
|
779
814
|
if (e.oe) e.Y = t;
|
|
780
815
|
else {
|
|
781
|
-
if (e.M === NOT_PENDING) globalQueue
|
|
816
|
+
if (e.M === NOT_PENDING) globalQueue.L.push(e);
|
|
782
817
|
e.M = t;
|
|
783
818
|
}
|
|
784
819
|
if (e.ce) setSignal(e.ce, t);
|
|
785
820
|
}
|
|
786
821
|
setStatusFlags(e, STATUS_NONE);
|
|
787
822
|
e.se = clock;
|
|
788
|
-
e.oe && !optimisticRun ? globalQueue
|
|
823
|
+
e.oe && !optimisticRun ? globalQueue.$.push(e) : notifySubs(e);
|
|
789
824
|
schedule();
|
|
790
825
|
return t;
|
|
791
826
|
}
|
|
@@ -885,6 +920,10 @@ function refresh(e) {
|
|
|
885
920
|
let t = refreshing;
|
|
886
921
|
refreshing = true;
|
|
887
922
|
try {
|
|
923
|
+
if (typeof e !== "function") {
|
|
924
|
+
recompute(e[$REFRESH]);
|
|
925
|
+
return e;
|
|
926
|
+
}
|
|
888
927
|
return untrack(e);
|
|
889
928
|
} finally {
|
|
890
929
|
refreshing = t;
|
|
@@ -929,8 +968,8 @@ function effect(e, t, n, i, r) {
|
|
|
929
968
|
pe: {
|
|
930
969
|
X: true,
|
|
931
970
|
Ae: i,
|
|
932
|
-
|
|
933
|
-
|
|
971
|
+
Ne: t,
|
|
972
|
+
ge: n,
|
|
934
973
|
Ie: undefined,
|
|
935
974
|
B: r?.render ? EFFECT_RENDER : EFFECT_USER,
|
|
936
975
|
le(e, t) {
|
|
@@ -944,8 +983,8 @@ function effect(e, t, n, i, r) {
|
|
|
944
983
|
this._e.notify(this, STATUS_PENDING, 0);
|
|
945
984
|
if (this.B === EFFECT_USER) {
|
|
946
985
|
try {
|
|
947
|
-
return this.
|
|
948
|
-
? this.
|
|
986
|
+
return this.ge
|
|
987
|
+
? this.ge(e, () => {
|
|
949
988
|
this.Ie?.();
|
|
950
989
|
this.Ie = undefined;
|
|
951
990
|
})
|
|
@@ -973,7 +1012,7 @@ function runEffect() {
|
|
|
973
1012
|
this.Ie?.();
|
|
974
1013
|
this.Ie = undefined;
|
|
975
1014
|
try {
|
|
976
|
-
this.Ie = this.
|
|
1015
|
+
this.Ie = this.Ne(this.Y, this.Ae);
|
|
977
1016
|
} catch (e) {
|
|
978
1017
|
if (!this._e.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
|
|
979
1018
|
} finally {
|
|
@@ -986,10 +1025,8 @@ function createSignal(e, t, n) {
|
|
|
986
1025
|
const i = computed(e, t, n);
|
|
987
1026
|
return [read.bind(null, i), setSignal.bind(null, i)];
|
|
988
1027
|
}
|
|
989
|
-
const i =
|
|
990
|
-
|
|
991
|
-
const s = signal(e, r ? { id: getNextChildId(i), ...t } : t);
|
|
992
|
-
return [read.bind(null, s), setSignal.bind(null, s)];
|
|
1028
|
+
const i = signal(e, t);
|
|
1029
|
+
return [read.bind(null, i), setSignal.bind(null, i)];
|
|
993
1030
|
}
|
|
994
1031
|
function createMemo(e, t, n) {
|
|
995
1032
|
let i = computed(e, t, n);
|
|
@@ -1041,8 +1078,10 @@ function createOptimistic(e, t, n) {
|
|
|
1041
1078
|
if (typeof e === "function") {
|
|
1042
1079
|
const i = computed(
|
|
1043
1080
|
t => {
|
|
1044
|
-
|
|
1045
|
-
|
|
1081
|
+
const n = getOwner();
|
|
1082
|
+
const i = e(t);
|
|
1083
|
+
if (n.J & STATUS_UNINITIALIZED) return i;
|
|
1084
|
+
n.M = i;
|
|
1046
1085
|
return t;
|
|
1047
1086
|
},
|
|
1048
1087
|
t,
|
|
@@ -1051,15 +1090,13 @@ function createOptimistic(e, t, n) {
|
|
|
1051
1090
|
i.oe = true;
|
|
1052
1091
|
return [read.bind(null, i), setSignal.bind(null, i)];
|
|
1053
1092
|
}
|
|
1054
|
-
const i =
|
|
1055
|
-
|
|
1056
|
-
const s = signal(e, r ? { id: getNextChildId(i), ...t } : t);
|
|
1057
|
-
s.oe = true;
|
|
1093
|
+
const i = signal(e, t);
|
|
1094
|
+
i.oe = true;
|
|
1058
1095
|
return [
|
|
1059
|
-
read.bind(null,
|
|
1096
|
+
read.bind(null, i),
|
|
1060
1097
|
t => {
|
|
1061
|
-
|
|
1062
|
-
return setSignal(
|
|
1098
|
+
i.M = e;
|
|
1099
|
+
return setSignal(i, t);
|
|
1063
1100
|
}
|
|
1064
1101
|
];
|
|
1065
1102
|
}
|
|
@@ -1076,7 +1113,7 @@ function unwrap(e) {
|
|
|
1076
1113
|
return e?.[$TARGET]?.[STORE_NODE] ?? e;
|
|
1077
1114
|
}
|
|
1078
1115
|
function getOverrideValue(e, t, n, i) {
|
|
1079
|
-
return
|
|
1116
|
+
return t && i in t ? t[i] : e[i];
|
|
1080
1117
|
}
|
|
1081
1118
|
function getAllKeys(e, t, n) {
|
|
1082
1119
|
const i = getKeys(e, t);
|
|
@@ -1157,10 +1194,12 @@ function applyState(e, t, n, i) {
|
|
|
1157
1194
|
} else r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], wrap(e[a], r));
|
|
1158
1195
|
}
|
|
1159
1196
|
if (f < e.length) t = true;
|
|
1160
|
-
} else if (
|
|
1197
|
+
} else if (e.length) {
|
|
1161
1198
|
for (let t = 0, l = e.length; t < l; t++) {
|
|
1162
1199
|
const l = getOverrideValue(s, o, u, t);
|
|
1163
|
-
isWrappable(l)
|
|
1200
|
+
isWrappable(l)
|
|
1201
|
+
? applyState(e[t], wrap(l, r), n, i)
|
|
1202
|
+
: r[STORE_NODE][t] && setSignal(r[STORE_NODE][t], e[t]);
|
|
1164
1203
|
}
|
|
1165
1204
|
}
|
|
1166
1205
|
if (l !== e.length) {
|
|
@@ -1206,34 +1245,70 @@ function reconcile(e, t, n = false) {
|
|
|
1206
1245
|
function createProjectionInternal(e, t = {}, n) {
|
|
1207
1246
|
let i;
|
|
1208
1247
|
const r = new WeakMap();
|
|
1248
|
+
const wrapper = e => {
|
|
1249
|
+
e[STORE_WRAP] = wrapProjection;
|
|
1250
|
+
e[STORE_LOOKUP] = r;
|
|
1251
|
+
Object.defineProperty(e, STORE_FIREWALL, {
|
|
1252
|
+
get() {
|
|
1253
|
+
return i;
|
|
1254
|
+
},
|
|
1255
|
+
configurable: true
|
|
1256
|
+
});
|
|
1257
|
+
};
|
|
1209
1258
|
const wrapProjection = e => {
|
|
1210
1259
|
if (r.has(e)) return r.get(e);
|
|
1211
1260
|
if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
|
|
1212
|
-
const t = createStoreProxy(e, storeTraps,
|
|
1213
|
-
[STORE_WRAP]: wrapProjection,
|
|
1214
|
-
[STORE_LOOKUP]: r,
|
|
1215
|
-
[STORE_FIREWALL]() {
|
|
1216
|
-
return i;
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1261
|
+
const t = createStoreProxy(e, storeTraps, wrapper);
|
|
1219
1262
|
r.set(e, t);
|
|
1220
1263
|
return t;
|
|
1221
1264
|
};
|
|
1222
1265
|
const s = wrapProjection(t);
|
|
1223
1266
|
i = computed(() => {
|
|
1224
|
-
const t =
|
|
1225
|
-
storeSetter(s, i => {
|
|
1267
|
+
const t = getOwner();
|
|
1268
|
+
storeSetter(new Proxy(s, writeTraps), i => {
|
|
1226
1269
|
const r = handleAsync(t, e(i), e => {
|
|
1227
|
-
e !==
|
|
1270
|
+
e !== s && e !== undefined && storeSetter(s, reconcile(e, n?.key || "id", n?.all));
|
|
1271
|
+
setSignal(t, undefined);
|
|
1228
1272
|
});
|
|
1229
|
-
r !==
|
|
1273
|
+
r !== s && r !== undefined && reconcile(r, n?.key || "id", n?.all)(s);
|
|
1230
1274
|
});
|
|
1231
1275
|
});
|
|
1276
|
+
i.Te = true;
|
|
1232
1277
|
return { store: s, node: i };
|
|
1233
1278
|
}
|
|
1234
1279
|
function createProjection(e, t = {}, n) {
|
|
1235
1280
|
return createProjectionInternal(e, t, n).store;
|
|
1236
1281
|
}
|
|
1282
|
+
const writeTraps = {
|
|
1283
|
+
get(e, t) {
|
|
1284
|
+
let n;
|
|
1285
|
+
setWriteOverride(true);
|
|
1286
|
+
try {
|
|
1287
|
+
n = e[t];
|
|
1288
|
+
} finally {
|
|
1289
|
+
setWriteOverride(false);
|
|
1290
|
+
}
|
|
1291
|
+
return typeof n === "object" && n !== null ? new Proxy(n, writeTraps) : n;
|
|
1292
|
+
},
|
|
1293
|
+
set(e, t, n) {
|
|
1294
|
+
setWriteOverride(true);
|
|
1295
|
+
try {
|
|
1296
|
+
e[t] = n;
|
|
1297
|
+
} finally {
|
|
1298
|
+
setWriteOverride(false);
|
|
1299
|
+
}
|
|
1300
|
+
return true;
|
|
1301
|
+
},
|
|
1302
|
+
deleteProperty(e, t) {
|
|
1303
|
+
setWriteOverride(true);
|
|
1304
|
+
try {
|
|
1305
|
+
delete e[t];
|
|
1306
|
+
} finally {
|
|
1307
|
+
setWriteOverride(false);
|
|
1308
|
+
}
|
|
1309
|
+
return true;
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1237
1312
|
const $TRACK = Symbol(0),
|
|
1238
1313
|
$DEEP = Symbol(0),
|
|
1239
1314
|
$TARGET = Symbol(0),
|
|
@@ -1253,7 +1328,7 @@ function createStoreProxy(e, t = storeTraps, n) {
|
|
|
1253
1328
|
i = [];
|
|
1254
1329
|
i.v = e;
|
|
1255
1330
|
} else i = { v: e };
|
|
1256
|
-
n &&
|
|
1331
|
+
n && n(i);
|
|
1257
1332
|
return (i[$PROXY] = new Proxy(i, t));
|
|
1258
1333
|
}
|
|
1259
1334
|
const storeLookup = new WeakMap();
|
|
@@ -1266,6 +1341,13 @@ function wrap(e, t) {
|
|
|
1266
1341
|
function isWrappable(e) {
|
|
1267
1342
|
return e != null && typeof e === "object" && !Object.isFrozen(e);
|
|
1268
1343
|
}
|
|
1344
|
+
let writeOverride = false;
|
|
1345
|
+
function setWriteOverride(e) {
|
|
1346
|
+
writeOverride = e;
|
|
1347
|
+
}
|
|
1348
|
+
function writeOnly(e) {
|
|
1349
|
+
return writeOverride || !!Writing?.has(e);
|
|
1350
|
+
}
|
|
1269
1351
|
function getNodes(e, t) {
|
|
1270
1352
|
let n = e[t];
|
|
1271
1353
|
if (!n) e[t] = n = Object.create(null);
|
|
@@ -1285,8 +1367,7 @@ function getNode(e, t, n, i, r = isEqual) {
|
|
|
1285
1367
|
));
|
|
1286
1368
|
}
|
|
1287
1369
|
function trackSelf(e, t = $TRACK) {
|
|
1288
|
-
getObserver() &&
|
|
1289
|
-
read(getNode(getNodes(e, STORE_NODE), t, undefined, e[STORE_FIREWALL]?.(), false));
|
|
1370
|
+
getObserver() && read(getNode(getNodes(e, STORE_NODE), t, undefined, e[STORE_FIREWALL], false));
|
|
1290
1371
|
}
|
|
1291
1372
|
function getKeys(e, t, n = true) {
|
|
1292
1373
|
const i = untrack(() => (n ? Object.keys(e) : Reflect.ownKeys(e)));
|
|
@@ -1312,6 +1393,7 @@ const storeTraps = {
|
|
|
1312
1393
|
get(e, t, n) {
|
|
1313
1394
|
if (t === $TARGET) return e;
|
|
1314
1395
|
if (t === $PROXY) return n;
|
|
1396
|
+
if (t === $REFRESH) return e[STORE_FIREWALL];
|
|
1315
1397
|
if (t === $TRACK || t === $DEEP) {
|
|
1316
1398
|
trackSelf(e, t);
|
|
1317
1399
|
return n;
|
|
@@ -1325,12 +1407,12 @@ const storeTraps = {
|
|
|
1325
1407
|
const e = Object.getOwnPropertyDescriptor(u, t);
|
|
1326
1408
|
if (e && e.get) return e.get.call(n);
|
|
1327
1409
|
}
|
|
1328
|
-
if (
|
|
1410
|
+
if (writeOnly(n)) {
|
|
1329
1411
|
let n = r && (s || !o) ? (r.M !== NOT_PENDING ? r.M : r.Y) : u[t];
|
|
1330
1412
|
n === $DELETED && (n = undefined);
|
|
1331
1413
|
if (!isWrappable(n)) return n;
|
|
1332
1414
|
const i = wrap(n, e);
|
|
1333
|
-
Writing
|
|
1415
|
+
Writing?.add(i);
|
|
1334
1416
|
return i;
|
|
1335
1417
|
}
|
|
1336
1418
|
let l = r ? (s || !o ? read(i[t]) : (read(i[t]), u[t])) : u[t];
|
|
@@ -1344,7 +1426,7 @@ const storeTraps = {
|
|
|
1344
1426
|
? l.bind(u)
|
|
1345
1427
|
: l;
|
|
1346
1428
|
} else if (getObserver()) {
|
|
1347
|
-
return read(getNode(i, t, isWrappable(l) ? wrap(l, e) : l, e[STORE_FIREWALL]
|
|
1429
|
+
return read(getNode(i, t, isWrappable(l) ? wrap(l, e) : l, e[STORE_FIREWALL]));
|
|
1348
1430
|
}
|
|
1349
1431
|
}
|
|
1350
1432
|
return isWrappable(l) ? wrap(l, e) : l;
|
|
@@ -1355,12 +1437,12 @@ const storeTraps = {
|
|
|
1355
1437
|
e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
|
|
1356
1438
|
? e[STORE_OVERRIDE][t] !== $DELETED
|
|
1357
1439
|
: t in e[STORE_VALUE];
|
|
1358
|
-
getObserver() && read(getNode(getNodes(e, STORE_HAS), t, n, e[STORE_FIREWALL]
|
|
1440
|
+
getObserver() && read(getNode(getNodes(e, STORE_HAS), t, n, e[STORE_FIREWALL]));
|
|
1359
1441
|
return n;
|
|
1360
1442
|
},
|
|
1361
1443
|
set(e, t, n) {
|
|
1362
1444
|
const i = e[$PROXY];
|
|
1363
|
-
if (
|
|
1445
|
+
if (writeOnly(i)) {
|
|
1364
1446
|
untrack(() => {
|
|
1365
1447
|
const r = e[STORE_VALUE];
|
|
1366
1448
|
const s = r[t];
|
|
@@ -1389,7 +1471,7 @@ const storeTraps = {
|
|
|
1389
1471
|
return true;
|
|
1390
1472
|
},
|
|
1391
1473
|
deleteProperty(e, t) {
|
|
1392
|
-
if (
|
|
1474
|
+
if (writeOnly(e[$PROXY]) && e[STORE_OVERRIDE]?.[t] !== $DELETED) {
|
|
1393
1475
|
untrack(() => {
|
|
1394
1476
|
const n =
|
|
1395
1477
|
e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE] ? e[STORE_OVERRIDE][t] : e[STORE_VALUE][t];
|
|
@@ -1914,30 +1996,30 @@ function createBoundChildren(e, t, n, i) {
|
|
|
1914
1996
|
});
|
|
1915
1997
|
}
|
|
1916
1998
|
class ConditionalQueue extends Queue {
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1999
|
+
Le;
|
|
2000
|
+
$e = new Set();
|
|
2001
|
+
L = new Set();
|
|
1920
2002
|
constructor(e) {
|
|
1921
2003
|
super();
|
|
1922
|
-
this
|
|
2004
|
+
this.Le = e;
|
|
1923
2005
|
}
|
|
1924
2006
|
run(e) {
|
|
1925
|
-
if (!e || read(this
|
|
2007
|
+
if (!e || read(this.Le)) return;
|
|
1926
2008
|
return super.run(e);
|
|
1927
2009
|
}
|
|
1928
2010
|
notify(e, t, n) {
|
|
1929
|
-
if (read(this
|
|
2011
|
+
if (read(this.Le)) {
|
|
1930
2012
|
if (t & STATUS_PENDING) {
|
|
1931
2013
|
if (n & STATUS_PENDING) {
|
|
1932
|
-
this
|
|
2014
|
+
this.L.add(e);
|
|
1933
2015
|
t &= ~STATUS_PENDING;
|
|
1934
|
-
} else if (this
|
|
2016
|
+
} else if (this.L.delete(e)) t &= ~STATUS_PENDING;
|
|
1935
2017
|
}
|
|
1936
2018
|
if (t & STATUS_ERROR) {
|
|
1937
2019
|
if (n & STATUS_ERROR) {
|
|
1938
|
-
this.
|
|
2020
|
+
this.$e.add(e);
|
|
1939
2021
|
t &= ~STATUS_ERROR;
|
|
1940
|
-
} else if (this.
|
|
2022
|
+
} else if (this.$e.delete(e)) t &= ~STATUS_ERROR;
|
|
1941
2023
|
}
|
|
1942
2024
|
}
|
|
1943
2025
|
return t ? super.notify(e, t, n) : true;
|
|
@@ -1946,24 +2028,24 @@ class ConditionalQueue extends Queue {
|
|
|
1946
2028
|
class CollectionQueue extends Queue {
|
|
1947
2029
|
Fe;
|
|
1948
2030
|
Ve = new Set();
|
|
1949
|
-
|
|
2031
|
+
Le = signal(false, { pureWrite: true });
|
|
1950
2032
|
We = false;
|
|
1951
2033
|
constructor(e) {
|
|
1952
2034
|
super();
|
|
1953
2035
|
this.Fe = e;
|
|
1954
2036
|
}
|
|
1955
2037
|
run(e) {
|
|
1956
|
-
if (!e || read(this
|
|
2038
|
+
if (!e || read(this.Le)) return;
|
|
1957
2039
|
return super.run(e);
|
|
1958
2040
|
}
|
|
1959
2041
|
notify(e, t, n) {
|
|
1960
2042
|
if (!(t & this.Fe) || (this.Fe & STATUS_PENDING && this.We)) return super.notify(e, t, n);
|
|
1961
2043
|
if (n & this.Fe) {
|
|
1962
2044
|
this.Ve.add(e);
|
|
1963
|
-
if (this.Ve.size === 1) setSignal(this
|
|
2045
|
+
if (this.Ve.size === 1) setSignal(this.Le, true);
|
|
1964
2046
|
} else if (this.Ve.size > 0) {
|
|
1965
2047
|
this.Ve.delete(e);
|
|
1966
|
-
if (this.Ve.size === 0) setSignal(this
|
|
2048
|
+
if (this.Ve.size === 0) setSignal(this.Le, false);
|
|
1967
2049
|
}
|
|
1968
2050
|
t &= ~this.Fe;
|
|
1969
2051
|
return t ? super.notify(e, t, n) : true;
|
|
@@ -1979,25 +2061,25 @@ function createBoundary(e, t) {
|
|
|
1979
2061
|
const i = new ConditionalQueue(computed(() => t() === BoundaryMode.HIDDEN));
|
|
1980
2062
|
const r = createBoundChildren(n, e, i, 0);
|
|
1981
2063
|
computed(() => {
|
|
1982
|
-
const e = read(i
|
|
2064
|
+
const e = read(i.Le);
|
|
1983
2065
|
r.Qe = e ? STATUS_ERROR | STATUS_PENDING : 0;
|
|
1984
2066
|
if (!e) {
|
|
1985
|
-
i
|
|
1986
|
-
i.
|
|
1987
|
-
i
|
|
1988
|
-
i.
|
|
2067
|
+
i.L.forEach(e => i.notify(e, STATUS_PENDING, STATUS_PENDING));
|
|
2068
|
+
i.$e.forEach(e => i.notify(e, STATUS_ERROR, STATUS_ERROR));
|
|
2069
|
+
i.L.clear();
|
|
2070
|
+
i.$e.clear();
|
|
1989
2071
|
}
|
|
1990
2072
|
});
|
|
1991
|
-
return () => (read(i
|
|
2073
|
+
return () => (read(i.Le) ? undefined : read(r));
|
|
1992
2074
|
}
|
|
1993
2075
|
function createCollectionBoundary(e, t, n) {
|
|
1994
2076
|
const i = createOwner();
|
|
1995
2077
|
const r = new CollectionQueue(e);
|
|
1996
2078
|
const s = createBoundChildren(i, t, r, e);
|
|
1997
2079
|
const o = computed(() => {
|
|
1998
|
-
if (!read(r
|
|
2080
|
+
if (!read(r.Le)) {
|
|
1999
2081
|
const e = read(s);
|
|
2000
|
-
if (!untrack(() => read(r
|
|
2082
|
+
if (!untrack(() => read(r.Le))) r.We = true;
|
|
2001
2083
|
return e;
|
|
2002
2084
|
}
|
|
2003
2085
|
return n(r);
|
|
@@ -2088,6 +2170,7 @@ export {
|
|
|
2088
2170
|
NoOwnerError,
|
|
2089
2171
|
NotReadyError,
|
|
2090
2172
|
SUPPORTS_PROXY,
|
|
2173
|
+
action,
|
|
2091
2174
|
createBoundary,
|
|
2092
2175
|
createContext,
|
|
2093
2176
|
createEffect,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NOT_PENDING } from "./constants.js";
|
|
1
|
+
import { $REFRESH, NOT_PENDING } from "./constants.js";
|
|
2
2
|
import { type IQueue, type Transition } from "./scheduler.js";
|
|
3
3
|
export interface Disposable {
|
|
4
4
|
(): void;
|
|
@@ -118,5 +118,7 @@ export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
|
|
|
118
118
|
export declare function staleValues<T>(fn: () => T, set?: boolean): T;
|
|
119
119
|
export declare function pending<T>(fn: () => T): T;
|
|
120
120
|
export declare function isPending(fn: () => any): boolean;
|
|
121
|
-
export declare function refresh<T>(fn: () => T)
|
|
121
|
+
export declare function refresh<T>(fn: (() => T) | (T & {
|
|
122
|
+
[$REFRESH]: any;
|
|
123
|
+
})): T;
|
|
122
124
|
export declare function isRefreshing(): boolean;
|
|
@@ -2,5 +2,5 @@ export { ContextNotFoundError, NoOwnerError, NotReadyError } from "./error.js";
|
|
|
2
2
|
export { createContext, getContext, setContext, type Context, type ContextRecord } from "./context.js";
|
|
3
3
|
export { getObserver, isEqual, untrack, getOwner, runWithOwner, createOwner, createRoot, computed, dispose, signal, read, setSignal, onCleanup, getNextChildId, isPending, pending, refresh, isRefreshing, staleValues, handleAsync, type Owner, type Computed, type Root, type Signal, type SignalOptions } from "./core.js";
|
|
4
4
|
export { effect, type Effect } from "./effect.js";
|
|
5
|
-
export { flush, Queue, type IQueue, type QueueCallback } from "./scheduler.js";
|
|
5
|
+
export { action, flush, Queue, type IQueue, type QueueCallback } from "./scheduler.js";
|
|
6
6
|
export * from "./constants.js";
|
|
@@ -15,8 +15,9 @@ export interface Transition {
|
|
|
15
15
|
asyncNodes: Computed<any>[];
|
|
16
16
|
pendingNodes: Signal<any>[];
|
|
17
17
|
optimisticNodes: Signal<any>[];
|
|
18
|
+
actions: Array<Generator<any, any, any> | AsyncGenerator<any, any, any>>;
|
|
18
19
|
queueStash: QueueStub;
|
|
19
|
-
done: boolean;
|
|
20
|
+
done: boolean | Transition;
|
|
20
21
|
}
|
|
21
22
|
export declare function schedule(): void;
|
|
22
23
|
export interface IQueue {
|
|
@@ -51,7 +52,7 @@ export declare class GlobalQueue extends Queue {
|
|
|
51
52
|
static _dispose: (el: Computed<unknown>, self: boolean, zombie: boolean) => void;
|
|
52
53
|
flush(): void;
|
|
53
54
|
notify(node: Computed<any>, mask: number, flags: number): boolean;
|
|
54
|
-
initTransition(node
|
|
55
|
+
initTransition(node?: Computed<any>): void;
|
|
55
56
|
}
|
|
56
57
|
export declare function notifySubs(node: Signal<any> | Computed<any>): void;
|
|
57
58
|
export declare function runOptimistic(activeTransition?: Transition | null): void;
|
|
@@ -61,5 +62,6 @@ export declare const globalQueue: GlobalQueue;
|
|
|
61
62
|
* the queue synchronously to get the latest updates by calling `flush()`.
|
|
62
63
|
*/
|
|
63
64
|
export declare function flush(): void;
|
|
64
|
-
export declare function runInTransition(
|
|
65
|
+
export declare function runInTransition<T>(transition: Transition, fn: () => T): T;
|
|
66
|
+
export declare function action<Args extends any[], Y, R>(genFn: (...args: Args) => Generator<Y, R, any> | AsyncGenerator<Y, R, any>): (...args: Args) => void;
|
|
65
67
|
export {};
|