@solidjs/signals 0.10.2 → 0.10.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 +169 -151
- package/dist/node.cjs +412 -399
- package/dist/prod.js +329 -316
- package/dist/types/core/core.d.ts +1 -6
- package/dist/types/core/index.d.ts +3 -1
- package/dist/types/core/owner.d.ts +5 -2
- package/dist/types/core/types.d.ts +2 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +2 -0
- package/package.json +2 -2
package/dist/dev.js
CHANGED
|
@@ -717,100 +717,67 @@ function notifyStatus(el, status, error, blockStatus, lane) {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
lazy: true
|
|
720
|
+
function unlinkSubs(link) {
|
|
721
|
+
const dep = link._dep;
|
|
722
|
+
const nextDep = link._nextDep;
|
|
723
|
+
const nextSub = link._nextSub;
|
|
724
|
+
const prevSub = link._prevSub;
|
|
725
|
+
if (nextSub !== null) nextSub._prevSub = prevSub;
|
|
726
|
+
else dep._subsTail = prevSub;
|
|
727
|
+
if (prevSub !== null) prevSub._nextSub = nextSub;
|
|
728
|
+
else {
|
|
729
|
+
dep._subs = nextSub;
|
|
730
|
+
if (nextSub === null) {
|
|
731
|
+
dep._unobserved?.();
|
|
732
|
+
dep._fn && !dep._preventAutoDisposal && unobserved(dep);
|
|
734
733
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
node._effectFn = effect;
|
|
738
|
-
node._errorFn = error;
|
|
739
|
-
node._cleanup = undefined;
|
|
740
|
-
node._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
741
|
-
node._notifyStatus = (status, error) => {
|
|
742
|
-
const actualStatus = status !== undefined ? status : node._statusFlags;
|
|
743
|
-
const actualError = error !== undefined ? error : node._error;
|
|
744
|
-
if (actualStatus & STATUS_ERROR) {
|
|
745
|
-
let err = actualError;
|
|
746
|
-
node._queue.notify(node, STATUS_PENDING, 0);
|
|
747
|
-
if (node._type === EFFECT_USER) {
|
|
748
|
-
try {
|
|
749
|
-
return node._errorFn
|
|
750
|
-
? node._errorFn(err, () => {
|
|
751
|
-
node._cleanup?.();
|
|
752
|
-
node._cleanup = undefined;
|
|
753
|
-
})
|
|
754
|
-
: console.error(err);
|
|
755
|
-
} catch (e) {
|
|
756
|
-
err = e;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
if (!node._queue.notify(node, STATUS_ERROR, STATUS_ERROR)) throw err;
|
|
760
|
-
} else if (node._type === EFFECT_RENDER)
|
|
761
|
-
node._queue.notify(node, STATUS_PENDING | STATUS_ERROR, actualStatus, actualError);
|
|
762
|
-
};
|
|
763
|
-
recompute(node, true);
|
|
764
|
-
!options?.defer &&
|
|
765
|
-
(node._type === EFFECT_USER
|
|
766
|
-
? node._queue.enqueue(node._type, runEffect.bind(node))
|
|
767
|
-
: runEffect.call(node));
|
|
768
|
-
initialized = true;
|
|
769
|
-
onCleanup(() => node._cleanup?.());
|
|
770
|
-
if (!node._parent)
|
|
771
|
-
console.warn("Effects created outside a reactive context will never be disposed");
|
|
734
|
+
}
|
|
735
|
+
return nextDep;
|
|
772
736
|
}
|
|
773
|
-
function
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
this._cleanup = this._effectFn(this._value, this._prevValue);
|
|
779
|
-
} catch (error) {
|
|
780
|
-
if (!this._queue.notify(this, STATUS_ERROR, STATUS_ERROR)) throw error;
|
|
781
|
-
} finally {
|
|
782
|
-
this._prevValue = this._value;
|
|
783
|
-
this._modified = false;
|
|
737
|
+
function unobserved(el) {
|
|
738
|
+
deleteFromHeap(el, el._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
|
|
739
|
+
let dep = el._deps;
|
|
740
|
+
while (dep !== null) {
|
|
741
|
+
dep = unlinkSubs(dep);
|
|
784
742
|
}
|
|
743
|
+
el._deps = null;
|
|
744
|
+
disposeChildren(el, true);
|
|
785
745
|
}
|
|
786
|
-
function
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
()
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
);
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
if (
|
|
813
|
-
|
|
746
|
+
function link(dep, sub) {
|
|
747
|
+
const prevDep = sub._depsTail;
|
|
748
|
+
if (prevDep !== null && prevDep._dep === dep) return;
|
|
749
|
+
let nextDep = null;
|
|
750
|
+
const isRecomputing = sub._flags & REACTIVE_RECOMPUTING_DEPS;
|
|
751
|
+
if (isRecomputing) {
|
|
752
|
+
nextDep = prevDep !== null ? prevDep._nextDep : sub._deps;
|
|
753
|
+
if (nextDep !== null && nextDep._dep === dep) {
|
|
754
|
+
sub._depsTail = nextDep;
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
const prevSub = dep._subsTail;
|
|
759
|
+
if (prevSub !== null && prevSub._sub === sub && (!isRecomputing || isValidLink(prevSub, sub)))
|
|
760
|
+
return;
|
|
761
|
+
const newLink =
|
|
762
|
+
(sub._depsTail =
|
|
763
|
+
dep._subsTail =
|
|
764
|
+
{ _dep: dep, _sub: sub, _nextDep: nextDep, _prevSub: prevSub, _nextSub: null });
|
|
765
|
+
if (prevDep !== null) prevDep._nextDep = newLink;
|
|
766
|
+
else sub._deps = newLink;
|
|
767
|
+
if (prevSub !== null) prevSub._nextSub = newLink;
|
|
768
|
+
else dep._subs = newLink;
|
|
769
|
+
}
|
|
770
|
+
function isValidLink(checkLink, sub) {
|
|
771
|
+
const depsTail = sub._depsTail;
|
|
772
|
+
if (depsTail !== null) {
|
|
773
|
+
let link = sub._deps;
|
|
774
|
+
do {
|
|
775
|
+
if (link === checkLink) return true;
|
|
776
|
+
if (link === depsTail) break;
|
|
777
|
+
link = link._nextDep;
|
|
778
|
+
} while (link !== null);
|
|
779
|
+
}
|
|
780
|
+
return false;
|
|
814
781
|
}
|
|
815
782
|
const PENDING_OWNER = {};
|
|
816
783
|
function markDisposal(el) {
|
|
@@ -875,10 +842,19 @@ function runDisposal(node, zombie) {
|
|
|
875
842
|
}
|
|
876
843
|
zombie ? (node._pendingDisposal = null) : (node._disposal = null);
|
|
877
844
|
}
|
|
878
|
-
function
|
|
879
|
-
|
|
845
|
+
function childId(owner, consume) {
|
|
846
|
+
let counter = owner;
|
|
847
|
+
while (counter._transparent && counter._parent) counter = counter._parent;
|
|
848
|
+
if (counter.id != null)
|
|
849
|
+
return formatId(counter.id, consume ? counter._childCount++ : counter._childCount);
|
|
880
850
|
throw new Error("Cannot get child id from owner without an id");
|
|
881
851
|
}
|
|
852
|
+
function getNextChildId(owner) {
|
|
853
|
+
return childId(owner, true);
|
|
854
|
+
}
|
|
855
|
+
function peekNextChildId(owner) {
|
|
856
|
+
return childId(owner, false);
|
|
857
|
+
}
|
|
882
858
|
function formatId(prefix, id) {
|
|
883
859
|
const num = id.toString(36),
|
|
884
860
|
len = num.length - 1;
|
|
@@ -900,8 +876,12 @@ function onCleanup(fn) {
|
|
|
900
876
|
}
|
|
901
877
|
function createOwner(options) {
|
|
902
878
|
const parent = context;
|
|
879
|
+
const transparent = options?.transparent ?? false;
|
|
903
880
|
const owner = {
|
|
904
|
-
id:
|
|
881
|
+
id:
|
|
882
|
+
options?.id ??
|
|
883
|
+
(transparent ? parent?.id : parent?.id != null ? getNextChildId(parent) : undefined),
|
|
884
|
+
_transparent: transparent || undefined,
|
|
905
885
|
_root: true,
|
|
906
886
|
_parentComputed: parent?._root ? parent._parentComputed : parent,
|
|
907
887
|
_firstChild: null,
|
|
@@ -935,67 +915,100 @@ function createRoot(init, options) {
|
|
|
935
915
|
const owner = createOwner(options);
|
|
936
916
|
return runWithOwner(owner, () => init(owner.dispose));
|
|
937
917
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
918
|
+
let leafEffectActive = false;
|
|
919
|
+
function effect(compute, effect, error, initialValue, options) {
|
|
920
|
+
let initialized = false;
|
|
921
|
+
const node = computed(
|
|
922
|
+
options?.render ? p => staleValues(() => compute(p)) : compute,
|
|
923
|
+
initialValue,
|
|
924
|
+
{
|
|
925
|
+
...options,
|
|
926
|
+
equals: () => {
|
|
927
|
+
node._modified = !node._error;
|
|
928
|
+
if (initialized) node._queue.enqueue(node._type, runEffect.bind(node));
|
|
929
|
+
return false;
|
|
930
|
+
},
|
|
931
|
+
lazy: true
|
|
951
932
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
933
|
+
);
|
|
934
|
+
node._prevValue = initialValue;
|
|
935
|
+
node._effectFn = effect;
|
|
936
|
+
node._errorFn = error;
|
|
937
|
+
node._cleanup = undefined;
|
|
938
|
+
node._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
939
|
+
node._notifyStatus = (status, error) => {
|
|
940
|
+
const actualStatus = status !== undefined ? status : node._statusFlags;
|
|
941
|
+
const actualError = error !== undefined ? error : node._error;
|
|
942
|
+
if (actualStatus & STATUS_ERROR) {
|
|
943
|
+
let err = actualError;
|
|
944
|
+
node._queue.notify(node, STATUS_PENDING, 0);
|
|
945
|
+
if (node._type === EFFECT_USER) {
|
|
946
|
+
try {
|
|
947
|
+
return node._errorFn
|
|
948
|
+
? node._errorFn(err, () => {
|
|
949
|
+
node._cleanup?.();
|
|
950
|
+
node._cleanup = undefined;
|
|
951
|
+
})
|
|
952
|
+
: console.error(err);
|
|
953
|
+
} catch (e) {
|
|
954
|
+
err = e;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (!node._queue.notify(node, STATUS_ERROR, STATUS_ERROR)) throw err;
|
|
958
|
+
} else if (node._type === EFFECT_RENDER)
|
|
959
|
+
node._queue.notify(node, STATUS_PENDING | STATUS_ERROR, actualStatus, actualError);
|
|
960
|
+
};
|
|
961
|
+
recompute(node, true);
|
|
962
|
+
!options?.defer &&
|
|
963
|
+
(node._type === EFFECT_USER
|
|
964
|
+
? node._queue.enqueue(node._type, runEffect.bind(node))
|
|
965
|
+
: runEffect.call(node));
|
|
966
|
+
initialized = true;
|
|
967
|
+
onCleanup(() => node._cleanup?.());
|
|
968
|
+
if (!node._parent)
|
|
969
|
+
console.warn("Effects created outside a reactive context will never be disposed");
|
|
963
970
|
}
|
|
964
|
-
function
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
971
|
+
function runEffect() {
|
|
972
|
+
if (!this._modified || this._flags & REACTIVE_DISPOSED) return;
|
|
973
|
+
this._cleanup?.();
|
|
974
|
+
this._cleanup = undefined;
|
|
975
|
+
try {
|
|
976
|
+
this._cleanup = this._effectFn(this._value, this._prevValue);
|
|
977
|
+
} catch (error) {
|
|
978
|
+
if (!this._queue.notify(this, STATUS_ERROR, STATUS_ERROR)) throw error;
|
|
979
|
+
} finally {
|
|
980
|
+
this._prevValue = this._value;
|
|
981
|
+
this._modified = false;
|
|
975
982
|
}
|
|
976
|
-
const prevSub = dep._subsTail;
|
|
977
|
-
if (prevSub !== null && prevSub._sub === sub && (!isRecomputing || isValidLink(prevSub, sub)))
|
|
978
|
-
return;
|
|
979
|
-
const newLink =
|
|
980
|
-
(sub._depsTail =
|
|
981
|
-
dep._subsTail =
|
|
982
|
-
{ _dep: dep, _sub: sub, _nextDep: nextDep, _prevSub: prevSub, _nextSub: null });
|
|
983
|
-
if (prevDep !== null) prevDep._nextDep = newLink;
|
|
984
|
-
else sub._deps = newLink;
|
|
985
|
-
if (prevSub !== null) prevSub._nextSub = newLink;
|
|
986
|
-
else dep._subs = newLink;
|
|
987
983
|
}
|
|
988
|
-
function
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
984
|
+
function trackedEffect(fn, options) {
|
|
985
|
+
const run = () => {
|
|
986
|
+
if (!node._modified || node._flags & REACTIVE_DISPOSED) return;
|
|
987
|
+
node._modified = false;
|
|
988
|
+
recompute(node);
|
|
989
|
+
};
|
|
990
|
+
const node = computed(
|
|
991
|
+
() => {
|
|
992
|
+
leafEffectActive = true;
|
|
993
|
+
try {
|
|
994
|
+
node._cleanup?.();
|
|
995
|
+
node._cleanup = undefined;
|
|
996
|
+
node._cleanup = staleValues(fn) || undefined;
|
|
997
|
+
} finally {
|
|
998
|
+
leafEffectActive = false;
|
|
999
|
+
}
|
|
1000
|
+
},
|
|
1001
|
+
undefined,
|
|
1002
|
+
{ ...options, lazy: true, pureWrite: true }
|
|
1003
|
+
);
|
|
1004
|
+
node._cleanup = undefined;
|
|
1005
|
+
node._modified = true;
|
|
1006
|
+
node._type = EFFECT_TRACKED;
|
|
1007
|
+
node._run = run;
|
|
1008
|
+
node._queue.enqueue(EFFECT_USER, run);
|
|
1009
|
+
onCleanup(() => node._cleanup?.());
|
|
1010
|
+
if (!node._parent)
|
|
1011
|
+
console.warn("Effects created outside a reactive context will never be disposed");
|
|
999
1012
|
}
|
|
1000
1013
|
GlobalQueue._update = recompute;
|
|
1001
1014
|
GlobalQueue._dispose = disposeChildren;
|
|
@@ -1135,8 +1148,12 @@ function updateIfNecessary(el) {
|
|
|
1135
1148
|
el._flags = REACTIVE_NONE;
|
|
1136
1149
|
}
|
|
1137
1150
|
function computed(fn, initialValue, options) {
|
|
1151
|
+
const transparent = options?.transparent ?? false;
|
|
1138
1152
|
const self = {
|
|
1139
|
-
id:
|
|
1153
|
+
id:
|
|
1154
|
+
options?.id ??
|
|
1155
|
+
(transparent ? context?.id : context?.id != null ? getNextChildId(context) : undefined),
|
|
1156
|
+
_transparent: transparent || undefined,
|
|
1140
1157
|
_equals: options?.equals != null ? options.equals : isEqual,
|
|
1141
1158
|
_pureWrite: !!options?.pureWrite,
|
|
1142
1159
|
_unobserved: options?.unobserved,
|
|
@@ -2892,6 +2909,7 @@ export {
|
|
|
2892
2909
|
omit,
|
|
2893
2910
|
onCleanup,
|
|
2894
2911
|
onSettled,
|
|
2912
|
+
peekNextChildId,
|
|
2895
2913
|
pending,
|
|
2896
2914
|
reconcile,
|
|
2897
2915
|
refresh,
|