@solidjs/signals 0.0.11 → 0.2.0
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 +43 -28
- package/dist/node.cjs +204 -189
- package/dist/prod.js +204 -189
- package/dist/types/core/core.d.ts +7 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +5 -18
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -664,11 +664,9 @@ function isStale(fn) {
|
|
|
664
664
|
try {
|
|
665
665
|
latest(fn);
|
|
666
666
|
return staleCheck._value;
|
|
667
|
-
} catch {
|
|
668
667
|
} finally {
|
|
669
668
|
staleCheck = current;
|
|
670
669
|
}
|
|
671
|
-
return false;
|
|
672
670
|
}
|
|
673
671
|
function latest(fn) {
|
|
674
672
|
const prevFlags = newFlags;
|
|
@@ -690,6 +688,43 @@ function catchError(fn) {
|
|
|
690
688
|
return e;
|
|
691
689
|
}
|
|
692
690
|
}
|
|
691
|
+
function runWithObserver(observer, run) {
|
|
692
|
+
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
|
693
|
+
newSources = null;
|
|
694
|
+
newSourcesIndex = observer._sources ? observer._sources.length : 0;
|
|
695
|
+
newFlags = 0;
|
|
696
|
+
try {
|
|
697
|
+
return compute(observer, run, observer);
|
|
698
|
+
} catch (error) {
|
|
699
|
+
if (error instanceof NotReadyError) {
|
|
700
|
+
observer.write(UNCHANGED, newFlags | LOADING_BIT | observer._stateFlags & UNINITIALIZED_BIT);
|
|
701
|
+
} else {
|
|
702
|
+
observer._setError(error);
|
|
703
|
+
}
|
|
704
|
+
} finally {
|
|
705
|
+
if (newSources) {
|
|
706
|
+
if (newSourcesIndex > 0) {
|
|
707
|
+
observer._sources.length = newSourcesIndex + newSources.length;
|
|
708
|
+
for (let i = 0; i < newSources.length; i++) {
|
|
709
|
+
observer._sources[newSourcesIndex + i] = newSources[i];
|
|
710
|
+
}
|
|
711
|
+
} else {
|
|
712
|
+
observer._sources = newSources;
|
|
713
|
+
}
|
|
714
|
+
let source;
|
|
715
|
+
for (let i = newSourcesIndex; i < observer._sources.length; i++) {
|
|
716
|
+
source = observer._sources[i];
|
|
717
|
+
if (!source._observers)
|
|
718
|
+
source._observers = [observer];
|
|
719
|
+
else
|
|
720
|
+
source._observers.push(observer);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
newSources = prevSources;
|
|
724
|
+
newSourcesIndex = prevSourcesIndex;
|
|
725
|
+
newFlags = prevFlags;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
693
728
|
function compute(owner, fn, observer) {
|
|
694
729
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
695
730
|
currentObserver = observer;
|
|
@@ -729,10 +764,8 @@ var Effect = class extends Computation {
|
|
|
729
764
|
if (this._type === EFFECT_RENDER) {
|
|
730
765
|
this._compute = (p) => getClock() > this._queue.created ? latest(() => compute2(p)) : compute2(p);
|
|
731
766
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect();
|
|
735
|
-
}
|
|
767
|
+
this._updateIfNecessary();
|
|
768
|
+
!options?.defer && (this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect());
|
|
736
769
|
if (!this._parent)
|
|
737
770
|
console.warn("Effects created outside a reactive context will never be disposed");
|
|
738
771
|
}
|
|
@@ -977,13 +1010,13 @@ function createEffect(compute2, effect, error, value, options) {
|
|
|
977
1010
|
compute2,
|
|
978
1011
|
effect,
|
|
979
1012
|
error,
|
|
980
|
-
{ name: options?.name ?? "effect" }
|
|
1013
|
+
{ ...options, name: options?.name ?? "effect" }
|
|
981
1014
|
);
|
|
982
1015
|
}
|
|
983
1016
|
function createRenderEffect(compute2, effect, value, options) {
|
|
984
1017
|
void new Effect(value, compute2, effect, void 0, {
|
|
985
1018
|
render: true,
|
|
986
|
-
...{ name: options?.name ?? "effect" }
|
|
1019
|
+
...{ ...options, name: options?.name ?? "effect" }
|
|
987
1020
|
});
|
|
988
1021
|
}
|
|
989
1022
|
function createRoot(init) {
|
|
@@ -991,12 +1024,7 @@ function createRoot(init) {
|
|
|
991
1024
|
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
992
1025
|
}
|
|
993
1026
|
function runWithOwner(owner, run) {
|
|
994
|
-
|
|
995
|
-
return compute(owner, run, null);
|
|
996
|
-
} catch (error) {
|
|
997
|
-
owner?.handleError(error);
|
|
998
|
-
return void 0;
|
|
999
|
-
}
|
|
1027
|
+
return compute(owner, run, null);
|
|
1000
1028
|
}
|
|
1001
1029
|
function createErrorBoundary(fn, fallback) {
|
|
1002
1030
|
const owner = new Owner();
|
|
@@ -1063,19 +1091,6 @@ function resolve(fn) {
|
|
|
1063
1091
|
});
|
|
1064
1092
|
});
|
|
1065
1093
|
}
|
|
1066
|
-
function createReaction(effect, error, options) {
|
|
1067
|
-
const node = new Effect(void 0, () => {
|
|
1068
|
-
}, effect, error, {
|
|
1069
|
-
defer: true,
|
|
1070
|
-
...{ name: options?.name ?? "reaction" }
|
|
1071
|
-
});
|
|
1072
|
-
return (tracking) => {
|
|
1073
|
-
node._compute = tracking;
|
|
1074
|
-
node._state = STATE_DIRTY;
|
|
1075
|
-
node._updateIfNecessary();
|
|
1076
|
-
node._compute = null;
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
1094
|
|
|
1080
1095
|
// src/store/projection.ts
|
|
1081
1096
|
function createProjection(fn, initialValue = {}) {
|
|
@@ -1726,4 +1741,4 @@ function compare(key, a, b) {
|
|
|
1726
1741
|
return key ? key(a) === key(b) : true;
|
|
1727
1742
|
}
|
|
1728
1743
|
|
|
1729
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection,
|
|
1744
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isStale, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
|