@solidjs/signals 0.0.4 → 0.0.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 +92 -19
- package/dist/node.cjs +221 -145
- package/dist/prod.js +218 -145
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/scheduler.d.ts +1 -0
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/core/utils.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +8 -3
- package/package.json +1 -1
- package/dist/types/utils.d.ts +0 -1
package/dist/dev.js
CHANGED
|
@@ -3,9 +3,7 @@ var NotReadyError = class extends Error {
|
|
|
3
3
|
};
|
|
4
4
|
var NoOwnerError = class extends Error {
|
|
5
5
|
constructor() {
|
|
6
|
-
super(
|
|
7
|
-
"Context can only be accessed under a reactive root."
|
|
8
|
-
);
|
|
6
|
+
super("Context can only be accessed under a reactive root." );
|
|
9
7
|
}
|
|
10
8
|
};
|
|
11
9
|
var ContextNotFoundError = class extends Error {
|
|
@@ -16,11 +14,6 @@ var ContextNotFoundError = class extends Error {
|
|
|
16
14
|
}
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
// src/utils.ts
|
|
20
|
-
function isUndefined(value) {
|
|
21
|
-
return typeof value === "undefined";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
// src/core/constants.ts
|
|
25
18
|
var STATE_CLEAN = 0;
|
|
26
19
|
var STATE_CHECK = 1;
|
|
@@ -32,6 +25,65 @@ var EFFECT_RENDER = 1;
|
|
|
32
25
|
var EFFECT_USER = 2;
|
|
33
26
|
var SUPPORTS_PROXY = typeof Proxy === "function";
|
|
34
27
|
|
|
28
|
+
// src/core/utils.ts
|
|
29
|
+
function isUndefined(value) {
|
|
30
|
+
return typeof value === "undefined";
|
|
31
|
+
}
|
|
32
|
+
function flatten(children, options) {
|
|
33
|
+
if (typeof children === "function" && !children.length) {
|
|
34
|
+
if (options?.doNotUnwrap)
|
|
35
|
+
return children;
|
|
36
|
+
do {
|
|
37
|
+
children = children();
|
|
38
|
+
} while (typeof children === "function" && !children.length);
|
|
39
|
+
}
|
|
40
|
+
if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
|
|
41
|
+
return;
|
|
42
|
+
if (Array.isArray(children)) {
|
|
43
|
+
let results = [];
|
|
44
|
+
if (flattenArray(children, results, options)) {
|
|
45
|
+
return () => {
|
|
46
|
+
let nested = [];
|
|
47
|
+
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
48
|
+
return nested;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
return children;
|
|
54
|
+
}
|
|
55
|
+
function flattenArray(children, results = [], options) {
|
|
56
|
+
let notReady = null;
|
|
57
|
+
let needsUnwrap = false;
|
|
58
|
+
for (let i = 0; i < children.length; i++) {
|
|
59
|
+
try {
|
|
60
|
+
let child = children[i];
|
|
61
|
+
if (typeof child === "function" && !child.length) {
|
|
62
|
+
if (options?.doNotUnwrap) {
|
|
63
|
+
results.push(child);
|
|
64
|
+
needsUnwrap = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
do {
|
|
68
|
+
child = child();
|
|
69
|
+
} while (typeof child === "function" && !child.length);
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(child)) {
|
|
72
|
+
needsUnwrap = flattenArray(child, results, options);
|
|
73
|
+
} else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
|
|
74
|
+
} else
|
|
75
|
+
results.push(child);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (!(e instanceof NotReadyError))
|
|
78
|
+
throw e;
|
|
79
|
+
notReady = e;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (notReady)
|
|
83
|
+
throw notReady;
|
|
84
|
+
return needsUnwrap;
|
|
85
|
+
}
|
|
86
|
+
|
|
35
87
|
// src/core/owner.ts
|
|
36
88
|
var currentOwner = null;
|
|
37
89
|
var defaultContext = {};
|
|
@@ -226,7 +278,7 @@ var Computation = class extends Owner {
|
|
|
226
278
|
_read() {
|
|
227
279
|
if (this._compute)
|
|
228
280
|
this._updateIfNecessary();
|
|
229
|
-
if (!this.
|
|
281
|
+
if (!this._compute || this._sources?.length)
|
|
230
282
|
track(this);
|
|
231
283
|
newFlags |= this._stateFlags & ~currentMask;
|
|
232
284
|
if (this._stateFlags & ERROR_BIT) {
|
|
@@ -598,14 +650,22 @@ var Queue = class {
|
|
|
598
650
|
}
|
|
599
651
|
};
|
|
600
652
|
var globalQueue = new Queue();
|
|
653
|
+
var globalTasks = [];
|
|
601
654
|
function flushSync() {
|
|
602
655
|
let count = 0;
|
|
603
656
|
while (scheduled) {
|
|
604
657
|
if (++count === 1e5)
|
|
605
658
|
throw new Error("Potential Infinite Loop Detected.");
|
|
606
659
|
globalQueue.flush();
|
|
660
|
+
for (let i = 0; i < globalTasks.length; i++)
|
|
661
|
+
globalTasks[i]();
|
|
662
|
+
globalTasks.length = 0;
|
|
607
663
|
}
|
|
608
664
|
}
|
|
665
|
+
function queueTask(fn) {
|
|
666
|
+
globalTasks.push(fn);
|
|
667
|
+
schedule();
|
|
668
|
+
}
|
|
609
669
|
function createBoundary(fn, queue) {
|
|
610
670
|
const owner = new Owner();
|
|
611
671
|
const parentQueue = owner._queue || globalQueue;
|
|
@@ -657,7 +717,7 @@ var Effect = class extends Computation {
|
|
|
657
717
|
write(value, flags = 0) {
|
|
658
718
|
const currentFlags = this._stateFlags;
|
|
659
719
|
this._stateFlags = flags;
|
|
660
|
-
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
720
|
+
if (this._type === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
661
721
|
this._queue._update?.(this);
|
|
662
722
|
}
|
|
663
723
|
if (value === UNCHANGED)
|
|
@@ -722,22 +782,35 @@ var SuspenseQueue = class extends Queue {
|
|
|
722
782
|
this._nodes.add(node);
|
|
723
783
|
if (!this._fallback) {
|
|
724
784
|
this._fallback = true;
|
|
725
|
-
|
|
785
|
+
queueTask(() => this._signal.write(true));
|
|
726
786
|
}
|
|
727
787
|
} else {
|
|
728
788
|
this._nodes.delete(node);
|
|
729
789
|
if (this._nodes.size === 0) {
|
|
730
790
|
this._fallback = false;
|
|
731
|
-
|
|
791
|
+
queueTask(() => this._signal.write(false));
|
|
732
792
|
}
|
|
733
793
|
}
|
|
734
794
|
}
|
|
735
795
|
};
|
|
796
|
+
var LiveComputation = class extends EagerComputation {
|
|
797
|
+
write(value, flags = 0) {
|
|
798
|
+
const currentFlags = this._stateFlags;
|
|
799
|
+
super.write(value, flags);
|
|
800
|
+
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
801
|
+
this._queue._update?.(this);
|
|
802
|
+
}
|
|
803
|
+
return this._value;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
736
806
|
function createSuspense(fn, fallbackFn) {
|
|
737
807
|
const queue = new SuspenseQueue();
|
|
738
|
-
const tree = createBoundary(
|
|
808
|
+
const tree = createBoundary(() => {
|
|
809
|
+
const child = new Computation(null, fn);
|
|
810
|
+
return new LiveComputation(null, () => flatten(child.wait()));
|
|
811
|
+
}, queue);
|
|
739
812
|
const equality = new Computation(null, () => queue._signal.read() || queue._fallback);
|
|
740
|
-
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
|
|
813
|
+
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree.read());
|
|
741
814
|
return comp.read.bind(comp);
|
|
742
815
|
}
|
|
743
816
|
|
|
@@ -767,7 +840,7 @@ function createMemo(compute2, value, options) {
|
|
|
767
840
|
return () => {
|
|
768
841
|
if (node) {
|
|
769
842
|
resolvedValue = node.wait();
|
|
770
|
-
if (!node._sources?.length) {
|
|
843
|
+
if (!node._sources?.length && node._nextSibling?._parent !== node) {
|
|
771
844
|
node.dispose();
|
|
772
845
|
node = void 0;
|
|
773
846
|
} else if (!node._parent && !node._observers?.length) {
|
|
@@ -801,7 +874,7 @@ function createAsync(compute2, value, options) {
|
|
|
801
874
|
if (isPromise) {
|
|
802
875
|
source.then(
|
|
803
876
|
(value3) => {
|
|
804
|
-
signal.write(value3, 0);
|
|
877
|
+
signal.write(value3, 0, true);
|
|
805
878
|
},
|
|
806
879
|
(error) => {
|
|
807
880
|
signal.write(error, ERROR_BIT);
|
|
@@ -815,7 +888,7 @@ function createAsync(compute2, value, options) {
|
|
|
815
888
|
for await (let value3 of source) {
|
|
816
889
|
if (abort)
|
|
817
890
|
return;
|
|
818
|
-
signal.write(value3, 0);
|
|
891
|
+
signal.write(value3, 0, true);
|
|
819
892
|
}
|
|
820
893
|
} catch (error) {
|
|
821
894
|
signal.write(error, ERROR_BIT);
|
|
@@ -857,7 +930,7 @@ function catchError(fn, handler) {
|
|
|
857
930
|
const owner = new Owner();
|
|
858
931
|
owner._handlers = owner._handlers ? [handler, ...owner._handlers] : [handler];
|
|
859
932
|
try {
|
|
860
|
-
compute(owner, fn, null);
|
|
933
|
+
return compute(owner, fn, null);
|
|
861
934
|
} catch (error) {
|
|
862
935
|
owner.handleError(error);
|
|
863
936
|
}
|
|
@@ -1441,4 +1514,4 @@ function compare(key, a, b) {
|
|
|
1441
1514
|
return key ? key(a) === key(b) : true;
|
|
1442
1515
|
}
|
|
1443
1516
|
|
|
1444
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
|
|
1517
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
|