@solidjs/signals 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev.js +80 -41
- package/dist/node.cjs +359 -318
- package/dist/prod.js +356 -317
- package/dist/types/core/core.d.ts +1 -0
- package/dist/types/core/error.d.ts +1 -0
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +2 -11
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +10 -0
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// src/core/error.ts
|
|
2
2
|
var NotReadyError = class extends Error {
|
|
3
|
+
constructor(node) {
|
|
4
|
+
super();
|
|
5
|
+
this.cause = node;
|
|
6
|
+
}
|
|
3
7
|
};
|
|
4
8
|
var NoOwnerError = class extends Error {
|
|
5
9
|
constructor() {
|
|
@@ -172,8 +176,10 @@ var Transition = class _Transition {
|
|
|
172
176
|
_running = false;
|
|
173
177
|
_scheduled = false;
|
|
174
178
|
_cloned = globalQueue;
|
|
179
|
+
_signal;
|
|
175
180
|
created = clock;
|
|
176
|
-
constructor() {
|
|
181
|
+
constructor(signal) {
|
|
182
|
+
this._signal = signal;
|
|
177
183
|
this._clonedQueues.set(globalQueue, this);
|
|
178
184
|
for (const child of globalQueue._children) {
|
|
179
185
|
cloneQueue(child, this, this);
|
|
@@ -202,6 +208,7 @@ var Transition = class _Transition {
|
|
|
202
208
|
flush() {
|
|
203
209
|
if (this._running || this._done)
|
|
204
210
|
return;
|
|
211
|
+
globalQueue.flush();
|
|
205
212
|
this._running = true;
|
|
206
213
|
let currentTransition = ActiveTransition;
|
|
207
214
|
ActiveTransition = this;
|
|
@@ -316,13 +323,12 @@ var Transition = class _Transition {
|
|
|
316
323
|
this._optimistic.add(fn);
|
|
317
324
|
}
|
|
318
325
|
};
|
|
319
|
-
function transition(fn) {
|
|
320
|
-
let t = new Transition();
|
|
321
|
-
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
322
|
-
}
|
|
323
326
|
function cloneGraph(node) {
|
|
324
327
|
if (node._optimistic) {
|
|
325
|
-
|
|
328
|
+
if (node._state !== STATE_DISPOSED) {
|
|
329
|
+
!node._transition && node._optimistic._init?.();
|
|
330
|
+
ActiveTransition.addOptimistic(node._optimistic);
|
|
331
|
+
}
|
|
326
332
|
return node;
|
|
327
333
|
}
|
|
328
334
|
if (node._transition) {
|
|
@@ -486,6 +492,7 @@ function finishTransition(transition2) {
|
|
|
486
492
|
delete reset._transition;
|
|
487
493
|
reset();
|
|
488
494
|
}
|
|
495
|
+
transition2._signal.write(true);
|
|
489
496
|
globalQueue.flush();
|
|
490
497
|
}
|
|
491
498
|
|
|
@@ -678,6 +685,10 @@ var Computation = class extends Owner {
|
|
|
678
685
|
}
|
|
679
686
|
}
|
|
680
687
|
_read() {
|
|
688
|
+
if (staleCheck && (this._stateFlags & LOADING_BIT || this._transition)) {
|
|
689
|
+
staleCheck._value = true;
|
|
690
|
+
this._transition?._signal.read();
|
|
691
|
+
}
|
|
681
692
|
track(this);
|
|
682
693
|
newFlags |= this._stateFlags & ~currentMask;
|
|
683
694
|
if (this._stateFlags & ERROR_BIT) {
|
|
@@ -724,11 +735,7 @@ var Computation = class extends Owner {
|
|
|
724
735
|
this._updateIfNecessary();
|
|
725
736
|
}
|
|
726
737
|
if ((notStale || this._stateFlags & UNINITIALIZED_BIT) && this._stateFlags & LOADING_BIT) {
|
|
727
|
-
|
|
728
|
-
throw new NotReadyError();
|
|
729
|
-
}
|
|
730
|
-
if (staleCheck && this._stateFlags & LOADING_BIT) {
|
|
731
|
-
staleCheck._value = true;
|
|
738
|
+
throw new NotReadyError(this);
|
|
732
739
|
}
|
|
733
740
|
return this._read();
|
|
734
741
|
}
|
|
@@ -891,6 +898,12 @@ function update(node) {
|
|
|
891
898
|
node.write(result, newFlags, true);
|
|
892
899
|
} catch (error) {
|
|
893
900
|
if (error instanceof NotReadyError) {
|
|
901
|
+
if (error.cause !== node)
|
|
902
|
+
compute(
|
|
903
|
+
node,
|
|
904
|
+
() => track(error.cause),
|
|
905
|
+
node
|
|
906
|
+
);
|
|
894
907
|
node.write(UNCHANGED, newFlags | LOADING_BIT | node._stateFlags & UNINITIALIZED_BIT);
|
|
895
908
|
} else {
|
|
896
909
|
node._setError(error);
|
|
@@ -964,8 +977,17 @@ function isPending(fn, loadingValue) {
|
|
|
964
977
|
if (!currentObserver)
|
|
965
978
|
return pendingCheck(fn, loadingValue);
|
|
966
979
|
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
980
|
+
c._optimistic = () => c.write(false);
|
|
981
|
+
c._optimistic._init = () => globalQueue.enqueue(0, () => c._optimistic._transition && c.write(true));
|
|
967
982
|
c._handlerMask |= LOADING_BIT;
|
|
968
|
-
|
|
983
|
+
const res = c.wait();
|
|
984
|
+
c._disposal = () => {
|
|
985
|
+
if (c._optimistic._transition) {
|
|
986
|
+
c._optimistic._transition._optimistic.delete(c._optimistic);
|
|
987
|
+
delete c._optimistic._transition;
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
return res;
|
|
969
991
|
}
|
|
970
992
|
function latest(fn, fallback) {
|
|
971
993
|
const argLength = arguments.length;
|
|
@@ -1105,11 +1127,15 @@ var TrackedEffect = class extends Computation {
|
|
|
1105
1127
|
_type = EFFECT_USER;
|
|
1106
1128
|
_cleanup;
|
|
1107
1129
|
constructor(compute2, options) {
|
|
1108
|
-
super(
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1130
|
+
super(
|
|
1131
|
+
void 0,
|
|
1132
|
+
() => {
|
|
1133
|
+
this._cleanup?.();
|
|
1134
|
+
this._cleanup = latest(compute2);
|
|
1135
|
+
return void 0;
|
|
1136
|
+
},
|
|
1137
|
+
options
|
|
1138
|
+
);
|
|
1113
1139
|
getQueue(this).enqueue(this._type, this._run.bind(this));
|
|
1114
1140
|
if (!this._parent)
|
|
1115
1141
|
console.warn("Effects created outside a reactive context will never be disposed");
|
|
@@ -1196,10 +1222,13 @@ function runTop(node) {
|
|
|
1196
1222
|
function createSignal(first, second, third) {
|
|
1197
1223
|
if (typeof first === "function") {
|
|
1198
1224
|
const node2 = new Computation(second, first, third);
|
|
1199
|
-
return [
|
|
1200
|
-
node2.
|
|
1201
|
-
|
|
1202
|
-
|
|
1225
|
+
return [
|
|
1226
|
+
node2.wait.bind(node2),
|
|
1227
|
+
(v) => {
|
|
1228
|
+
node2._updateIfNecessary();
|
|
1229
|
+
return node2.write(v);
|
|
1230
|
+
}
|
|
1231
|
+
];
|
|
1203
1232
|
}
|
|
1204
1233
|
const o = getOwner();
|
|
1205
1234
|
const needsId = o?.id != null;
|
|
@@ -1291,7 +1320,7 @@ function createAsync(compute2, value, options) {
|
|
|
1291
1320
|
}
|
|
1292
1321
|
})();
|
|
1293
1322
|
}
|
|
1294
|
-
throw new NotReadyError();
|
|
1323
|
+
throw new NotReadyError(getOwner());
|
|
1295
1324
|
},
|
|
1296
1325
|
options
|
|
1297
1326
|
);
|
|
@@ -1369,12 +1398,17 @@ function resolve(fn) {
|
|
|
1369
1398
|
});
|
|
1370
1399
|
}
|
|
1371
1400
|
function createOptimistic(first, second, third) {
|
|
1372
|
-
const node = typeof first === "function" ? new Computation(
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1401
|
+
const node = typeof first === "function" ? new Computation(
|
|
1402
|
+
second,
|
|
1403
|
+
(prev) => {
|
|
1404
|
+
if (node._optimistic._transition) {
|
|
1405
|
+
latest(() => first(prev));
|
|
1406
|
+
return prev;
|
|
1407
|
+
}
|
|
1408
|
+
return first(prev);
|
|
1409
|
+
},
|
|
1410
|
+
third
|
|
1411
|
+
) : new Computation(first, null, second);
|
|
1378
1412
|
node._optimistic = () => node.write(first);
|
|
1379
1413
|
function write(v) {
|
|
1380
1414
|
if (!ActiveTransition)
|
|
@@ -1387,7 +1421,11 @@ function createOptimistic(first, second, third) {
|
|
|
1387
1421
|
}
|
|
1388
1422
|
});
|
|
1389
1423
|
}
|
|
1390
|
-
return [node.
|
|
1424
|
+
return [node.wait.bind(node), write];
|
|
1425
|
+
}
|
|
1426
|
+
function transition(fn) {
|
|
1427
|
+
let t = new Transition(new Computation(void 0, null));
|
|
1428
|
+
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
1391
1429
|
}
|
|
1392
1430
|
function useTransition() {
|
|
1393
1431
|
const [pending, setPending] = createOptimistic(false);
|
|
@@ -1858,20 +1896,21 @@ function deep(store) {
|
|
|
1858
1896
|
// src/store/optimistic.ts
|
|
1859
1897
|
function createOptimisticStore(first, second, options) {
|
|
1860
1898
|
const derived = typeof first === "function";
|
|
1861
|
-
const { store, node } = derived ? createProjectionInternal(
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1899
|
+
const { store, node } = derived ? createProjectionInternal(
|
|
1900
|
+
(draft) => {
|
|
1901
|
+
if (reset._transition) {
|
|
1902
|
+
latest(() => first(draft));
|
|
1903
|
+
return draft;
|
|
1904
|
+
}
|
|
1905
|
+
return first(draft);
|
|
1906
|
+
},
|
|
1907
|
+
second,
|
|
1908
|
+
options
|
|
1909
|
+
) : createProjectionInternal(() => {
|
|
1867
1910
|
}, first);
|
|
1868
1911
|
const reset = () => storeSetter(
|
|
1869
1912
|
store,
|
|
1870
|
-
reconcile(
|
|
1871
|
-
derived ? first(store) || store : first,
|
|
1872
|
-
options?.key || "id",
|
|
1873
|
-
options?.all
|
|
1874
|
-
)
|
|
1913
|
+
reconcile(derived ? first(store) || store : first, options?.key || "id", options?.all)
|
|
1875
1914
|
);
|
|
1876
1915
|
const write = (v) => {
|
|
1877
1916
|
if (!ActiveTransition)
|
|
@@ -2306,7 +2345,7 @@ function createBoundChildren(owner, fn, queue, mask) {
|
|
|
2306
2345
|
owner,
|
|
2307
2346
|
() => {
|
|
2308
2347
|
const c = new Computation(void 0, fn);
|
|
2309
|
-
return new BoundaryComputation(() => flatten(c.wait()), mask);
|
|
2348
|
+
return new BoundaryComputation(() => latest(() => flatten(c.wait())), mask);
|
|
2310
2349
|
},
|
|
2311
2350
|
null
|
|
2312
2351
|
);
|