@solidjs/signals 0.1.0 → 0.2.1
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 +58 -30
- package/dist/node.cjs +220 -192
- package/dist/prod.js +219 -191
- package/dist/types/core/core.d.ts +10 -2
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +7 -19
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -658,24 +658,32 @@ function hasUpdated(fn) {
|
|
|
658
658
|
updateCheck = current;
|
|
659
659
|
}
|
|
660
660
|
}
|
|
661
|
-
function
|
|
661
|
+
function isPending(fn, loadingValue) {
|
|
662
|
+
const argLength = arguments.length;
|
|
662
663
|
const current = staleCheck;
|
|
663
664
|
staleCheck = { _value: false };
|
|
664
665
|
try {
|
|
665
666
|
latest(fn);
|
|
666
667
|
return staleCheck._value;
|
|
667
|
-
} catch {
|
|
668
|
+
} catch (err) {
|
|
669
|
+
if (argLength > 1 && err instanceof NotReadyError)
|
|
670
|
+
return !!loadingValue;
|
|
671
|
+
throw err;
|
|
668
672
|
} finally {
|
|
669
673
|
staleCheck = current;
|
|
670
674
|
}
|
|
671
|
-
return false;
|
|
672
675
|
}
|
|
673
|
-
function latest(fn) {
|
|
676
|
+
function latest(fn, fallback) {
|
|
677
|
+
const argLength = arguments.length;
|
|
674
678
|
const prevFlags = newFlags;
|
|
675
679
|
const prevNotStale = notStale;
|
|
676
680
|
notStale = false;
|
|
677
681
|
try {
|
|
678
682
|
return fn();
|
|
683
|
+
} catch (err) {
|
|
684
|
+
if (argLength > 1 && err instanceof NotReadyError)
|
|
685
|
+
return fallback;
|
|
686
|
+
throw err;
|
|
679
687
|
} finally {
|
|
680
688
|
newFlags = prevFlags;
|
|
681
689
|
notStale = prevNotStale;
|
|
@@ -690,6 +698,46 @@ function catchError(fn) {
|
|
|
690
698
|
return e;
|
|
691
699
|
}
|
|
692
700
|
}
|
|
701
|
+
function runWithObserver(observer, run) {
|
|
702
|
+
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
|
703
|
+
newSources = null;
|
|
704
|
+
newSourcesIndex = observer._sources ? observer._sources.length : 0;
|
|
705
|
+
newFlags = 0;
|
|
706
|
+
try {
|
|
707
|
+
return compute(observer, run, observer);
|
|
708
|
+
} catch (error) {
|
|
709
|
+
if (error instanceof NotReadyError) {
|
|
710
|
+
observer.write(
|
|
711
|
+
UNCHANGED,
|
|
712
|
+
newFlags | LOADING_BIT | observer._stateFlags & UNINITIALIZED_BIT
|
|
713
|
+
);
|
|
714
|
+
} else {
|
|
715
|
+
observer._setError(error);
|
|
716
|
+
}
|
|
717
|
+
} finally {
|
|
718
|
+
if (newSources) {
|
|
719
|
+
if (newSourcesIndex > 0) {
|
|
720
|
+
observer._sources.length = newSourcesIndex + newSources.length;
|
|
721
|
+
for (let i = 0; i < newSources.length; i++) {
|
|
722
|
+
observer._sources[newSourcesIndex + i] = newSources[i];
|
|
723
|
+
}
|
|
724
|
+
} else {
|
|
725
|
+
observer._sources = newSources;
|
|
726
|
+
}
|
|
727
|
+
let source;
|
|
728
|
+
for (let i = newSourcesIndex; i < observer._sources.length; i++) {
|
|
729
|
+
source = observer._sources[i];
|
|
730
|
+
if (!source._observers)
|
|
731
|
+
source._observers = [observer];
|
|
732
|
+
else
|
|
733
|
+
source._observers.push(observer);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
newSources = prevSources;
|
|
737
|
+
newSourcesIndex = prevSourcesIndex;
|
|
738
|
+
newFlags = prevFlags;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
693
741
|
function compute(owner, fn, observer) {
|
|
694
742
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
695
743
|
currentObserver = observer;
|
|
@@ -729,10 +777,8 @@ var Effect = class extends Computation {
|
|
|
729
777
|
if (this._type === EFFECT_RENDER) {
|
|
730
778
|
this._compute = (p) => getClock() > this._queue.created ? latest(() => compute2(p)) : compute2(p);
|
|
731
779
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect();
|
|
735
|
-
}
|
|
780
|
+
this._updateIfNecessary();
|
|
781
|
+
!options?.defer && (this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect());
|
|
736
782
|
if (!this._parent)
|
|
737
783
|
console.warn("Effects created outside a reactive context will never be disposed");
|
|
738
784
|
}
|
|
@@ -977,13 +1023,13 @@ function createEffect(compute2, effect, error, value, options) {
|
|
|
977
1023
|
compute2,
|
|
978
1024
|
effect,
|
|
979
1025
|
error,
|
|
980
|
-
{ name: options?.name ?? "effect" }
|
|
1026
|
+
{ ...options, name: options?.name ?? "effect" }
|
|
981
1027
|
);
|
|
982
1028
|
}
|
|
983
1029
|
function createRenderEffect(compute2, effect, value, options) {
|
|
984
1030
|
void new Effect(value, compute2, effect, void 0, {
|
|
985
1031
|
render: true,
|
|
986
|
-
...{ name: options?.name ?? "effect" }
|
|
1032
|
+
...{ ...options, name: options?.name ?? "effect" }
|
|
987
1033
|
});
|
|
988
1034
|
}
|
|
989
1035
|
function createRoot(init) {
|
|
@@ -991,12 +1037,7 @@ function createRoot(init) {
|
|
|
991
1037
|
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
992
1038
|
}
|
|
993
1039
|
function runWithOwner(owner, run) {
|
|
994
|
-
|
|
995
|
-
return compute(owner, run, null);
|
|
996
|
-
} catch (error) {
|
|
997
|
-
owner?.handleError(error);
|
|
998
|
-
return void 0;
|
|
999
|
-
}
|
|
1040
|
+
return compute(owner, run, null);
|
|
1000
1041
|
}
|
|
1001
1042
|
function createErrorBoundary(fn, fallback) {
|
|
1002
1043
|
const owner = new Owner();
|
|
@@ -1063,19 +1104,6 @@ function resolve(fn) {
|
|
|
1063
1104
|
});
|
|
1064
1105
|
});
|
|
1065
1106
|
}
|
|
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
1107
|
|
|
1080
1108
|
// src/store/projection.ts
|
|
1081
1109
|
function createProjection(fn, initialValue = {}) {
|
|
@@ -1726,4 +1754,4 @@ function compare(key, a, b) {
|
|
|
1726
1754
|
return key ? key(a) === key(b) : true;
|
|
1727
1755
|
}
|
|
1728
1756
|
|
|
1729
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection,
|
|
1757
|
+
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, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
|