@ersbeth/picoflow 0.2.3 → 0.2.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/picoflow.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createSignal, createResource, createMemo, onMount, onCleanup } from 'solid-js';
|
|
2
|
+
|
|
1
3
|
class FlowSignal {
|
|
2
4
|
/**
|
|
3
5
|
* Triggers the FlowSignal.
|
|
@@ -785,724 +787,6 @@ function array(initial) {
|
|
|
785
787
|
return new FlowArray(initial);
|
|
786
788
|
}
|
|
787
789
|
|
|
788
|
-
let FlowSignal$1 = class FlowSignal {
|
|
789
|
-
/**
|
|
790
|
-
* Triggers the FlowSignal.
|
|
791
|
-
* Notifies all registered listeners and schedules execution of associated effects.
|
|
792
|
-
* @throws If the FlowSignal has already been disposed.
|
|
793
|
-
* @public
|
|
794
|
-
*/
|
|
795
|
-
trigger() {
|
|
796
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
797
|
-
this._notify();
|
|
798
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* Disposes the FlowSignal.
|
|
801
|
-
* Cleans up all registered effects, listeners, and dependencies.
|
|
802
|
-
* Once disposed, further usage of the signal will throw an error.
|
|
803
|
-
* @throws If the FlowSignal is already disposed.
|
|
804
|
-
* @public
|
|
805
|
-
*/
|
|
806
|
-
dispose(options) {
|
|
807
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
808
|
-
if (options?.self) {
|
|
809
|
-
Array.from(this._effects).forEach(
|
|
810
|
-
(effect) => effect._unregisterDependency(this)
|
|
811
|
-
);
|
|
812
|
-
Array.from(this._listeners).forEach(
|
|
813
|
-
(listener) => listener._unregisterDependency(this)
|
|
814
|
-
);
|
|
815
|
-
} else {
|
|
816
|
-
Array.from(this._effects).forEach((effect) => effect.dispose());
|
|
817
|
-
Array.from(this._listeners).forEach(
|
|
818
|
-
(listener) => listener.dispose()
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
Array.from(this._dependencies).forEach((dependency) => {
|
|
822
|
-
this._unregisterDependency(dependency);
|
|
823
|
-
});
|
|
824
|
-
this._disposed = true;
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Indicates whether the FlowSignal has been disposed.
|
|
828
|
-
* @remarks Once disposed, the signal should not be used.
|
|
829
|
-
* @public
|
|
830
|
-
*/
|
|
831
|
-
get disposed() {
|
|
832
|
-
return this._disposed;
|
|
833
|
-
}
|
|
834
|
-
/* INTERNAL ------------------------------------------------------------- */
|
|
835
|
-
/*@internal*/
|
|
836
|
-
_disposed = false;
|
|
837
|
-
/*@internal*/
|
|
838
|
-
_dependencies = /* @__PURE__ */ new Set();
|
|
839
|
-
/*@internal*/
|
|
840
|
-
_listeners = /* @__PURE__ */ new Set();
|
|
841
|
-
/*@internal*/
|
|
842
|
-
_effects = /* @__PURE__ */ new Set();
|
|
843
|
-
/*@internal*/
|
|
844
|
-
_watch() {
|
|
845
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
846
|
-
}
|
|
847
|
-
/*@internal*/
|
|
848
|
-
_notify() {
|
|
849
|
-
this._listeners.forEach((listener) => listener._notify());
|
|
850
|
-
this._effects.forEach((effect) => effect._exec());
|
|
851
|
-
}
|
|
852
|
-
/*@internal*/
|
|
853
|
-
_watchFrom(listener) {
|
|
854
|
-
listener._registerDependency(this);
|
|
855
|
-
this._watch();
|
|
856
|
-
}
|
|
857
|
-
/*@internal*/
|
|
858
|
-
_registerDependency(dependency) {
|
|
859
|
-
this._dependencies.add(dependency);
|
|
860
|
-
dependency._registerListener(this);
|
|
861
|
-
}
|
|
862
|
-
/*@internal*/
|
|
863
|
-
_unregisterDependency(dependency) {
|
|
864
|
-
this._dependencies.delete(dependency);
|
|
865
|
-
dependency._unregisterListener(this);
|
|
866
|
-
}
|
|
867
|
-
/*@internal*/
|
|
868
|
-
_registerListener(signal) {
|
|
869
|
-
this._listeners.add(signal);
|
|
870
|
-
}
|
|
871
|
-
/*@internal*/
|
|
872
|
-
_unregisterListener(signal) {
|
|
873
|
-
this._listeners.delete(signal);
|
|
874
|
-
}
|
|
875
|
-
/*@internal*/
|
|
876
|
-
_registerEffect(effect) {
|
|
877
|
-
this._effects.add(effect);
|
|
878
|
-
}
|
|
879
|
-
/*@internal*/
|
|
880
|
-
_unregisterEffect(effect) {
|
|
881
|
-
this._effects.delete(effect);
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
|
|
885
|
-
let FlowEffect$1 = class FlowEffect {
|
|
886
|
-
/**
|
|
887
|
-
* Creates a new FlowEffect.
|
|
888
|
-
*
|
|
889
|
-
* @param apply - A side-effect function that receives a getter and a watcher to
|
|
890
|
-
* access and register dependencies on reactive observables and signals.
|
|
891
|
-
*
|
|
892
|
-
* @remarks
|
|
893
|
-
* The provided function is executed immediately in a tracked mode to collect dependencies.
|
|
894
|
-
* On subsequent executions, it runs in an untracked mode.
|
|
895
|
-
*
|
|
896
|
-
* @public
|
|
897
|
-
*/
|
|
898
|
-
constructor(apply) {
|
|
899
|
-
this._trackedExec = () => apply(this._trackedGet, this._trackedWatch);
|
|
900
|
-
this._untrackedExec = () => apply(this._untrackedGet, this._untrackedWatch);
|
|
901
|
-
this._exec();
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Disposes the effect, unregistering all its tracked dependencies.
|
|
905
|
-
*
|
|
906
|
-
* @remarks
|
|
907
|
-
* Once disposed, the effect must no longer be used. Trying to dispose an effect
|
|
908
|
-
* that is already disposed will throw an error.
|
|
909
|
-
*
|
|
910
|
-
* @public
|
|
911
|
-
*/
|
|
912
|
-
dispose() {
|
|
913
|
-
if (this._disposed) throw new Error("[PicoFlow] Effect is disposed");
|
|
914
|
-
Array.from(this._dependencies).forEach((dependency) => {
|
|
915
|
-
this._unregisterDependency(dependency);
|
|
916
|
-
});
|
|
917
|
-
this._disposed = true;
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Indicates whether this effect has been disposed.
|
|
921
|
-
*
|
|
922
|
-
* @returns A boolean value that is true if the effect is disposed, false otherwise.
|
|
923
|
-
*
|
|
924
|
-
* @public
|
|
925
|
-
*/
|
|
926
|
-
get disposed() {
|
|
927
|
-
return this._disposed;
|
|
928
|
-
}
|
|
929
|
-
/* INTERNAL ------------------------------------------------------------ */
|
|
930
|
-
_disposed = false;
|
|
931
|
-
_initialized = false;
|
|
932
|
-
_dependencies = /* @__PURE__ */ new Set();
|
|
933
|
-
_trackedGet = (observable) => observable._getFrom(this);
|
|
934
|
-
_trackedWatch = (signal) => signal._watchFrom(this);
|
|
935
|
-
_untrackedGet = (observable) => observable.get();
|
|
936
|
-
_untrackedWatch = (signal) => signal._watch();
|
|
937
|
-
_trackedExec;
|
|
938
|
-
_untrackedExec;
|
|
939
|
-
/*@internal*/
|
|
940
|
-
_exec() {
|
|
941
|
-
if (this._disposed)
|
|
942
|
-
throw new Error("[PicoFlow] Effect is disposed");
|
|
943
|
-
if (this._initialized) this._untrackedExec();
|
|
944
|
-
else {
|
|
945
|
-
this._trackedExec();
|
|
946
|
-
this._initialized = true;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
/*@internal*/
|
|
950
|
-
_registerDependency(dependency) {
|
|
951
|
-
this._dependencies.add(dependency);
|
|
952
|
-
dependency._registerEffect(this);
|
|
953
|
-
}
|
|
954
|
-
/*@internal*/
|
|
955
|
-
_unregisterDependency(dependency) {
|
|
956
|
-
this._dependencies.delete(dependency);
|
|
957
|
-
dependency._unregisterEffect(this);
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
let FlowObservable$1 = class FlowObservable extends FlowSignal$1 {
|
|
962
|
-
/* INTERNAL -------------------------------------------*/
|
|
963
|
-
/*@internal*/
|
|
964
|
-
_value;
|
|
965
|
-
/*@internal*/
|
|
966
|
-
_getFrom(listener) {
|
|
967
|
-
listener._registerDependency(this);
|
|
968
|
-
return this.get();
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Subscribes a listener function to changes of the observable.
|
|
972
|
-
* The listener is executed immediately with the current value and on subsequent updates.
|
|
973
|
-
* @param listener - A callback function that receives the new value.
|
|
974
|
-
* @returns A disposer function to cancel the subscription.
|
|
975
|
-
*/
|
|
976
|
-
subscribe(listener) {
|
|
977
|
-
const effect = new FlowEffect$1((get) => {
|
|
978
|
-
listener(get(this));
|
|
979
|
-
});
|
|
980
|
-
return () => effect.dispose();
|
|
981
|
-
}
|
|
982
|
-
};
|
|
983
|
-
|
|
984
|
-
let FlowDerivation$1 = class FlowDerivation extends FlowObservable$1 {
|
|
985
|
-
/**
|
|
986
|
-
* Creates a new FlowDerivation.
|
|
987
|
-
* @param compute - A function that computes the derived value. It is provided with two parameters:
|
|
988
|
-
* a getter and a watcher that respect dependency tracking.
|
|
989
|
-
* @public
|
|
990
|
-
*/
|
|
991
|
-
constructor(compute) {
|
|
992
|
-
super();
|
|
993
|
-
this._initEager(compute);
|
|
994
|
-
}
|
|
995
|
-
/**
|
|
996
|
-
* Gets the current derived value.
|
|
997
|
-
* @returns The current computed value.
|
|
998
|
-
* @remarks
|
|
999
|
-
* This method lazily initializes and updates the derivation if it is marked as dirty. It throws an error
|
|
1000
|
-
* if the derivation has been disposed.
|
|
1001
|
-
* @public
|
|
1002
|
-
*/
|
|
1003
|
-
get() {
|
|
1004
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
1005
|
-
this._initLazy();
|
|
1006
|
-
this._compute();
|
|
1007
|
-
return this._value;
|
|
1008
|
-
}
|
|
1009
|
-
/* INTERNAL --------------------------------------------------------- */
|
|
1010
|
-
_initialized = false;
|
|
1011
|
-
_dirty = false;
|
|
1012
|
-
_trackedGet = (observable) => observable._getFrom(this);
|
|
1013
|
-
_trackedWatch = (signal) => signal._watchFrom(this);
|
|
1014
|
-
_untrackedGet = (observable) => observable.get();
|
|
1015
|
-
_untrackedWatch = (signal) => signal._watch();
|
|
1016
|
-
_trackedCompute;
|
|
1017
|
-
_untrackedCompute;
|
|
1018
|
-
_initEager(compute) {
|
|
1019
|
-
this._trackedCompute = () => compute(this._trackedGet, this._trackedWatch);
|
|
1020
|
-
this._untrackedCompute = () => compute(this._untrackedGet, this._untrackedWatch);
|
|
1021
|
-
}
|
|
1022
|
-
_initLazy() {
|
|
1023
|
-
if (!this._initialized) {
|
|
1024
|
-
this._value = this._trackedCompute();
|
|
1025
|
-
this._initialized = true;
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
/* @internal */
|
|
1029
|
-
_compute() {
|
|
1030
|
-
if (this._dirty) {
|
|
1031
|
-
const dependencies = [...this._dependencies];
|
|
1032
|
-
this._dependencies.clear();
|
|
1033
|
-
this._value = this._trackedCompute();
|
|
1034
|
-
const dependenciesToRemove = dependencies.filter(
|
|
1035
|
-
(dependency) => !this._dependencies.has(dependency)
|
|
1036
|
-
);
|
|
1037
|
-
dependenciesToRemove.forEach(
|
|
1038
|
-
(dependency) => dependency._unregisterDependency(this)
|
|
1039
|
-
);
|
|
1040
|
-
this._dirty = false;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
/* @internal */
|
|
1044
|
-
_notify() {
|
|
1045
|
-
this._dirty = true;
|
|
1046
|
-
super._notify();
|
|
1047
|
-
}
|
|
1048
|
-
/* @internal */
|
|
1049
|
-
_watch() {
|
|
1050
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
1051
|
-
this._initLazy();
|
|
1052
|
-
this._compute();
|
|
1053
|
-
}
|
|
1054
|
-
};
|
|
1055
|
-
|
|
1056
|
-
const IS_DEV = false;
|
|
1057
|
-
const equalFn = (a, b) => a === b;
|
|
1058
|
-
const signalOptions = {
|
|
1059
|
-
equals: equalFn
|
|
1060
|
-
};
|
|
1061
|
-
let runEffects = runQueue;
|
|
1062
|
-
const STALE = 1;
|
|
1063
|
-
const PENDING = 2;
|
|
1064
|
-
const UNOWNED = {
|
|
1065
|
-
};
|
|
1066
|
-
const NO_INIT = {};
|
|
1067
|
-
var Owner = null;
|
|
1068
|
-
let Transition = null;
|
|
1069
|
-
let ExternalSourceConfig = null;
|
|
1070
|
-
let Listener = null;
|
|
1071
|
-
let Updates = null;
|
|
1072
|
-
let Effects = null;
|
|
1073
|
-
let ExecCount = 0;
|
|
1074
|
-
function createSignal(value, options) {
|
|
1075
|
-
options = options ? Object.assign({}, signalOptions, options) : signalOptions;
|
|
1076
|
-
const s = {
|
|
1077
|
-
value,
|
|
1078
|
-
observers: null,
|
|
1079
|
-
observerSlots: null,
|
|
1080
|
-
comparator: options.equals || undefined
|
|
1081
|
-
};
|
|
1082
|
-
const setter = value => {
|
|
1083
|
-
if (typeof value === "function") {
|
|
1084
|
-
value = value(s.value);
|
|
1085
|
-
}
|
|
1086
|
-
return writeSignal(s, value);
|
|
1087
|
-
};
|
|
1088
|
-
return [readSignal.bind(s), setter];
|
|
1089
|
-
}
|
|
1090
|
-
function createComputed(fn, value, options) {
|
|
1091
|
-
const c = createComputation(fn, value, true, STALE);
|
|
1092
|
-
updateComputation(c);
|
|
1093
|
-
}
|
|
1094
|
-
function createEffect(fn, value, options) {
|
|
1095
|
-
runEffects = runUserEffects;
|
|
1096
|
-
const c = createComputation(fn, value, false, STALE);
|
|
1097
|
-
c.user = true;
|
|
1098
|
-
Effects ? Effects.push(c) : updateComputation(c);
|
|
1099
|
-
}
|
|
1100
|
-
function createMemo(fn, value, options) {
|
|
1101
|
-
options = options ? Object.assign({}, signalOptions, options) : signalOptions;
|
|
1102
|
-
const c = createComputation(fn, value, true, 0);
|
|
1103
|
-
c.observers = null;
|
|
1104
|
-
c.observerSlots = null;
|
|
1105
|
-
c.comparator = options.equals || undefined;
|
|
1106
|
-
updateComputation(c);
|
|
1107
|
-
return readSignal.bind(c);
|
|
1108
|
-
}
|
|
1109
|
-
function isPromise(v) {
|
|
1110
|
-
return v && typeof v === "object" && "then" in v;
|
|
1111
|
-
}
|
|
1112
|
-
function createResource(pSource, pFetcher, pOptions) {
|
|
1113
|
-
let source;
|
|
1114
|
-
let fetcher;
|
|
1115
|
-
let options;
|
|
1116
|
-
{
|
|
1117
|
-
source = true;
|
|
1118
|
-
fetcher = pSource;
|
|
1119
|
-
options = {};
|
|
1120
|
-
}
|
|
1121
|
-
let pr = null,
|
|
1122
|
-
initP = NO_INIT,
|
|
1123
|
-
scheduled = false,
|
|
1124
|
-
resolved = "initialValue" in options,
|
|
1125
|
-
dynamic = typeof source === "function" && createMemo(source);
|
|
1126
|
-
const contexts = new Set(),
|
|
1127
|
-
[value, setValue] = (options.storage || createSignal)(options.initialValue),
|
|
1128
|
-
[error, setError] = createSignal(undefined),
|
|
1129
|
-
[track, trigger] = createSignal(undefined, {
|
|
1130
|
-
equals: false
|
|
1131
|
-
}),
|
|
1132
|
-
[state, setState] = createSignal(resolved ? "ready" : "unresolved");
|
|
1133
|
-
function loadEnd(p, v, error, key) {
|
|
1134
|
-
if (pr === p) {
|
|
1135
|
-
pr = null;
|
|
1136
|
-
key !== undefined && (resolved = true);
|
|
1137
|
-
if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
|
|
1138
|
-
value: v
|
|
1139
|
-
}));
|
|
1140
|
-
initP = NO_INIT;
|
|
1141
|
-
completeLoad(v, error);
|
|
1142
|
-
}
|
|
1143
|
-
return v;
|
|
1144
|
-
}
|
|
1145
|
-
function completeLoad(v, err) {
|
|
1146
|
-
runUpdates(() => {
|
|
1147
|
-
if (err === undefined) setValue(() => v);
|
|
1148
|
-
setState(err !== undefined ? "errored" : resolved ? "ready" : "unresolved");
|
|
1149
|
-
setError(err);
|
|
1150
|
-
for (const c of contexts.keys()) c.decrement();
|
|
1151
|
-
contexts.clear();
|
|
1152
|
-
}, false);
|
|
1153
|
-
}
|
|
1154
|
-
function read() {
|
|
1155
|
-
const c = SuspenseContext,
|
|
1156
|
-
v = value(),
|
|
1157
|
-
err = error();
|
|
1158
|
-
if (err !== undefined && !pr) throw err;
|
|
1159
|
-
if (Listener && !Listener.user && c) {
|
|
1160
|
-
createComputed(() => {
|
|
1161
|
-
track();
|
|
1162
|
-
if (pr) {
|
|
1163
|
-
if (c.resolved && Transition) ;else if (!contexts.has(c)) {
|
|
1164
|
-
c.increment();
|
|
1165
|
-
contexts.add(c);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
return v;
|
|
1171
|
-
}
|
|
1172
|
-
function load(refetching = true) {
|
|
1173
|
-
if (refetching !== false && scheduled) return;
|
|
1174
|
-
scheduled = false;
|
|
1175
|
-
const lookup = dynamic ? dynamic() : source;
|
|
1176
|
-
if (lookup == null || lookup === false) {
|
|
1177
|
-
loadEnd(pr, untrack(value));
|
|
1178
|
-
return;
|
|
1179
|
-
}
|
|
1180
|
-
let error;
|
|
1181
|
-
const p = initP !== NO_INIT ? initP : untrack(() => {
|
|
1182
|
-
try {
|
|
1183
|
-
return fetcher(lookup, {
|
|
1184
|
-
value: value(),
|
|
1185
|
-
refetching
|
|
1186
|
-
});
|
|
1187
|
-
} catch (fetcherError) {
|
|
1188
|
-
error = fetcherError;
|
|
1189
|
-
}
|
|
1190
|
-
});
|
|
1191
|
-
if (error !== undefined) {
|
|
1192
|
-
loadEnd(pr, undefined, castError(error), lookup);
|
|
1193
|
-
return;
|
|
1194
|
-
} else if (!isPromise(p)) {
|
|
1195
|
-
loadEnd(pr, p, undefined, lookup);
|
|
1196
|
-
return p;
|
|
1197
|
-
}
|
|
1198
|
-
pr = p;
|
|
1199
|
-
if ("v" in p) {
|
|
1200
|
-
if (p.s === 1) loadEnd(pr, p.v, undefined, lookup);else loadEnd(pr, undefined, castError(p.v), lookup);
|
|
1201
|
-
return p;
|
|
1202
|
-
}
|
|
1203
|
-
scheduled = true;
|
|
1204
|
-
queueMicrotask(() => scheduled = false);
|
|
1205
|
-
runUpdates(() => {
|
|
1206
|
-
setState(resolved ? "refreshing" : "pending");
|
|
1207
|
-
trigger();
|
|
1208
|
-
}, false);
|
|
1209
|
-
return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, undefined, castError(e), lookup));
|
|
1210
|
-
}
|
|
1211
|
-
Object.defineProperties(read, {
|
|
1212
|
-
state: {
|
|
1213
|
-
get: () => state()
|
|
1214
|
-
},
|
|
1215
|
-
error: {
|
|
1216
|
-
get: () => error()
|
|
1217
|
-
},
|
|
1218
|
-
loading: {
|
|
1219
|
-
get() {
|
|
1220
|
-
const s = state();
|
|
1221
|
-
return s === "pending" || s === "refreshing";
|
|
1222
|
-
}
|
|
1223
|
-
},
|
|
1224
|
-
latest: {
|
|
1225
|
-
get() {
|
|
1226
|
-
if (!resolved) return read();
|
|
1227
|
-
const err = error();
|
|
1228
|
-
if (err && !pr) throw err;
|
|
1229
|
-
return value();
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
});
|
|
1233
|
-
let owner = Owner;
|
|
1234
|
-
if (dynamic) createComputed(() => (owner = Owner, load(false)));else load(false);
|
|
1235
|
-
return [read, {
|
|
1236
|
-
refetch: info => runWithOwner(owner, () => load(info)),
|
|
1237
|
-
mutate: setValue
|
|
1238
|
-
}];
|
|
1239
|
-
}
|
|
1240
|
-
function untrack(fn) {
|
|
1241
|
-
if (Listener === null) return fn();
|
|
1242
|
-
const listener = Listener;
|
|
1243
|
-
Listener = null;
|
|
1244
|
-
try {
|
|
1245
|
-
if (ExternalSourceConfig) ;
|
|
1246
|
-
return fn();
|
|
1247
|
-
} finally {
|
|
1248
|
-
Listener = listener;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
function onMount(fn) {
|
|
1252
|
-
createEffect(() => untrack(fn));
|
|
1253
|
-
}
|
|
1254
|
-
function onCleanup(fn) {
|
|
1255
|
-
if (Owner === null) ;else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
|
|
1256
|
-
return fn;
|
|
1257
|
-
}
|
|
1258
|
-
function runWithOwner(o, fn) {
|
|
1259
|
-
const prev = Owner;
|
|
1260
|
-
const prevListener = Listener;
|
|
1261
|
-
Owner = o;
|
|
1262
|
-
Listener = null;
|
|
1263
|
-
try {
|
|
1264
|
-
return runUpdates(fn, true);
|
|
1265
|
-
} catch (err) {
|
|
1266
|
-
handleError(err);
|
|
1267
|
-
} finally {
|
|
1268
|
-
Owner = prev;
|
|
1269
|
-
Listener = prevListener;
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
|
|
1273
|
-
let SuspenseContext;
|
|
1274
|
-
function readSignal() {
|
|
1275
|
-
if (this.sources && (this.state)) {
|
|
1276
|
-
if ((this.state) === STALE) updateComputation(this);else {
|
|
1277
|
-
const updates = Updates;
|
|
1278
|
-
Updates = null;
|
|
1279
|
-
runUpdates(() => lookUpstream(this), false);
|
|
1280
|
-
Updates = updates;
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
if (Listener) {
|
|
1284
|
-
const sSlot = this.observers ? this.observers.length : 0;
|
|
1285
|
-
if (!Listener.sources) {
|
|
1286
|
-
Listener.sources = [this];
|
|
1287
|
-
Listener.sourceSlots = [sSlot];
|
|
1288
|
-
} else {
|
|
1289
|
-
Listener.sources.push(this);
|
|
1290
|
-
Listener.sourceSlots.push(sSlot);
|
|
1291
|
-
}
|
|
1292
|
-
if (!this.observers) {
|
|
1293
|
-
this.observers = [Listener];
|
|
1294
|
-
this.observerSlots = [Listener.sources.length - 1];
|
|
1295
|
-
} else {
|
|
1296
|
-
this.observers.push(Listener);
|
|
1297
|
-
this.observerSlots.push(Listener.sources.length - 1);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
return this.value;
|
|
1301
|
-
}
|
|
1302
|
-
function writeSignal(node, value, isComp) {
|
|
1303
|
-
let current = node.value;
|
|
1304
|
-
if (!node.comparator || !node.comparator(current, value)) {
|
|
1305
|
-
node.value = value;
|
|
1306
|
-
if (node.observers && node.observers.length) {
|
|
1307
|
-
runUpdates(() => {
|
|
1308
|
-
for (let i = 0; i < node.observers.length; i += 1) {
|
|
1309
|
-
const o = node.observers[i];
|
|
1310
|
-
const TransitionRunning = Transition && Transition.running;
|
|
1311
|
-
if (TransitionRunning && Transition.disposed.has(o)) ;
|
|
1312
|
-
if (TransitionRunning ? !o.tState : !o.state) {
|
|
1313
|
-
if (o.pure) Updates.push(o);else Effects.push(o);
|
|
1314
|
-
if (o.observers) markDownstream(o);
|
|
1315
|
-
}
|
|
1316
|
-
if (!TransitionRunning) o.state = STALE;
|
|
1317
|
-
}
|
|
1318
|
-
if (Updates.length > 10e5) {
|
|
1319
|
-
Updates = [];
|
|
1320
|
-
if (IS_DEV) ;
|
|
1321
|
-
throw new Error();
|
|
1322
|
-
}
|
|
1323
|
-
}, false);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
return value;
|
|
1327
|
-
}
|
|
1328
|
-
function updateComputation(node) {
|
|
1329
|
-
if (!node.fn) return;
|
|
1330
|
-
cleanNode(node);
|
|
1331
|
-
const time = ExecCount;
|
|
1332
|
-
runComputation(node, node.value, time);
|
|
1333
|
-
}
|
|
1334
|
-
function runComputation(node, value, time) {
|
|
1335
|
-
let nextValue;
|
|
1336
|
-
const owner = Owner,
|
|
1337
|
-
listener = Listener;
|
|
1338
|
-
Listener = Owner = node;
|
|
1339
|
-
try {
|
|
1340
|
-
nextValue = node.fn(value);
|
|
1341
|
-
} catch (err) {
|
|
1342
|
-
if (node.pure) {
|
|
1343
|
-
{
|
|
1344
|
-
node.state = STALE;
|
|
1345
|
-
node.owned && node.owned.forEach(cleanNode);
|
|
1346
|
-
node.owned = null;
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
node.updatedAt = time + 1;
|
|
1350
|
-
return handleError(err);
|
|
1351
|
-
} finally {
|
|
1352
|
-
Listener = listener;
|
|
1353
|
-
Owner = owner;
|
|
1354
|
-
}
|
|
1355
|
-
if (!node.updatedAt || node.updatedAt <= time) {
|
|
1356
|
-
if (node.updatedAt != null && "observers" in node) {
|
|
1357
|
-
writeSignal(node, nextValue);
|
|
1358
|
-
} else node.value = nextValue;
|
|
1359
|
-
node.updatedAt = time;
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
function createComputation(fn, init, pure, state = STALE, options) {
|
|
1363
|
-
const c = {
|
|
1364
|
-
fn,
|
|
1365
|
-
state: state,
|
|
1366
|
-
updatedAt: null,
|
|
1367
|
-
owned: null,
|
|
1368
|
-
sources: null,
|
|
1369
|
-
sourceSlots: null,
|
|
1370
|
-
cleanups: null,
|
|
1371
|
-
value: init,
|
|
1372
|
-
owner: Owner,
|
|
1373
|
-
context: Owner ? Owner.context : null,
|
|
1374
|
-
pure
|
|
1375
|
-
};
|
|
1376
|
-
if (Owner === null) ;else if (Owner !== UNOWNED) {
|
|
1377
|
-
{
|
|
1378
|
-
if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
return c;
|
|
1382
|
-
}
|
|
1383
|
-
function runTop(node) {
|
|
1384
|
-
if ((node.state) === 0) return;
|
|
1385
|
-
if ((node.state) === PENDING) return lookUpstream(node);
|
|
1386
|
-
if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
|
|
1387
|
-
const ancestors = [node];
|
|
1388
|
-
while ((node = node.owner) && (!node.updatedAt || node.updatedAt < ExecCount)) {
|
|
1389
|
-
if (node.state) ancestors.push(node);
|
|
1390
|
-
}
|
|
1391
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1392
|
-
node = ancestors[i];
|
|
1393
|
-
if ((node.state) === STALE) {
|
|
1394
|
-
updateComputation(node);
|
|
1395
|
-
} else if ((node.state) === PENDING) {
|
|
1396
|
-
const updates = Updates;
|
|
1397
|
-
Updates = null;
|
|
1398
|
-
runUpdates(() => lookUpstream(node, ancestors[0]), false);
|
|
1399
|
-
Updates = updates;
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
function runUpdates(fn, init) {
|
|
1404
|
-
if (Updates) return fn();
|
|
1405
|
-
let wait = false;
|
|
1406
|
-
if (!init) Updates = [];
|
|
1407
|
-
if (Effects) wait = true;else Effects = [];
|
|
1408
|
-
ExecCount++;
|
|
1409
|
-
try {
|
|
1410
|
-
const res = fn();
|
|
1411
|
-
completeUpdates(wait);
|
|
1412
|
-
return res;
|
|
1413
|
-
} catch (err) {
|
|
1414
|
-
if (!wait) Effects = null;
|
|
1415
|
-
Updates = null;
|
|
1416
|
-
handleError(err);
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
function completeUpdates(wait) {
|
|
1420
|
-
if (Updates) {
|
|
1421
|
-
runQueue(Updates);
|
|
1422
|
-
Updates = null;
|
|
1423
|
-
}
|
|
1424
|
-
if (wait) return;
|
|
1425
|
-
const e = Effects;
|
|
1426
|
-
Effects = null;
|
|
1427
|
-
if (e.length) runUpdates(() => runEffects(e), false);
|
|
1428
|
-
}
|
|
1429
|
-
function runQueue(queue) {
|
|
1430
|
-
for (let i = 0; i < queue.length; i++) runTop(queue[i]);
|
|
1431
|
-
}
|
|
1432
|
-
function runUserEffects(queue) {
|
|
1433
|
-
let i,
|
|
1434
|
-
userLength = 0;
|
|
1435
|
-
for (i = 0; i < queue.length; i++) {
|
|
1436
|
-
const e = queue[i];
|
|
1437
|
-
if (!e.user) runTop(e);else queue[userLength++] = e;
|
|
1438
|
-
}
|
|
1439
|
-
for (i = 0; i < userLength; i++) runTop(queue[i]);
|
|
1440
|
-
}
|
|
1441
|
-
function lookUpstream(node, ignore) {
|
|
1442
|
-
node.state = 0;
|
|
1443
|
-
for (let i = 0; i < node.sources.length; i += 1) {
|
|
1444
|
-
const source = node.sources[i];
|
|
1445
|
-
if (source.sources) {
|
|
1446
|
-
const state = source.state;
|
|
1447
|
-
if (state === STALE) {
|
|
1448
|
-
if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) runTop(source);
|
|
1449
|
-
} else if (state === PENDING) lookUpstream(source, ignore);
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
function markDownstream(node) {
|
|
1454
|
-
for (let i = 0; i < node.observers.length; i += 1) {
|
|
1455
|
-
const o = node.observers[i];
|
|
1456
|
-
if (!o.state) {
|
|
1457
|
-
o.state = PENDING;
|
|
1458
|
-
if (o.pure) Updates.push(o);else Effects.push(o);
|
|
1459
|
-
o.observers && markDownstream(o);
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
function cleanNode(node) {
|
|
1464
|
-
let i;
|
|
1465
|
-
if (node.sources) {
|
|
1466
|
-
while (node.sources.length) {
|
|
1467
|
-
const source = node.sources.pop(),
|
|
1468
|
-
index = node.sourceSlots.pop(),
|
|
1469
|
-
obs = source.observers;
|
|
1470
|
-
if (obs && obs.length) {
|
|
1471
|
-
const n = obs.pop(),
|
|
1472
|
-
s = source.observerSlots.pop();
|
|
1473
|
-
if (index < obs.length) {
|
|
1474
|
-
n.sourceSlots[s] = index;
|
|
1475
|
-
obs[index] = n;
|
|
1476
|
-
source.observerSlots[index] = s;
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
if (node.tOwned) {
|
|
1482
|
-
for (i = node.tOwned.length - 1; i >= 0; i--) cleanNode(node.tOwned[i]);
|
|
1483
|
-
delete node.tOwned;
|
|
1484
|
-
}
|
|
1485
|
-
if (node.owned) {
|
|
1486
|
-
for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
|
|
1487
|
-
node.owned = null;
|
|
1488
|
-
}
|
|
1489
|
-
if (node.cleanups) {
|
|
1490
|
-
for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
|
|
1491
|
-
node.cleanups = null;
|
|
1492
|
-
}
|
|
1493
|
-
node.state = 0;
|
|
1494
|
-
}
|
|
1495
|
-
function castError(err) {
|
|
1496
|
-
if (err instanceof Error) return err;
|
|
1497
|
-
return new Error(typeof err === "string" ? err : "Unknown error", {
|
|
1498
|
-
cause: err
|
|
1499
|
-
});
|
|
1500
|
-
}
|
|
1501
|
-
function handleError(err, owner = Owner) {
|
|
1502
|
-
const error = castError(err);
|
|
1503
|
-
throw error;
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
790
|
class SolidState {
|
|
1507
791
|
/**
|
|
1508
792
|
* Returns the current value.
|
|
@@ -1570,7 +854,7 @@ function fromSync(state) {
|
|
|
1570
854
|
const solidState = new SolidState(state.get());
|
|
1571
855
|
let fx;
|
|
1572
856
|
onMount(() => {
|
|
1573
|
-
fx = new FlowEffect
|
|
857
|
+
fx = new FlowEffect((get) => {
|
|
1574
858
|
const value = get(state);
|
|
1575
859
|
solidState.set(() => value);
|
|
1576
860
|
});
|
|
@@ -1585,7 +869,7 @@ function fromAsync(derivation) {
|
|
|
1585
869
|
});
|
|
1586
870
|
let fx;
|
|
1587
871
|
onMount(() => {
|
|
1588
|
-
fx = new FlowEffect
|
|
872
|
+
fx = new FlowEffect(async (get) => {
|
|
1589
873
|
await get(derivation);
|
|
1590
874
|
solidResource.refetch();
|
|
1591
875
|
});
|
|
@@ -1602,7 +886,7 @@ function shallowFrom(flow) {
|
|
|
1602
886
|
return fromSync(flow);
|
|
1603
887
|
}
|
|
1604
888
|
function deepFrom(getter) {
|
|
1605
|
-
const derivation = new FlowDerivation
|
|
889
|
+
const derivation = new FlowDerivation((get) => {
|
|
1606
890
|
return getter(get);
|
|
1607
891
|
});
|
|
1608
892
|
const initialValue = derivation.get();
|
|
@@ -1613,7 +897,7 @@ function deepFrom(getter) {
|
|
|
1613
897
|
return fromSync(derivation);
|
|
1614
898
|
}
|
|
1615
899
|
function from(flow) {
|
|
1616
|
-
if (flow instanceof FlowObservable
|
|
900
|
+
if (flow instanceof FlowObservable) {
|
|
1617
901
|
return shallowFrom(flow);
|
|
1618
902
|
}
|
|
1619
903
|
return deepFrom(flow);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FlowObservable, FlowGetter } from '@ersbeth/picoflow';
|
|
2
1
|
import { SolidResource, SolidDerivation } from './primitives';
|
|
2
|
+
import { FlowObservable, FlowGetter } from '../basic';
|
|
3
3
|
/**
|
|
4
4
|
* Utility type that excludes Promise types from T.
|
|
5
5
|
* Used to ensure type safety for synchronous derivations/resources.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAc,cAAc,EAAE,KAAK,UAAU,EAAkB,MAAM,UAAU,CAAC;AAsEvF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAEnE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACpG;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAClB,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAC7E,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClG;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACzG;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAClB,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAC3F,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/solid/converters.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FlowDerivation, FlowEffect, FlowObservable, type FlowGetter } from '@ersbeth/picoflow';
|
|
2
1
|
import { onCleanup, onMount } from 'solid-js';
|
|
3
2
|
import { SolidResource, SolidState, type SolidDerivation } from './primitives';
|
|
3
|
+
import { FlowEffect, FlowObservable, type FlowGetter, FlowDerivation } from '../basic';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
function fromSync<T>(state: FlowObservable<T>): SolidDerivation<T> {
|