@effect-rx/rx-react 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present The Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ WIP.
2
+
3
+ Docs: https://effect-ts.github.io/rx
package/Registry.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * from "@effect-rx/rx/Registry";
5
+ //# sourceMappingURL=Registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["./src/Registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,wBAAwB,CAAA"}
package/Registry.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _Registry = /*#__PURE__*/require("@effect-rx/rx/Registry");
7
+ Object.keys(_Registry).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Registry[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Registry[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=Registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registry.js","names":["_Registry","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["./src/Registry.ts"],"sourcesContent":[null],"mappings":";;;;;AAIA,IAAAA,SAAA,gBAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,SAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
package/Result.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * from "@effect-rx/rx/Result";
5
+ //# sourceMappingURL=Result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["./src/Result.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,sBAAsB,CAAA"}
package/Result.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _Result = /*#__PURE__*/require("@effect-rx/rx/Result");
7
+ Object.keys(_Result).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Result[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Result[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=Result.js.map
package/Result.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Result.js","names":["_Result","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["./src/Result.ts"],"sourcesContent":[null],"mappings":";;;;;AAIA,IAAAA,OAAA,gBAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
package/Rx.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * from "@effect-rx/rx/Rx";
5
+ //# sourceMappingURL=Rx.d.ts.map
package/Rx.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rx.d.ts","sourceRoot":"","sources":["./src/Rx.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAA"}
package/Rx.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _Rx = /*#__PURE__*/require("@effect-rx/rx/Rx");
7
+ Object.keys(_Rx).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Rx[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Rx[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=Rx.js.map
package/Rx.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rx.js","names":["_Rx","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["./src/Rx.ts"],"sourcesContent":[null],"mappings":";;;;;AAIA,IAAAA,GAAA,gBAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,GAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,GAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,GAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
package/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Registry from "@effect-rx/rx/Registry";
5
+ import type * as Rx from "@effect-rx/rx/Rx";
6
+ import * as React from "react";
7
+ /**
8
+ * @since 1.0.0
9
+ * @category context
10
+ */
11
+ export declare const RegistryContext: React.Context<Registry.Registry>;
12
+ /**
13
+ * @since 1.0.0
14
+ * @category hooks
15
+ */
16
+ export declare const useRxValue: <A>(rx: Rx.Rx<A>) => A;
17
+ /**
18
+ * @since 1.0.0
19
+ * @category hooks
20
+ */
21
+ export declare const useSetRx: <R, W>(rx: Rx.Writeable<R, W>) => (_: W) => void;
22
+ /**
23
+ * @since 1.0.0
24
+ * @category hooks
25
+ */
26
+ export declare const useRx: <R, W>(rx: Rx.Writeable<R, W>) => readonly [R, (_: W) => void];
27
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["./src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;GAGG;AACH,eAAO,MAAM,eAAe,kCAA0D,CAAA;AAqBtF;;;GAGG;AACH,eAAO,MAAM,UAAU,wBAOtB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,8CAA6C,IAGjE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,2DAA0D,IAAI,CAG/E,CAAA"}
package/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSetRx = exports.useRxValue = exports.useRx = exports.RegistryContext = void 0;
7
+ var Registry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Registry"));
8
+ var React = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ /**
12
+ * @since 1.0.0
13
+ */
14
+
15
+ /**
16
+ * @since 1.0.0
17
+ * @category context
18
+ */
19
+ const RegistryContext = /*#__PURE__*/React.createContext( /*#__PURE__*/Registry.make());
20
+ exports.RegistryContext = RegistryContext;
21
+ class RxStore {
22
+ constructor(registry, rx) {
23
+ this.registry = registry;
24
+ this.rx = rx;
25
+ this.value = this.registry.get(this.rx);
26
+ this.subscribe = f => {
27
+ this.value = this.registry.get(this.rx);
28
+ return this.registry.subscribe(this.rx, a => {
29
+ this.value = a;
30
+ f();
31
+ });
32
+ };
33
+ this.snapshot = () => this.value;
34
+ }
35
+ }
36
+ /**
37
+ * @since 1.0.0
38
+ * @category hooks
39
+ */
40
+ const useRxValue = rx => {
41
+ const registry = React.useContext(RegistryContext);
42
+ const store = React.useRef(undefined);
43
+ if (store.current === undefined) {
44
+ store.current = new RxStore(registry, rx);
45
+ }
46
+ return React.useSyncExternalStore(store.current.subscribe, store.current.snapshot);
47
+ };
48
+ /**
49
+ * @since 1.0.0
50
+ * @category hooks
51
+ */
52
+ exports.useRxValue = useRxValue;
53
+ const useSetRx = rx => {
54
+ const registry = React.useContext(RegistryContext);
55
+ return React.useCallback(value => registry.set(rx, value), [registry, rx]);
56
+ };
57
+ /**
58
+ * @since 1.0.0
59
+ * @category hooks
60
+ */
61
+ exports.useSetRx = useSetRx;
62
+ const useRx = rx => [useRxValue(rx), useSetRx(rx)];
63
+ exports.useRx = useRx;
64
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Registry","_interopRequireWildcard","require","React","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","RegistryContext","createContext","make","exports","RxStore","constructor","registry","rx","value","subscribe","f","a","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","useRx"],"sources":["./src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAEA,IAAAC,KAAA,gBAAAF,uBAAA,eAAAC,OAAA;AAA8B,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAA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AED;;;;AAAAT,OAAA,CAAAU,UAAA,GAAAA,UAAA;AAIO,MAAMO,QAAQ,GAAUb,EAAsB,IAAoB;EACvE,MAAMD,QAAQ,GAAG7B,KAAK,CAACqC,UAAU,CAACd,eAAe,CAAC;EAClD,OAAOvB,KAAK,CAAC4C,WAAW,CAAEb,KAAK,IAAKF,QAAQ,CAACP,GAAG,CAACQ,EAAE,EAAEC,KAAK,CAAC,EAAE,CAACF,QAAQ,EAAEC,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;;AAAAJ,OAAA,CAAAiB,QAAA,GAAAA,QAAA;AAIO,MAAME,KAAK,GAAUf,EAAsB,IAAmC,CACnFM,UAAU,CAACN,EAAE,CAAC,EACda,QAAQ,CAACb,EAAE,CAAC,CACb;AAAAJ,OAAA,CAAAmB,KAAA,GAAAA,KAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * from "@effect-rx/rx/Registry";
5
+ //# sourceMappingURL=Registry.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registry.mjs","names":[],"sources":["../src/Registry.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA,cAAc,wBAAwB"}
package/mjs/Result.mjs ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * from "@effect-rx/rx/Result";
5
+ //# sourceMappingURL=Result.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Result.mjs","names":[],"sources":["../src/Result.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA,cAAc,sBAAsB"}
package/mjs/Rx.mjs ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * from "@effect-rx/rx/Rx";
5
+ //# sourceMappingURL=Rx.mjs.map
package/mjs/Rx.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rx.mjs","names":[],"sources":["../src/Rx.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA,cAAc,kBAAkB"}
package/mjs/index.mjs ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Registry from "@effect-rx/rx/Registry";
5
+ import * as React from "react";
6
+ /**
7
+ * @since 1.0.0
8
+ * @category context
9
+ */
10
+ export const RegistryContext = /*#__PURE__*/React.createContext( /*#__PURE__*/Registry.make());
11
+ class RxStore {
12
+ constructor(registry, rx) {
13
+ this.registry = registry;
14
+ this.rx = rx;
15
+ this.value = this.registry.get(this.rx);
16
+ this.subscribe = f => {
17
+ this.value = this.registry.get(this.rx);
18
+ return this.registry.subscribe(this.rx, a => {
19
+ this.value = a;
20
+ f();
21
+ });
22
+ };
23
+ this.snapshot = () => this.value;
24
+ }
25
+ }
26
+ /**
27
+ * @since 1.0.0
28
+ * @category hooks
29
+ */
30
+ export const useRxValue = rx => {
31
+ const registry = React.useContext(RegistryContext);
32
+ const store = React.useRef(undefined);
33
+ if (store.current === undefined) {
34
+ store.current = new RxStore(registry, rx);
35
+ }
36
+ return React.useSyncExternalStore(store.current.subscribe, store.current.snapshot);
37
+ };
38
+ /**
39
+ * @since 1.0.0
40
+ * @category hooks
41
+ */
42
+ export const useSetRx = rx => {
43
+ const registry = React.useContext(RegistryContext);
44
+ return React.useCallback(value => registry.set(rx, value), [registry, rx]);
45
+ };
46
+ /**
47
+ * @since 1.0.0
48
+ * @category hooks
49
+ */
50
+ export const useRx = rx => [useRxValue(rx), useSetRx(rx)];
51
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["Registry","React","RegistryContext","createContext","make","RxStore","constructor","registry","rx","value","get","subscribe","f","a","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","set","useRx"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,QAAQ,MAAM,wBAAwB;AAElD,OAAO,KAAKC,K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UAAU,CAACd,eAAe,CAAC;EAClD,OAAOD,KAAK,CAACsB,WAAW,CAAEd,KAAK,IAAKF,QAAQ,CAACiB,GAAG,CAAChB,EAAE,EAAEC,KAAK,CAAC,EAAE,CAACF,QAAQ,EAAEC,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;;AAIA,OAAO,MAAMiB,KAAK,GAAUjB,EAAsB,IAAmC,CACnFO,UAAU,CAACP,EAAE,CAAC,EACdc,QAAQ,CAACd,EAAE,CAAC,CACb"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@effect-rx/rx-react",
3
+ "version": "0.1.0",
4
+ "description": "Reactive toolkit for Effect",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/effect-ts/rx.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "exports": {
14
+ "./*": {
15
+ "import": {
16
+ "types": "./*.d.ts",
17
+ "default": "./mjs/*.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./*.d.ts",
21
+ "default": "./*.js"
22
+ }
23
+ },
24
+ ".": {
25
+ "import": {
26
+ "types": "./index.d.ts",
27
+ "default": "./mjs/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./index.d.ts",
31
+ "default": "./index.js"
32
+ }
33
+ }
34
+ },
35
+ "sideEffects": [],
36
+ "author": "Effect contributors",
37
+ "dependencies": {
38
+ "@effect-rx/rx": "^0.1.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@effect/data": "^0.18.5",
42
+ "@effect/io": "^0.40.1",
43
+ "@effect/stream": "^0.36.0",
44
+ "react": "^18"
45
+ },
46
+ "main": "./index.js"
47
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ export * from "@effect-rx/rx/Registry"
package/src/Result.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ export * from "@effect-rx/rx/Result"
package/src/Rx.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ export * from "@effect-rx/rx/Rx"
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Registry from "@effect-rx/rx/Registry"
5
+ import type * as Rx from "@effect-rx/rx/Rx"
6
+ import * as React from "react"
7
+
8
+ /**
9
+ * @since 1.0.0
10
+ * @category context
11
+ */
12
+ export const RegistryContext = React.createContext<Registry.Registry>(Registry.make())
13
+
14
+ class RxStore<A> {
15
+ constructor(
16
+ readonly registry: Registry.Registry,
17
+ readonly rx: Rx.Rx<A>
18
+ ) {}
19
+
20
+ value = this.registry.get(this.rx)
21
+
22
+ subscribe = (f: () => void): () => void => {
23
+ this.value = this.registry.get(this.rx)
24
+ return this.registry.subscribe(this.rx, (a) => {
25
+ this.value = a
26
+ f()
27
+ })
28
+ }
29
+
30
+ snapshot = (): A => this.value
31
+ }
32
+
33
+ /**
34
+ * @since 1.0.0
35
+ * @category hooks
36
+ */
37
+ export const useRxValue = <A>(rx: Rx.Rx<A>): A => {
38
+ const registry = React.useContext(RegistryContext)
39
+ const store = React.useRef<RxStore<A>>(undefined as any)
40
+ if (store.current === undefined) {
41
+ store.current = new RxStore(registry, rx)
42
+ }
43
+ return React.useSyncExternalStore(store.current.subscribe, store.current.snapshot)
44
+ }
45
+
46
+ /**
47
+ * @since 1.0.0
48
+ * @category hooks
49
+ */
50
+ export const useSetRx = <R, W>(rx: Rx.Writeable<R, W>): (_: W) => void => {
51
+ const registry = React.useContext(RegistryContext)
52
+ return React.useCallback((value) => registry.set(rx, value), [registry, rx])
53
+ }
54
+
55
+ /**
56
+ * @since 1.0.0
57
+ * @category hooks
58
+ */
59
+ export const useRx = <R, W>(rx: Rx.Writeable<R, W>): readonly [R, (_: W) => void] => [
60
+ useRxValue(rx),
61
+ useSetRx(rx)
62
+ ]
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/esm",
5
+ "declarationDir": "build/dts",
6
+ "tsBuildInfoFile": "build/tsbuildinfo/esm.tsbuildinfo",
7
+ "rootDir": "src"
8
+ },
9
+ "include": ["src/**/*.ts"],
10
+ "references": [{ "path": "../rx" }]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "tsBuildInfoFile": "build/tsbuildinfo/examples.tsbuildinfo",
5
+ "rootDir": "examples",
6
+ "module": "CommonJS",
7
+ "outDir": "build/examples"
8
+ },
9
+ "include": ["examples/**/*.ts"],
10
+ "references": [{ "path": "./tsconfig.build.json" }]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "tsBuildInfoFile": "build/tsbuildinfo/tsconfig.tsbuildinfo"
5
+ },
6
+ "references": [
7
+ { "path": "./tsconfig.build.json" },
8
+ { "path": "./tsconfig.test.json" },
9
+ { "path": "./tsconfig.examples.json" }
10
+ ]
11
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/test",
5
+ "declarationDir": "build/test-dts",
6
+ "tsBuildInfoFile": "build/tsbuildinfo/test.tsbuildinfo",
7
+ "rootDir": "test",
8
+ "types": ["vitest/globals"]
9
+ },
10
+ "include": ["test/**/*.ts"],
11
+ "references": [{ "path": "./tsconfig.build.json" }]
12
+ }