@effect-rx/rx-vue 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
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useRxValue = exports.useRxSet = exports.useRxRef = exports.useRx = exports.registryKey = exports.injectRegistry = exports.defaultRegistry = exports.RxRef = exports.Rx = exports.Result = exports.Registry = void 0;
7
+ var Registry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Registry"));
8
+ var _Registry = Registry;
9
+ exports.Registry = Registry;
10
+ var _GlobalValue = /*#__PURE__*/require("effect/GlobalValue");
11
+ var _vue = /*#__PURE__*/require("vue");
12
+ var _Result = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Result"));
13
+ exports.Result = _Result;
14
+ var _Rx = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Rx"));
15
+ exports.Rx = _Rx;
16
+ var _RxRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/RxRef"));
17
+ exports.RxRef = _RxRef;
18
+ function _getRequireWildcardCache(e) {
19
+ if ("function" != typeof WeakMap) return null;
20
+ var r = new WeakMap(),
21
+ t = new WeakMap();
22
+ return (_getRequireWildcardCache = function (e) {
23
+ return e ? t : r;
24
+ })(e);
25
+ }
26
+ function _interopRequireWildcard(e, r) {
27
+ if (!r && e && e.__esModule) return e;
28
+ if (null === e || "object" != typeof e && "function" != typeof e) return {
29
+ default: e
30
+ };
31
+ var t = _getRequireWildcardCache(r);
32
+ if (t && t.has(e)) return t.get(e);
33
+ var n = {
34
+ __proto__: null
35
+ },
36
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
37
+ for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {
38
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
39
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
40
+ }
41
+ return n.default = e, t && t.set(e, n), n;
42
+ }
43
+ /**
44
+ * @since 1.0.0
45
+ */
46
+
47
+ /**
48
+ * @since 1.0.0
49
+ * @category modules
50
+ */
51
+
52
+ /**
53
+ * @since 1.0.0
54
+ * @category modules
55
+ */
56
+
57
+ /**
58
+ * @since 1.0.0
59
+ * @category modules
60
+ */
61
+
62
+ /**
63
+ * @since 1.0.0
64
+ * @category modules
65
+ */
66
+
67
+ /**
68
+ * @since 1.0.0
69
+ * @category registry
70
+ */
71
+ const registryKey = exports.registryKey = Registry.TypeId;
72
+ /**
73
+ * @since 1.0.0
74
+ * @category registry
75
+ */
76
+ const defaultRegistry = exports.defaultRegistry = /*#__PURE__*/(0, _GlobalValue.globalValue)("@effect-rx/rx-vue/defaultRegistry", () => Registry.make());
77
+ /**
78
+ * @since 1.0.0
79
+ * @category registry
80
+ */
81
+ const injectRegistry = () => {
82
+ return (0, _vue.inject)(registryKey) ?? defaultRegistry;
83
+ };
84
+ /**
85
+ * @since 1.0.0
86
+ * @category composables
87
+ */
88
+ exports.injectRegistry = injectRegistry;
89
+ const useRx = rx => {
90
+ const registry = injectRegistry();
91
+ const value = (0, _vue.ref)(registry.get(rx));
92
+ const cancel = registry.subscribe(rx, nextValue => {
93
+ value.value = nextValue;
94
+ });
95
+ if ((0, _vue.getCurrentScope)()) {
96
+ (0, _vue.onScopeDispose)(cancel);
97
+ }
98
+ return [value, _ => registry.set(rx, _)];
99
+ };
100
+ /**
101
+ * @since 1.0.0
102
+ * @category composables
103
+ */
104
+ exports.useRx = useRx;
105
+ const useRxValue = rx => {
106
+ const registry = injectRegistry();
107
+ const value = (0, _vue.ref)(registry.get(rx));
108
+ const cancel = registry.subscribe(rx, nextValue => {
109
+ value.value = nextValue;
110
+ });
111
+ if ((0, _vue.getCurrentScope)()) {
112
+ (0, _vue.onScopeDispose)(cancel);
113
+ }
114
+ return value;
115
+ };
116
+ /**
117
+ * @since 1.0.0
118
+ * @category composables
119
+ */
120
+ exports.useRxValue = useRxValue;
121
+ const useRxSet = rx => {
122
+ const registry = injectRegistry();
123
+ const cancel = registry.mount(rx);
124
+ if ((0, _vue.getCurrentScope)()) {
125
+ (0, _vue.onScopeDispose)(cancel);
126
+ }
127
+ return _ => registry.set(rx, _);
128
+ };
129
+ /**
130
+ * @since 1.0.0
131
+ * @category composables
132
+ */
133
+ exports.useRxSet = useRxSet;
134
+ const useRxRef = rxRef => {
135
+ const value = (0, _vue.ref)(rxRef.value);
136
+ const cancel = rxRef.subscribe(nextValue => {
137
+ value.value = nextValue;
138
+ });
139
+ if ((0, _vue.getCurrentScope)()) {
140
+ (0, _vue.onScopeDispose)(cancel);
141
+ }
142
+ return value;
143
+ };
144
+ exports.useRxRef = useRxRef;
145
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Registry","_interopRequireWildcard","require","_Registry","exports","_GlobalValue","_vue","_Result","Result","_Rx","Rx","_RxRef","RxRef","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","registryKey","TypeId","defaultRegistry","globalValue","make","injectRegistry","inject","useRx","rx","registry","value","ref","cancel","subscribe","nextValue","getCurrentScope","onScopeDispose","_","useRxValue","useRxSet","mount","useRxRef","rxRef"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAAkD,IAAAC,SAAA,GAAAH,QAAA;AAAAI,OAAA,CAAAJ,QAAA,GAAAA,QAAA;AAGlD,IAAAK,YAAA,gBAAAH,OAAA;AAEA,IAAAI,IAAA,gBAAAJ,OAAA;AAAkE,IAAAK,OAAA,gBAAAN,uBAAA,eAAAC,OAAA;AAAAE,OAAA,CAAAI,MAAA,GAAAD,OAAA;AAAA,IAAAE,GAAA,gBAAAR,uBAAA,eAAAC,OAAA;AAAAE,OAAA,CAAAM,EAAA,GAAAD,GAAA;AAAA,IAAAE,MAAA,gBAAAV,uBAAA,eAAAC,OAAA;AAAAE,OAAA,CAAAQ,KAAA,GAAAD,MAAA;AAAA,SAAAE,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAF,wBAAA,YAAAA,CAAAC,CAAA;IAAA,OAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA;EAAA,GAAAF,CAAA;AAAA;AAAA,SAAAb,wB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ACJ,MAAM,CAAC;EACxB;EACA,OAAOF,KAAyB;AAClC,CAAC;AAED;;;;AAAAxC,OAAA,CAAAgD,UAAA,GAAAA,UAAA;AAIO,MAAMC,QAAQ,GAAUX,EAAqB,IAAoB;EACtE,MAAMC,QAAQ,GAAGJ,cAAc,EAAE;EACjC,MAAMO,MAAM,GAAGH,QAAQ,CAACW,KAAK,CAACZ,EAAE,CAAC;EACjC,IAAI,IAAApC,IAAA,CAAA2C,eAAe,GAAE,EAAE;IACrB,IAAA3C,IAAA,CAAA4C,cAAc,EAACJ,MAAM,CAAC;EACxB;EACA,OAAQK,CAAC,IAAKR,QAAQ,CAACV,GAAG,CAACS,EAAE,EAAES,CAAC,CAAC;AACnC,CAAC;AAED;;;;AAAA/C,OAAA,CAAAiD,QAAA,GAAAA,QAAA;AAIO,MAAME,QAAQ,GAAOC,KAA2B,IAAsB;EAC3E,MAAMZ,KAAK,GAAG,IAAAtC,IAAA,CAAAuC,GAAG,EAAIW,KAAK,CAACZ,KAAK,CAAC;EACjC,MAAME,MAAM,GAAGU,KAAK,CAACT,SAAS,CAAEC,SAAS,IAAI;IAC3CJ,KAAK,CAACA,KAAK,GAAGI,SAAgB;EAChC,CAAC,CAAC;EACF,IAAI,IAAA1C,IAAA,CAAA2C,eAAe,GAAE,EAAE;IACrB,IAAA3C,IAAA,CAAA4C,cAAc,EAACJ,MAAM,CAAC;EACxB;EACA,OAAOF,KAAyB;AAClC,CAAC;AAAAxC,OAAA,CAAAmD,QAAA,GAAAA,QAAA"}
@@ -0,0 +1,63 @@
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 type * as RxRef from "@effect-rx/rx/RxRef";
7
+ import type { InjectionKey, Ref } from "vue";
8
+ /**
9
+ * @since 1.0.0
10
+ * @category modules
11
+ */
12
+ export * as Registry from "@effect-rx/rx/Registry";
13
+ /**
14
+ * @since 1.0.0
15
+ * @category modules
16
+ */
17
+ export * as Result from "@effect-rx/rx/Result";
18
+ /**
19
+ * @since 1.0.0
20
+ * @category modules
21
+ */
22
+ export * as Rx from "@effect-rx/rx/Rx";
23
+ /**
24
+ * @since 1.0.0
25
+ * @category modules
26
+ */
27
+ export * as RxRef from "@effect-rx/rx/RxRef";
28
+ /**
29
+ * @since 1.0.0
30
+ * @category registry
31
+ */
32
+ export declare const registryKey: InjectionKey<Registry.Registry>;
33
+ /**
34
+ * @since 1.0.0
35
+ * @category registry
36
+ */
37
+ export declare const defaultRegistry: Registry.Registry;
38
+ /**
39
+ * @since 1.0.0
40
+ * @category registry
41
+ */
42
+ export declare const injectRegistry: () => Registry.Registry;
43
+ /**
44
+ * @since 1.0.0
45
+ * @category composables
46
+ */
47
+ export declare const useRx: <R, W>(rx: Rx.Writable<R, W>) => readonly [Readonly<Ref<R>>, (_: W) => void];
48
+ /**
49
+ * @since 1.0.0
50
+ * @category composables
51
+ */
52
+ export declare const useRxValue: <A>(rx: Rx.Rx<A>) => Readonly<Ref<A>>;
53
+ /**
54
+ * @since 1.0.0
55
+ * @category composables
56
+ */
57
+ export declare const useRxSet: <R, W>(rx: Rx.Writable<R, W>) => (_: W) => void;
58
+ /**
59
+ * @since 1.0.0
60
+ * @category composables
61
+ */
62
+ export declare const useRxRef: <A>(rxRef: RxRef.ReadonlyRef<A>) => Readonly<Ref<A>>;
63
+ //# sourceMappingURL=index.d.ts.map
@@ -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,KAAK,MAAM,qBAAqB,CAAA;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAG5C;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAC9C;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,WAAW,iCAAqD,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,QAGtC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAO,iBAEjC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,yEAAwE,IAAI,CAU7F,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,uCAUtB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,6CAA4C,IAOhE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,sDASpB,CAAA"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Registry from "@effect-rx/rx/Registry";
5
+ import { globalValue } from "effect/GlobalValue";
6
+ import { getCurrentScope, inject, onScopeDispose, ref } from "vue";
7
+ /**
8
+ * @since 1.0.0
9
+ * @category modules
10
+ */
11
+ export * as Registry from "@effect-rx/rx/Registry";
12
+ /**
13
+ * @since 1.0.0
14
+ * @category modules
15
+ */
16
+ export * as Result from "@effect-rx/rx/Result";
17
+ /**
18
+ * @since 1.0.0
19
+ * @category modules
20
+ */
21
+ export * as Rx from "@effect-rx/rx/Rx";
22
+ /**
23
+ * @since 1.0.0
24
+ * @category modules
25
+ */
26
+ export * as RxRef from "@effect-rx/rx/RxRef";
27
+ /**
28
+ * @since 1.0.0
29
+ * @category registry
30
+ */
31
+ export const registryKey = Registry.TypeId;
32
+ /**
33
+ * @since 1.0.0
34
+ * @category registry
35
+ */
36
+ export const defaultRegistry = /*#__PURE__*/globalValue("@effect-rx/rx-vue/defaultRegistry", () => Registry.make());
37
+ /**
38
+ * @since 1.0.0
39
+ * @category registry
40
+ */
41
+ export const injectRegistry = () => {
42
+ return inject(registryKey) ?? defaultRegistry;
43
+ };
44
+ /**
45
+ * @since 1.0.0
46
+ * @category composables
47
+ */
48
+ export const useRx = rx => {
49
+ const registry = injectRegistry();
50
+ const value = ref(registry.get(rx));
51
+ const cancel = registry.subscribe(rx, nextValue => {
52
+ value.value = nextValue;
53
+ });
54
+ if (getCurrentScope()) {
55
+ onScopeDispose(cancel);
56
+ }
57
+ return [value, _ => registry.set(rx, _)];
58
+ };
59
+ /**
60
+ * @since 1.0.0
61
+ * @category composables
62
+ */
63
+ export const useRxValue = rx => {
64
+ const registry = injectRegistry();
65
+ const value = ref(registry.get(rx));
66
+ const cancel = registry.subscribe(rx, nextValue => {
67
+ value.value = nextValue;
68
+ });
69
+ if (getCurrentScope()) {
70
+ onScopeDispose(cancel);
71
+ }
72
+ return value;
73
+ };
74
+ /**
75
+ * @since 1.0.0
76
+ * @category composables
77
+ */
78
+ export const useRxSet = rx => {
79
+ const registry = injectRegistry();
80
+ const cancel = registry.mount(rx);
81
+ if (getCurrentScope()) {
82
+ onScopeDispose(cancel);
83
+ }
84
+ return _ => registry.set(rx, _);
85
+ };
86
+ /**
87
+ * @since 1.0.0
88
+ * @category composables
89
+ */
90
+ export const useRxRef = rxRef => {
91
+ const value = ref(rxRef.value);
92
+ const cancel = rxRef.subscribe(nextValue => {
93
+ value.value = nextValue;
94
+ });
95
+ if (getCurrentScope()) {
96
+ onScopeDispose(cancel);
97
+ }
98
+ return value;
99
+ };
100
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Registry","globalValue","getCurrentScope","inject","onScopeDispose","ref","Result","Rx","RxRef","registryKey","TypeId","defaultRegistry","make","injectRegistry","useRx","rx","registry","value","get","cancel","subscribe","nextValue","_","set","useRxValue","useRxSet","mount","useRxRef","rxRef"],"sources":["../../src/index.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AMC,QAAQ,GAAGH,cAAc,EAAE;EACjC,MAAMI,KAAK,GAAGZ,GAAG,CAAIW,QAAQ,CAACE,GAAG,CAACH,EAAE,CAAC,CAAC;EACtC,MAAMI,MAAM,GAAGH,QAAQ,CAACI,SAAS,CAACL,EAAE,EAAGM,SAAS,IAAI;IAClDJ,KAAK,CAACA,KAAK,GAAGI,SAAgB;EAChC,CAAC,CAAC;EACF,IAAInB,eAAe,EAAE,EAAE;IACrBE,cAAc,CAACe,MAAM,CAAC;EACxB;EACA,OAAOF,KAAyB;AAClC,CAAC;AAED;;;;AAIA,OAAO,MAAMQ,QAAQ,GAAUV,EAAqB,IAAoB;EACtE,MAAMC,QAAQ,GAAGH,cAAc,EAAE;EACjC,MAAMM,MAAM,GAAGH,QAAQ,CAACU,KAAK,CAACX,EAAE,CAAC;EACjC,IAAIb,eAAe,EAAE,EAAE;IACrBE,cAAc,CAACe,MAAM,CAAC;EACxB;EACA,OAAQG,CAAC,IAAKN,QAAQ,CAACO,GAAG,CAACR,EAAE,EAAEO,CAAC,CAAC;AACnC,CAAC;AAED;;;;AAIA,OAAO,MAAMK,QAAQ,GAAOC,KAA2B,IAAsB;EAC3E,MAAMX,KAAK,GAAGZ,GAAG,CAAIuB,KAAK,CAACX,KAAK,CAAC;EACjC,MAAME,MAAM,GAAGS,KAAK,CAACR,SAAS,CAAEC,SAAS,IAAI;IAC3CJ,KAAK,CAACA,KAAK,GAAGI,SAAgB;EAChC,CAAC,CAAC;EACF,IAAInB,eAAe,EAAE,EAAE;IACrBE,cAAc,CAACe,MAAM,CAAC;EACxB;EACA,OAAOF,KAAyB;AAClC,CAAC"}
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": []
4
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@effect-rx/rx-vue",
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
+ "sideEffects": [],
11
+ "author": "Effect contributors",
12
+ "dependencies": {
13
+ "@effect-rx/rx": "^0.22.1"
14
+ },
15
+ "peerDependencies": {
16
+ "effect": "^2.0.0",
17
+ "vue": "^3.4"
18
+ },
19
+ "main": "./dist/cjs/index.js",
20
+ "module": "./dist/esm/index.js",
21
+ "types": "./dist/dts/index.d.ts",
22
+ "exports": {
23
+ "./package.json": "./package.json",
24
+ ".": {
25
+ "types": "./dist/dts/index.d.ts",
26
+ "import": "./dist/esm/index.js",
27
+ "default": "./dist/cjs/index.js"
28
+ }
29
+ }
30
+ }
package/src/index.ts ADDED
@@ -0,0 +1,113 @@
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 type * as RxRef from "@effect-rx/rx/RxRef"
7
+ import { globalValue } from "effect/GlobalValue"
8
+ import type { InjectionKey, Ref } from "vue"
9
+ import { getCurrentScope, inject, onScopeDispose, ref } from "vue"
10
+
11
+ /**
12
+ * @since 1.0.0
13
+ * @category modules
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
24
+ */
25
+ export * as Rx from "@effect-rx/rx/Rx"
26
+ /**
27
+ * @since 1.0.0
28
+ * @category modules
29
+ */
30
+ export * as RxRef from "@effect-rx/rx/RxRef"
31
+
32
+ /**
33
+ * @since 1.0.0
34
+ * @category registry
35
+ */
36
+ export const registryKey = Registry.TypeId as InjectionKey<Registry.Registry>
37
+
38
+ /**
39
+ * @since 1.0.0
40
+ * @category registry
41
+ */
42
+ export const defaultRegistry: Registry.Registry = globalValue(
43
+ "@effect-rx/rx-vue/defaultRegistry",
44
+ () => Registry.make()
45
+ )
46
+
47
+ /**
48
+ * @since 1.0.0
49
+ * @category registry
50
+ */
51
+ export const injectRegistry = (): Registry.Registry => {
52
+ return inject(registryKey) ?? defaultRegistry
53
+ }
54
+
55
+ /**
56
+ * @since 1.0.0
57
+ * @category composables
58
+ */
59
+ export const useRx = <R, W>(rx: Rx.Writable<R, W>): readonly [Readonly<Ref<R>>, (_: W) => void] => {
60
+ const registry = injectRegistry()
61
+ const value = ref<R>(registry.get(rx))
62
+ const cancel = registry.subscribe(rx, (nextValue) => {
63
+ value.value = nextValue as any
64
+ })
65
+ if (getCurrentScope()) {
66
+ onScopeDispose(cancel)
67
+ }
68
+ return [value as Readonly<Ref<R>>, (_) => registry.set(rx, _)]
69
+ }
70
+
71
+ /**
72
+ * @since 1.0.0
73
+ * @category composables
74
+ */
75
+ export const useRxValue = <A>(rx: Rx.Rx<A>): Readonly<Ref<A>> => {
76
+ const registry = injectRegistry()
77
+ const value = ref<A>(registry.get(rx))
78
+ const cancel = registry.subscribe(rx, (nextValue) => {
79
+ value.value = nextValue as any
80
+ })
81
+ if (getCurrentScope()) {
82
+ onScopeDispose(cancel)
83
+ }
84
+ return value as Readonly<Ref<A>>
85
+ }
86
+
87
+ /**
88
+ * @since 1.0.0
89
+ * @category composables
90
+ */
91
+ export const useRxSet = <R, W>(rx: Rx.Writable<R, W>): (_: W) => void => {
92
+ const registry = injectRegistry()
93
+ const cancel = registry.mount(rx)
94
+ if (getCurrentScope()) {
95
+ onScopeDispose(cancel)
96
+ }
97
+ return (_) => registry.set(rx, _)
98
+ }
99
+
100
+ /**
101
+ * @since 1.0.0
102
+ * @category composables
103
+ */
104
+ export const useRxRef = <A>(rxRef: RxRef.ReadonlyRef<A>): Readonly<Ref<A>> => {
105
+ const value = ref<A>(rxRef.value)
106
+ const cancel = rxRef.subscribe((nextValue) => {
107
+ value.value = nextValue as any
108
+ })
109
+ if (getCurrentScope()) {
110
+ onScopeDispose(cancel)
111
+ }
112
+ return value as Readonly<Ref<A>>
113
+ }