@effect-rx/rx-react 0.38.0 → 0.38.2
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/Hooks/package.json +6 -0
- package/ReactHydration/package.json +6 -0
- package/RegistryContext/package.json +6 -0
- package/dist/cjs/Hooks.js +254 -0
- package/dist/cjs/Hooks.js.map +1 -0
- package/dist/cjs/ReactHydration.js +50 -0
- package/dist/cjs/ReactHydration.js.map +1 -0
- package/dist/cjs/RegistryContext.js +73 -0
- package/dist/cjs/RegistryContext.js.map +1 -0
- package/dist/cjs/index.js +40 -293
- package/dist/cjs/index.js.map +1 -1
- package/dist/dts/Hooks.d.ts +79 -0
- package/dist/dts/Hooks.d.ts.map +1 -0
- package/dist/dts/ReactHydration.d.ts +11 -0
- package/dist/dts/ReactHydration.d.ts.map +1 -0
- package/dist/dts/RegistryContext.d.ts +25 -0
- package/dist/dts/RegistryContext.d.ts.map +1 -0
- package/dist/dts/index.d.ts +12 -98
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/Hooks.js +215 -0
- package/dist/esm/Hooks.js.map +1 -0
- package/dist/esm/ReactHydration.js +23 -0
- package/dist/esm/ReactHydration.js.map +1 -0
- package/dist/esm/RegistryContext.js +45 -0
- package/dist/esm/RegistryContext.js.map +1 -0
- package/dist/esm/index.js +12 -243
- package/dist/esm/index.js.map +1 -1
- package/package.json +30 -2
- package/src/Hooks.ts +285 -0
- package/src/ReactHydration.ts +22 -0
- package/src/RegistryContext.ts +54 -0
- package/src/index.ts +12 -319
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
"use client";
|
|
5
|
+
|
|
6
|
+
import * as Result from "@effect-rx/rx/Result";
|
|
7
|
+
import * as Rx from "@effect-rx/rx/Rx";
|
|
8
|
+
import * as Cause from "effect/Cause";
|
|
9
|
+
import { globalValue } from "effect/GlobalValue";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { RegistryContext } from "./RegistryContext.js";
|
|
12
|
+
const storeRegistry = /*#__PURE__*/globalValue("@effect-rx/rx-react/storeRegistry", () => new WeakMap());
|
|
13
|
+
function makeStore(registry, rx) {
|
|
14
|
+
let stores = storeRegistry.get(registry);
|
|
15
|
+
if (stores === undefined) {
|
|
16
|
+
stores = new WeakMap();
|
|
17
|
+
storeRegistry.set(registry, stores);
|
|
18
|
+
}
|
|
19
|
+
const store = stores.get(rx);
|
|
20
|
+
if (store !== undefined) {
|
|
21
|
+
return store;
|
|
22
|
+
}
|
|
23
|
+
const newStore = {
|
|
24
|
+
subscribe(f) {
|
|
25
|
+
return registry.subscribe(rx, f);
|
|
26
|
+
},
|
|
27
|
+
snapshot() {
|
|
28
|
+
return registry.get(rx);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
stores.set(rx, newStore);
|
|
32
|
+
return newStore;
|
|
33
|
+
}
|
|
34
|
+
function useStore(registry, rx) {
|
|
35
|
+
const store = makeStore(registry, rx);
|
|
36
|
+
return React.useSyncExternalStore(store.subscribe, store.snapshot, store.snapshot);
|
|
37
|
+
}
|
|
38
|
+
const initialValuesSet = /*#__PURE__*/globalValue("@effect-rx/rx-react/initialValuesSet", () => new WeakMap());
|
|
39
|
+
/**
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
* @category hooks
|
|
42
|
+
*/
|
|
43
|
+
export const useRxInitialValues = initialValues => {
|
|
44
|
+
const registry = React.useContext(RegistryContext);
|
|
45
|
+
let set = initialValuesSet.get(registry);
|
|
46
|
+
if (set === undefined) {
|
|
47
|
+
set = new WeakSet();
|
|
48
|
+
initialValuesSet.set(registry, set);
|
|
49
|
+
}
|
|
50
|
+
for (const [rx, value] of initialValues) {
|
|
51
|
+
if (!set.has(rx)) {
|
|
52
|
+
set.add(rx);
|
|
53
|
+
registry.ensureNode(rx).setValue(value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* @since 1.0.0
|
|
59
|
+
* @category hooks
|
|
60
|
+
*/
|
|
61
|
+
export const useRxValue = (rx, f) => {
|
|
62
|
+
const registry = React.useContext(RegistryContext);
|
|
63
|
+
if (f) {
|
|
64
|
+
const rxB = React.useMemo(() => Rx.map(rx, f), [rx, f]);
|
|
65
|
+
return useStore(registry, rxB);
|
|
66
|
+
}
|
|
67
|
+
return useStore(registry, rx);
|
|
68
|
+
};
|
|
69
|
+
function mountRx(registry, rx) {
|
|
70
|
+
React.useEffect(() => registry.mount(rx), [rx, registry]);
|
|
71
|
+
}
|
|
72
|
+
function setRx(registry, rx) {
|
|
73
|
+
return React.useCallback(value => {
|
|
74
|
+
if (typeof value === "function") {
|
|
75
|
+
registry.set(rx, value(registry.get(rx)));
|
|
76
|
+
return;
|
|
77
|
+
} else {
|
|
78
|
+
registry.set(rx, value);
|
|
79
|
+
}
|
|
80
|
+
}, [registry, rx]);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @category hooks
|
|
85
|
+
*/
|
|
86
|
+
export const useRxMount = rx => {
|
|
87
|
+
const registry = React.useContext(RegistryContext);
|
|
88
|
+
mountRx(registry, rx);
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
* @category hooks
|
|
93
|
+
*/
|
|
94
|
+
export const useRxSet = rx => {
|
|
95
|
+
const registry = React.useContext(RegistryContext);
|
|
96
|
+
mountRx(registry, rx);
|
|
97
|
+
return setRx(registry, rx);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* @since 1.0.0
|
|
101
|
+
* @category hooks
|
|
102
|
+
*/
|
|
103
|
+
export const useRxSetPromise = rx => {
|
|
104
|
+
const registry = React.useContext(RegistryContext);
|
|
105
|
+
const resolves = React.useMemo(() => new Set(), []);
|
|
106
|
+
React.useEffect(() => registry.subscribe(rx, result => {
|
|
107
|
+
if (result.waiting || result._tag === "Initial") return;
|
|
108
|
+
const fns = Array.from(resolves);
|
|
109
|
+
resolves.clear();
|
|
110
|
+
const exit = Result.toExit(result);
|
|
111
|
+
fns.forEach(resolve => resolve(exit));
|
|
112
|
+
}, {
|
|
113
|
+
immediate: true
|
|
114
|
+
}), [registry, rx, resolves]);
|
|
115
|
+
return React.useCallback(value => new Promise(resolve => {
|
|
116
|
+
resolves.add(resolve);
|
|
117
|
+
registry.set(rx, value);
|
|
118
|
+
}), [registry, rx, resolves]);
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* @since 1.0.0
|
|
122
|
+
* @category hooks
|
|
123
|
+
*/
|
|
124
|
+
export const useRxRefresh = rx => {
|
|
125
|
+
const registry = React.useContext(RegistryContext);
|
|
126
|
+
mountRx(registry, rx);
|
|
127
|
+
return React.useCallback(() => {
|
|
128
|
+
registry.refresh(rx);
|
|
129
|
+
}, [registry, rx]);
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* @since 1.0.0
|
|
133
|
+
* @category hooks
|
|
134
|
+
*/
|
|
135
|
+
export const useRx = rx => {
|
|
136
|
+
const registry = React.useContext(RegistryContext);
|
|
137
|
+
return [useStore(registry, rx), setRx(registry, rx)];
|
|
138
|
+
};
|
|
139
|
+
const rxPromiseMap = /*#__PURE__*/globalValue("@effect-rx/rx-react/rxPromiseMap", () => ({
|
|
140
|
+
suspendOnWaiting: new Map(),
|
|
141
|
+
default: new Map()
|
|
142
|
+
}));
|
|
143
|
+
function rxToPromise(registry, rx, suspendOnWaiting) {
|
|
144
|
+
const map = suspendOnWaiting ? rxPromiseMap.suspendOnWaiting : rxPromiseMap.default;
|
|
145
|
+
let promise = map.get(rx);
|
|
146
|
+
if (promise !== undefined) {
|
|
147
|
+
return promise;
|
|
148
|
+
}
|
|
149
|
+
promise = new Promise(resolve => {
|
|
150
|
+
const dispose = registry.subscribe(rx, result => {
|
|
151
|
+
if (result._tag === "Initial" || suspendOnWaiting && result.waiting) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
setTimeout(dispose, 1000);
|
|
155
|
+
resolve();
|
|
156
|
+
map.delete(rx);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
map.set(rx, promise);
|
|
160
|
+
return promise;
|
|
161
|
+
}
|
|
162
|
+
function rxResultOrSuspend(registry, rx, suspendOnWaiting) {
|
|
163
|
+
const value = useStore(registry, rx);
|
|
164
|
+
if (value._tag === "Initial" || suspendOnWaiting && value.waiting) {
|
|
165
|
+
throw rxToPromise(registry, rx, suspendOnWaiting);
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @since 1.0.0
|
|
171
|
+
* @category hooks
|
|
172
|
+
*/
|
|
173
|
+
export const useRxSuspense = (rx, options) => {
|
|
174
|
+
const registry = React.useContext(RegistryContext);
|
|
175
|
+
return rxResultOrSuspend(registry, rx, options?.suspendOnWaiting ?? false);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* @since 1.0.0
|
|
179
|
+
* @category hooks
|
|
180
|
+
*/
|
|
181
|
+
export const useRxSuspenseSuccess = (rx, options) => {
|
|
182
|
+
const result = useRxSuspense(rx, options);
|
|
183
|
+
if (result._tag === "Failure") {
|
|
184
|
+
throw Cause.squash(result.cause);
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* @since 1.0.0
|
|
190
|
+
* @category hooks
|
|
191
|
+
*/
|
|
192
|
+
export const useRxSubscribe = (rx, f, options) => {
|
|
193
|
+
const registry = React.useContext(RegistryContext);
|
|
194
|
+
React.useEffect(() => registry.subscribe(rx, f, options), [registry, rx, f, options?.immediate]);
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* @since 1.0.0
|
|
198
|
+
* @category hooks
|
|
199
|
+
*/
|
|
200
|
+
export const useRxRef = ref => {
|
|
201
|
+
const [, setValue] = React.useState(ref.value);
|
|
202
|
+
React.useEffect(() => ref.subscribe(setValue), [ref]);
|
|
203
|
+
return ref.value;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* @since 1.0.0
|
|
207
|
+
* @category hooks
|
|
208
|
+
*/
|
|
209
|
+
export const useRxRefProp = (ref, prop) => React.useMemo(() => ref.prop(prop), [ref, prop]);
|
|
210
|
+
/**
|
|
211
|
+
* @since 1.0.0
|
|
212
|
+
* @category hooks
|
|
213
|
+
*/
|
|
214
|
+
export const useRxRefPropValue = (ref, prop) => useRxRef(useRxRefProp(ref, prop));
|
|
215
|
+
//# sourceMappingURL=Hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hooks.js","names":["Result","Rx","Cause","globalValue","React","RegistryContext","storeRegistry","WeakMap","makeStore","registry","rx","stores","get","undefined","set","store","newStore","subscribe","f","snapshot","useStore","useSyncExternalStore","initialValuesSet","useRxInitialValues","initialValues","useContext","WeakSet","value","has","add","ensureNode","setValue","useRxValue","rxB","useMemo","map","mountRx","useEffect","mount","setRx","useCallback","useRxMount","useRxSet","useRxSetPromise","resolves","Set","result","waiting","_tag","fns","Array","from","clear","exit","toExit","forEach","resolve","immediate","Promise","useRxRefresh","refresh","useRx","rxPromiseMap","suspendOnWaiting","Map","default","rxToPromise","promise","dispose","setTimeout","delete","rxResultOrSuspend","useRxSuspense","options","useRxSuspenseSuccess","squash","cause","useRxSubscribe","useRxRef","ref","useState","useRxRefProp","prop","useRxRefPropValue"],"sources":["../../src/Hooks.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,YAAY;;AAEZ,OAAO,KAAKA,MAAM,MAAM,sBAAsB;AAC9C,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AAEtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,SAASC,WAAW,QAAQ,oBAAoB;AAChD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,eAAe,QAAQ,sBAAsB;AAOtD,MAAMC,aAAa,gB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AAI,CAACA,IAAI,CAAC,EAAE,CAACH,GAAG,EAAEG,IAAI,CAAC,CAAC;AAElD;;;;AAIA,OAAO,MAAMC,iBAAiB,GAAGA,CAAuBJ,GAAmB,EAAEG,IAAO,KAClFJ,QAAQ,CAACG,YAAY,CAACF,GAAG,EAAEG,IAAI,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
"use client";
|
|
5
|
+
|
|
6
|
+
import * as Hydration from "@effect-rx/rx/Hydration";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { RegistryContext } from "./RegistryContext.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
* @category components
|
|
12
|
+
*/
|
|
13
|
+
export const HydrationBoundary = ({
|
|
14
|
+
children,
|
|
15
|
+
state
|
|
16
|
+
}) => {
|
|
17
|
+
const registry = React.useContext(RegistryContext);
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
Hydration.hydrate(registry, state);
|
|
20
|
+
}, [registry, state]);
|
|
21
|
+
return React.createElement(React.Fragment, {}, children);
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=ReactHydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactHydration.js","names":["Hydration","React","RegistryContext","HydrationBoundary","children","state","registry","useContext","useEffect","hydrate","createElement","Fragment"],"sources":["../../src/ReactHydration.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,YAAY;;AACZ,OAAO,KAAKA,SAAS,MAAM,yBAAyB;AACpD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,eAAe,QAAQ,sBAAsB;AAEtD;;;;AAIA,OAAO,MAAMC,iBAAiB,GAGzBA,CAAC;EAAEC,QAAQ;EAAEC;AAAK,CAAE,KAAI;EAC3B,MAAMC,QAAQ,GAAGL,KAAK,CAACM,UAAU,CAACL,eAAe,CAAC;EAClDD,KAAK,CAACO,SAAS,CAAC,MAAK;IACnBR,SAAS,CAACS,OAAO,CAACH,QAAQ,EAAED,KAAK,CAAC;EACpC,CAAC,EAAE,CAACC,QAAQ,EAAED,KAAK,CAAC,CAAC;EACrB,OAAOJ,KAAK,CAACS,aAAa,CAACT,KAAK,CAACU,QAAQ,EAAE,EAAE,EAAEP,QAAQ,CAAC;AAC1D,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
"use client";
|
|
5
|
+
|
|
6
|
+
import * as Registry from "@effect-rx/rx/Registry";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import * as Scheduler from "scheduler";
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
* @category context
|
|
12
|
+
*/
|
|
13
|
+
export function scheduleTask(f) {
|
|
14
|
+
Scheduler.unstable_scheduleCallback(Scheduler.unstable_LowPriority, f);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
* @category context
|
|
19
|
+
*/
|
|
20
|
+
export const RegistryContext = /*#__PURE__*/React.createContext(/*#__PURE__*/Registry.make({
|
|
21
|
+
scheduleTask,
|
|
22
|
+
defaultIdleTTL: 400
|
|
23
|
+
}));
|
|
24
|
+
/**
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
* @category context
|
|
27
|
+
*/
|
|
28
|
+
export const RegistryProvider = options => {
|
|
29
|
+
const registry = React.useMemo(() => Registry.make({
|
|
30
|
+
scheduleTask,
|
|
31
|
+
defaultIdleTTL: 400,
|
|
32
|
+
...options
|
|
33
|
+
}), []);
|
|
34
|
+
React.useEffect(() => () => {
|
|
35
|
+
registry.dispose();
|
|
36
|
+
}, [registry]);
|
|
37
|
+
return React.createElement(RegistryContext.Provider, {
|
|
38
|
+
value: Registry.make({
|
|
39
|
+
scheduleTask,
|
|
40
|
+
defaultIdleTTL: 400,
|
|
41
|
+
...options
|
|
42
|
+
})
|
|
43
|
+
}, options?.children);
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=RegistryContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegistryContext.js","names":["Registry","React","Scheduler","scheduleTask","f","unstable_scheduleCallback","unstable_LowPriority","RegistryContext","createContext","make","defaultIdleTTL","RegistryProvider","options","registry","useMemo","useEffect","dispose","createElement","Provider","value","children"],"sources":["../../src/RegistryContext.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,YAAY;;AACZ,OAAO,KAAKA,QAAQ,MAAM,wBAAwB;AAElD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,OAAO,KAAKC,SAAS,MAAM,WAAW;AAEtC;;;;AAIA,OAAM,SAAUC,YAAYA,CAACC,CAAa;EACxCF,SAAS,CAACG,yBAAyB,CAACH,SAAS,CAACI,oBAAoB,EAAEF,CAAC,CAAC;AACxE;AAEA;;;;AAIA,OAAO,MAAMG,eAAe,gBAAGN,KAAK,CAACO,aAAa,cAAoBR,QAAQ,CAACS,IAAI,CAAC;EAClFN,YAAY;EACZO,cAAc,EAAE;CACjB,CAAC,CAAC;AAEH;;;;AAIA,OAAO,MAAMC,gBAAgB,GAAIC,OAMhC,IAAI;EACH,MAAMC,QAAQ,GAAGZ,KAAK,CAACa,OAAO,CAAC,MAC7Bd,QAAQ,CAACS,IAAI,CAAC;IACZN,YAAY;IACZO,cAAc,EAAE,GAAG;IACnB,GAAGE;GACJ,CAAC,EAAE,EAAE,CAAC;EACTX,KAAK,CAACc,SAAS,CAAC,MAAM,MAAK;IACzBF,QAAQ,CAACG,OAAO,EAAE;EACpB,CAAC,EAAE,CAACH,QAAQ,CAAC,CAAC;EACd,OAAOZ,KAAK,CAACgB,aAAa,CAACV,eAAe,CAACW,QAAQ,EAAE;IACnDC,KAAK,EAAEnB,QAAQ,CAACS,IAAI,CAAC;MACnBN,YAAY;MACZO,cAAc,EAAE,GAAG;MACnB,GAAGE;KACJ;GACF,EAAEA,OAAO,EAAEQ,QAAQ,CAAC;AACvB,CAAC","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,270 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import * as Registry from "@effect-rx/rx/Registry";
|
|
5
|
-
import * as Result from "@effect-rx/rx/Result";
|
|
6
|
-
import * as Rx from "@effect-rx/rx/Rx";
|
|
7
|
-
import * as Cause from "effect/Cause";
|
|
8
|
-
import { globalValue } from "effect/GlobalValue";
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
import * as Scheduler from "scheduler";
|
|
11
4
|
/**
|
|
12
5
|
* @since 1.0.0
|
|
13
|
-
* @category
|
|
14
|
-
*/
|
|
15
|
-
export * as Registry from "@effect-rx/rx/Registry";
|
|
16
|
-
/**
|
|
17
|
-
* @since 1.0.0
|
|
18
|
-
* @category modules
|
|
19
|
-
*/
|
|
20
|
-
export * as Result from "@effect-rx/rx/Result";
|
|
21
|
-
/**
|
|
22
|
-
* @since 1.0.0
|
|
23
|
-
* @category modules
|
|
6
|
+
* @category re-exports
|
|
24
7
|
*/
|
|
25
8
|
export * as Rx from "@effect-rx/rx/Rx";
|
|
26
9
|
/**
|
|
27
10
|
* @since 1.0.0
|
|
28
|
-
* @category
|
|
29
|
-
*/
|
|
30
|
-
export * as RxRef from "@effect-rx/rx/RxRef";
|
|
31
|
-
/**
|
|
32
|
-
* @since 1.0.0
|
|
33
|
-
* @category context
|
|
34
|
-
*/
|
|
35
|
-
export function scheduleTask(f) {
|
|
36
|
-
Scheduler.unstable_scheduleCallback(Scheduler.unstable_LowPriority, f);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @since 1.0.0
|
|
40
|
-
* @category context
|
|
41
|
-
*/
|
|
42
|
-
export const RegistryContext = /*#__PURE__*/React.createContext(/*#__PURE__*/Registry.make({
|
|
43
|
-
scheduleTask,
|
|
44
|
-
defaultIdleTTL: 400
|
|
45
|
-
}));
|
|
46
|
-
/**
|
|
47
|
-
* @since 1.0.0
|
|
48
|
-
* @category context
|
|
11
|
+
* @category re-exports
|
|
49
12
|
*/
|
|
50
|
-
export
|
|
51
|
-
const registry = React.useMemo(() => Registry.make({
|
|
52
|
-
scheduleTask,
|
|
53
|
-
defaultIdleTTL: 400,
|
|
54
|
-
...options
|
|
55
|
-
}), []);
|
|
56
|
-
React.useEffect(() => () => {
|
|
57
|
-
registry.dispose();
|
|
58
|
-
}, [registry]);
|
|
59
|
-
return React.createElement(RegistryContext.Provider, {
|
|
60
|
-
value: Registry.make({
|
|
61
|
-
scheduleTask,
|
|
62
|
-
defaultIdleTTL: 400,
|
|
63
|
-
...options
|
|
64
|
-
})
|
|
65
|
-
}, options?.children);
|
|
66
|
-
};
|
|
67
|
-
const storeRegistry = /*#__PURE__*/globalValue("@effect-rx/rx-react/storeRegistry", () => new WeakMap());
|
|
68
|
-
function makeStore(registry, rx) {
|
|
69
|
-
let stores = storeRegistry.get(registry);
|
|
70
|
-
if (stores === undefined) {
|
|
71
|
-
stores = new WeakMap();
|
|
72
|
-
storeRegistry.set(registry, stores);
|
|
73
|
-
}
|
|
74
|
-
const store = stores.get(rx);
|
|
75
|
-
if (store !== undefined) {
|
|
76
|
-
return store;
|
|
77
|
-
}
|
|
78
|
-
const newStore = {
|
|
79
|
-
subscribe(f) {
|
|
80
|
-
return registry.subscribe(rx, f);
|
|
81
|
-
},
|
|
82
|
-
snapshot() {
|
|
83
|
-
return registry.get(rx);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
stores.set(rx, newStore);
|
|
87
|
-
return newStore;
|
|
88
|
-
}
|
|
89
|
-
function useStore(registry, rx) {
|
|
90
|
-
const store = makeStore(registry, rx);
|
|
91
|
-
return React.useSyncExternalStore(store.subscribe, store.snapshot, store.snapshot);
|
|
92
|
-
}
|
|
93
|
-
const initialValuesSet = /*#__PURE__*/globalValue("@effect-rx/rx-react/initialValuesSet", () => new WeakMap());
|
|
94
|
-
/**
|
|
95
|
-
* @since 1.0.0
|
|
96
|
-
* @category hooks
|
|
97
|
-
*/
|
|
98
|
-
export const useRxInitialValues = initialValues => {
|
|
99
|
-
const registry = React.useContext(RegistryContext);
|
|
100
|
-
let set = initialValuesSet.get(registry);
|
|
101
|
-
if (set === undefined) {
|
|
102
|
-
set = new WeakSet();
|
|
103
|
-
initialValuesSet.set(registry, set);
|
|
104
|
-
}
|
|
105
|
-
for (const [rx, value] of initialValues) {
|
|
106
|
-
if (!set.has(rx)) {
|
|
107
|
-
set.add(rx);
|
|
108
|
-
registry.ensureNode(rx).setValue(value);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* @since 1.0.0
|
|
114
|
-
* @category hooks
|
|
115
|
-
*/
|
|
116
|
-
export const useRxValue = (rx, f) => {
|
|
117
|
-
const registry = React.useContext(RegistryContext);
|
|
118
|
-
if (f) {
|
|
119
|
-
const rxB = React.useMemo(() => Rx.map(rx, f), [rx, f]);
|
|
120
|
-
return useStore(registry, rxB);
|
|
121
|
-
}
|
|
122
|
-
return useStore(registry, rx);
|
|
123
|
-
};
|
|
124
|
-
function mountRx(registry, rx) {
|
|
125
|
-
React.useEffect(() => registry.mount(rx), [rx, registry]);
|
|
126
|
-
}
|
|
127
|
-
function setRx(registry, rx) {
|
|
128
|
-
return React.useCallback(value => {
|
|
129
|
-
if (typeof value === "function") {
|
|
130
|
-
registry.set(rx, value(registry.get(rx)));
|
|
131
|
-
return;
|
|
132
|
-
} else {
|
|
133
|
-
registry.set(rx, value);
|
|
134
|
-
}
|
|
135
|
-
}, [registry, rx]);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* @since 1.0.0
|
|
139
|
-
* @category hooks
|
|
140
|
-
*/
|
|
141
|
-
export const useRxMount = rx => {
|
|
142
|
-
const registry = React.useContext(RegistryContext);
|
|
143
|
-
mountRx(registry, rx);
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* @since 1.0.0
|
|
147
|
-
* @category hooks
|
|
148
|
-
*/
|
|
149
|
-
export const useRxSet = rx => {
|
|
150
|
-
const registry = React.useContext(RegistryContext);
|
|
151
|
-
mountRx(registry, rx);
|
|
152
|
-
return setRx(registry, rx);
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* @since 1.0.0
|
|
156
|
-
* @category hooks
|
|
157
|
-
*/
|
|
158
|
-
export const useRxSetPromise = rx => {
|
|
159
|
-
const registry = React.useContext(RegistryContext);
|
|
160
|
-
const resolves = React.useMemo(() => new Set(), []);
|
|
161
|
-
React.useEffect(() => registry.subscribe(rx, result => {
|
|
162
|
-
if (result.waiting || result._tag === "Initial") return;
|
|
163
|
-
const fns = Array.from(resolves);
|
|
164
|
-
resolves.clear();
|
|
165
|
-
const exit = Result.toExit(result);
|
|
166
|
-
fns.forEach(resolve => resolve(exit));
|
|
167
|
-
}, {
|
|
168
|
-
immediate: true
|
|
169
|
-
}), [registry, rx, resolves]);
|
|
170
|
-
return React.useCallback(value => new Promise(resolve => {
|
|
171
|
-
resolves.add(resolve);
|
|
172
|
-
registry.set(rx, value);
|
|
173
|
-
}), [registry, rx, resolves]);
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* @since 1.0.0
|
|
177
|
-
* @category hooks
|
|
178
|
-
*/
|
|
179
|
-
export const useRxRefresh = rx => {
|
|
180
|
-
const registry = React.useContext(RegistryContext);
|
|
181
|
-
mountRx(registry, rx);
|
|
182
|
-
return React.useCallback(() => {
|
|
183
|
-
registry.refresh(rx);
|
|
184
|
-
}, [registry, rx]);
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* @since 1.0.0
|
|
188
|
-
* @category hooks
|
|
189
|
-
*/
|
|
190
|
-
export const useRx = rx => {
|
|
191
|
-
const registry = React.useContext(RegistryContext);
|
|
192
|
-
return [useStore(registry, rx), setRx(registry, rx)];
|
|
193
|
-
};
|
|
194
|
-
const rxPromiseMap = /*#__PURE__*/globalValue("@effect-rx/rx-react/rxPromiseMap", () => ({
|
|
195
|
-
suspendOnWaiting: new Map(),
|
|
196
|
-
default: new Map()
|
|
197
|
-
}));
|
|
198
|
-
function rxToPromise(registry, rx, suspendOnWaiting) {
|
|
199
|
-
const map = suspendOnWaiting ? rxPromiseMap.suspendOnWaiting : rxPromiseMap.default;
|
|
200
|
-
let promise = map.get(rx);
|
|
201
|
-
if (promise !== undefined) {
|
|
202
|
-
return promise;
|
|
203
|
-
}
|
|
204
|
-
promise = new Promise(resolve => {
|
|
205
|
-
const dispose = registry.subscribe(rx, result => {
|
|
206
|
-
if (result._tag === "Initial" || suspendOnWaiting && result.waiting) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
setTimeout(dispose, 1000);
|
|
210
|
-
resolve();
|
|
211
|
-
map.delete(rx);
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
map.set(rx, promise);
|
|
215
|
-
return promise;
|
|
216
|
-
}
|
|
217
|
-
function rxResultOrSuspend(registry, rx, suspendOnWaiting) {
|
|
218
|
-
const value = useStore(registry, rx);
|
|
219
|
-
if (value._tag === "Initial" || suspendOnWaiting && value.waiting) {
|
|
220
|
-
throw rxToPromise(registry, rx, suspendOnWaiting);
|
|
221
|
-
}
|
|
222
|
-
return value;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* @since 1.0.0
|
|
226
|
-
* @category hooks
|
|
227
|
-
*/
|
|
228
|
-
export const useRxSuspense = (rx, options) => {
|
|
229
|
-
const registry = React.useContext(RegistryContext);
|
|
230
|
-
return rxResultOrSuspend(registry, rx, options?.suspendOnWaiting ?? false);
|
|
231
|
-
};
|
|
13
|
+
export * as Registry from "@effect-rx/rx/Registry";
|
|
232
14
|
/**
|
|
233
15
|
* @since 1.0.0
|
|
234
|
-
* @category
|
|
16
|
+
* @category re-exports
|
|
235
17
|
*/
|
|
236
|
-
export
|
|
237
|
-
const result = useRxSuspense(rx, options);
|
|
238
|
-
if (result._tag === "Failure") {
|
|
239
|
-
throw Cause.squash(result.cause);
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
};
|
|
18
|
+
export * as Result from "@effect-rx/rx/Registry";
|
|
243
19
|
/**
|
|
244
20
|
* @since 1.0.0
|
|
245
|
-
* @category
|
|
21
|
+
* @category re-exports
|
|
246
22
|
*/
|
|
247
|
-
export
|
|
248
|
-
const registry = React.useContext(RegistryContext);
|
|
249
|
-
React.useEffect(() => registry.subscribe(rx, f, options), [registry, rx, f, options?.immediate]);
|
|
250
|
-
};
|
|
23
|
+
export * as Hydration from "@effect-rx/rx/Hydration";
|
|
251
24
|
/**
|
|
252
25
|
* @since 1.0.0
|
|
253
|
-
* @category
|
|
26
|
+
* @category re-exports
|
|
254
27
|
*/
|
|
255
|
-
export
|
|
256
|
-
const [, setValue] = React.useState(ref.value);
|
|
257
|
-
React.useEffect(() => ref.subscribe(setValue), [ref]);
|
|
258
|
-
return ref.value;
|
|
259
|
-
};
|
|
28
|
+
export * as RxRef from "@effect-rx/rx/RxRef";
|
|
260
29
|
/**
|
|
261
30
|
* @since 1.0.0
|
|
262
31
|
* @category hooks
|
|
263
32
|
*/
|
|
264
|
-
export
|
|
33
|
+
export * from "./Hooks.js";
|
|
265
34
|
/**
|
|
266
35
|
* @since 1.0.0
|
|
267
|
-
* @category
|
|
36
|
+
* @category context
|
|
268
37
|
*/
|
|
269
|
-
export
|
|
38
|
+
export * from "./RegistryContext.js";
|
|
270
39
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["Rx","Registry","Result","Hydration","RxRef"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;;;;AAIA,OAAO,KAAKA,EAAE,MAAM,kBAAkB;AAEtC;;;;AAIA,OAAO,KAAKC,QAAQ,MAAM,wBAAwB;AAElD;;;;AAIA,OAAO,KAAKC,MAAM,MAAM,wBAAwB;AAEhD;;;;AAIA,OAAO,KAAKC,SAAS,MAAM,yBAAyB;AAEpD;;;;AAIA,OAAO,KAAKC,KAAK,MAAM,qBAAqB;AAE5C;;;;AAIA,cAAc,YAAY;AAE1B;;;;AAIA,cAAc,sBAAsB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-rx/rx-react",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.2",
|
|
4
4
|
"description": "Reactive toolkit for Effect",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"author": "Effect contributors",
|
|
12
12
|
"homepage": "https://github.com/effect-ts/rx",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@effect-rx/rx": "^0.
|
|
14
|
+
"@effect-rx/rx": "^0.44.1"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"effect": "^3.16",
|
|
@@ -27,6 +27,34 @@
|
|
|
27
27
|
"types": "./dist/dts/index.d.ts",
|
|
28
28
|
"import": "./dist/esm/index.js",
|
|
29
29
|
"default": "./dist/cjs/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./Hooks": {
|
|
32
|
+
"types": "./dist/dts/Hooks.d.ts",
|
|
33
|
+
"import": "./dist/esm/Hooks.js",
|
|
34
|
+
"default": "./dist/cjs/Hooks.js"
|
|
35
|
+
},
|
|
36
|
+
"./ReactHydration": {
|
|
37
|
+
"types": "./dist/dts/ReactHydration.d.ts",
|
|
38
|
+
"import": "./dist/esm/ReactHydration.js",
|
|
39
|
+
"default": "./dist/cjs/ReactHydration.js"
|
|
40
|
+
},
|
|
41
|
+
"./RegistryContext": {
|
|
42
|
+
"types": "./dist/dts/RegistryContext.d.ts",
|
|
43
|
+
"import": "./dist/esm/RegistryContext.js",
|
|
44
|
+
"default": "./dist/cjs/RegistryContext.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"typesVersions": {
|
|
48
|
+
"*": {
|
|
49
|
+
"Hooks": [
|
|
50
|
+
"./dist/dts/Hooks.d.ts"
|
|
51
|
+
],
|
|
52
|
+
"ReactHydration": [
|
|
53
|
+
"./dist/dts/ReactHydration.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"RegistryContext": [
|
|
56
|
+
"./dist/dts/RegistryContext.d.ts"
|
|
57
|
+
]
|
|
30
58
|
}
|
|
31
59
|
}
|
|
32
60
|
}
|