@effect-rx/rx-react 0.1.0 → 0.1.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/index.d.ts CHANGED
@@ -4,6 +4,9 @@
4
4
  import * as Registry from "@effect-rx/rx/Registry";
5
5
  import type * as Rx from "@effect-rx/rx/Rx";
6
6
  import * as React from "react";
7
+ export * as Registry from "@effect-rx/rx/Registry";
8
+ export * as Result from "@effect-rx/rx/Result";
9
+ export * as Rx from "@effect-rx/rx/Rx";
7
10
  /**
8
11
  * @since 1.0.0
9
12
  * @category context
@@ -19,9 +22,19 @@ export declare const useRxValue: <A>(rx: Rx.Rx<A>) => A;
19
22
  * @category hooks
20
23
  */
21
24
  export declare const useSetRx: <R, W>(rx: Rx.Writeable<R, W>) => (_: W) => void;
25
+ /**
26
+ * @since 1.0.0
27
+ * @category hooks
28
+ */
29
+ export declare const useUpdateRx: <R, W>(rx: Rx.Writeable<R, W>) => (f: (_: R) => W) => void;
22
30
  /**
23
31
  * @since 1.0.0
24
32
  * @category hooks
25
33
  */
26
34
  export declare const useRx: <R, W>(rx: Rx.Writeable<R, W>) => readonly [R, (_: W) => void];
35
+ /**
36
+ * @since 1.0.0
37
+ * @category hooks
38
+ */
39
+ export declare const useRxUpdate: <R, W>(rx: Rx.Writeable<R, W>) => readonly [R, (f: (_: R) => W) => void];
27
40
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +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"}
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,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAEtC;;;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,WAAW,wDAAuD,IAG9E,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,2DAA0D,IAAI,CAIpE,CAAA;AAEZ;;;GAGG;AACH,eAAO,MAAM,WAAW,qEAAoE,IAAI,CAIpF,CAAA"}
package/index.js CHANGED
@@ -3,9 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useSetRx = exports.useRxValue = exports.useRx = exports.RegistryContext = void 0;
6
+ exports.useUpdateRx = exports.useSetRx = exports.useRxValue = exports.useRxUpdate = exports.useRx = exports.Rx = exports.Result = exports.RegistryContext = exports.Registry = void 0;
7
7
  var Registry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Registry"));
8
+ var Registry_1 = Registry;
9
+ exports.Registry = Registry;
8
10
  var React = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
11
+ var Result_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Result"));
12
+ exports.Result = Result_1;
13
+ var Rx_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Rx"));
14
+ exports.Rx = Rx_1;
9
15
  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
16
  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
17
  /**
@@ -22,7 +28,6 @@ class RxStore {
22
28
  constructor(registry, rx) {
23
29
  this.registry = registry;
24
30
  this.rx = rx;
25
- this.value = this.registry.get(this.rx);
26
31
  this.subscribe = f => {
27
32
  this.value = this.registry.get(this.rx);
28
33
  return this.registry.subscribe(this.rx, a => {
@@ -40,7 +45,7 @@ class RxStore {
40
45
  const useRxValue = rx => {
41
46
  const registry = React.useContext(RegistryContext);
42
47
  const store = React.useRef(undefined);
43
- if (store.current === undefined) {
48
+ if (store.current?.rx !== rx || store.current?.registry !== registry) {
44
49
  store.current = new RxStore(registry, rx);
45
50
  }
46
51
  return React.useSyncExternalStore(store.current.subscribe, store.current.snapshot);
@@ -59,6 +64,21 @@ const useSetRx = rx => {
59
64
  * @category hooks
60
65
  */
61
66
  exports.useSetRx = useSetRx;
67
+ const useUpdateRx = rx => {
68
+ const registry = React.useContext(RegistryContext);
69
+ return React.useCallback(f => registry.set(rx, f(registry.get(rx))), [registry, rx]);
70
+ };
71
+ /**
72
+ * @since 1.0.0
73
+ * @category hooks
74
+ */
75
+ exports.useUpdateRx = useUpdateRx;
62
76
  const useRx = rx => [useRxValue(rx), useSetRx(rx)];
77
+ /**
78
+ * @since 1.0.0
79
+ * @category hooks
80
+ */
63
81
  exports.useRx = useRx;
82
+ const useRxUpdate = rx => [useRxValue(rx), useUpdateRx(rx)];
83
+ exports.useRxUpdate = useRxUpdate;
64
84
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +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,CAAA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AAAJ,OAAA,CAAAmB,KAAA,GAAAA,KAAA"}
1
+ {"version":3,"file":"index.js","names":["Registry","_interopRequireWildcard","require","Registry_1","exports","React","Result","Result_1","Rx","Rx_1","_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","RxStore","constructor","registry","rx","subscribe","f","value","a","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","useUpdateRx","useRx","useRxUpdate"],"sources":["./src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAAkD,IAAAC,UAAA,GAAAH,QAAA;AAAAI,OAAA,CAAAJ,QAAA,GAAAA,QAAA;AAElD,IAAAK,KAAA,gBAAAJ,uBAAA,eAAAC,OAAA;;AAG8CE,OAAA,CAAAE,MAAA,GAAAC,QAAA;;AACRH,OAAA,CAAAI,EAAA,GAAAC,IAAA;AAAA,SAAAC,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,SAAAV,wBAAAc,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,GAAA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MC,KAAK,GAAUhB,EAAsB,IAChD,CACEM,UAAU,CAACN,EAAE,CAAC,EACda,QAAQ,CAACb,EAAE,CAAC,CACJ;AAEZ;;;;AAAAlC,OAAA,CAAAkD,KAAA,GAAAA,KAAA;AAIO,MAAMC,WAAW,GAAUjB,EAAsB,IACtD,CACEM,UAAU,CAACN,EAAE,CAAC,EACde,WAAW,CAACf,EAAE,CAAC,CACP;AAAAlC,OAAA,CAAAmD,WAAA,GAAAA,WAAA"}
package/mjs/index.mjs CHANGED
@@ -3,6 +3,12 @@
3
3
  */
4
4
  import * as Registry from "@effect-rx/rx/Registry";
5
5
  import * as React from "react";
6
+ import * as Registry_1 from "@effect-rx/rx/Registry";
7
+ export { Registry_1 as Registry };
8
+ import * as Result_1 from "@effect-rx/rx/Result";
9
+ export { Result_1 as Result };
10
+ import * as Rx_1 from "@effect-rx/rx/Rx";
11
+ export { Rx_1 as Rx };
6
12
  /**
7
13
  * @since 1.0.0
8
14
  * @category context
@@ -12,7 +18,6 @@ class RxStore {
12
18
  constructor(registry, rx) {
13
19
  this.registry = registry;
14
20
  this.rx = rx;
15
- this.value = this.registry.get(this.rx);
16
21
  this.subscribe = f => {
17
22
  this.value = this.registry.get(this.rx);
18
23
  return this.registry.subscribe(this.rx, a => {
@@ -30,7 +35,7 @@ class RxStore {
30
35
  export const useRxValue = rx => {
31
36
  const registry = React.useContext(RegistryContext);
32
37
  const store = React.useRef(undefined);
33
- if (store.current === undefined) {
38
+ if (store.current?.rx !== rx || store.current?.registry !== registry) {
34
39
  store.current = new RxStore(registry, rx);
35
40
  }
36
41
  return React.useSyncExternalStore(store.current.subscribe, store.current.snapshot);
@@ -43,9 +48,22 @@ export const useSetRx = rx => {
43
48
  const registry = React.useContext(RegistryContext);
44
49
  return React.useCallback(value => registry.set(rx, value), [registry, rx]);
45
50
  };
51
+ /**
52
+ * @since 1.0.0
53
+ * @category hooks
54
+ */
55
+ export const useUpdateRx = rx => {
56
+ const registry = React.useContext(RegistryContext);
57
+ return React.useCallback(f => registry.set(rx, f(registry.get(rx))), [registry, rx]);
58
+ };
46
59
  /**
47
60
  * @since 1.0.0
48
61
  * @category hooks
49
62
  */
50
63
  export const useRx = rx => [useRxValue(rx), useSetRx(rx)];
64
+ /**
65
+ * @since 1.0.0
66
+ * @category hooks
67
+ */
68
+ export const useRxUpdate = rx => [useRxValue(rx), useUpdateRx(rx)];
51
69
  //# sourceMappingURL=index.mjs.map
package/mjs/index.mjs.map CHANGED
@@ -1 +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,KAAK,MAAM,OAAO;AAE9B;;;;AAIA,OAAO,MAAMC,eAAe,gBAAGD,KAAK,CAACE,aAAa,eAAoBH,QAAQ,CAACI,IAAI,EAAE,CAAC;AAEtF,MAAMC,OAAO;EACXC,YACWC,QAA2B,EAC3BC,EAAY;IADZ,KAAAD,QAAQ,GAARA,QAAQ;IACR,KAAAC,EAAE,GAAFA,EAAE;IAGb,KAAAC,KAAK,GAAG,IAAI,CAACF,QAAQ,CAACG,GAAG,CAAC,IAAI,CAACF,EAAE,CAAC;IAElC,KAAAG,SAAS,GAAIC,CAAa,IAAgB;MACxC,IAAI,CAACH,KAAK,GAAG,IAAI,CAACF,QAAQ,CAACG,GAAG,CAAC,IAAI,CAACF,EAAE,CAAC;MACvC,OAAO,IAAI,CAACD,QAAQ,CAACI,SAAS,CAAC,IAAI,CAACH,EAAE,EAAGK,CAAC,IAAI;QAC5C,IAAI,CAACJ,KAAK,GAAGI,CAAC;QACdD,CAAC,EAAE;MACL,CAAC,CAAC;IACJ,CAAC;IAED,KAAAE,QAAQ,GAAG,MAAS,IAAI,CAACL,KAAK;EAZ3B;;AAeL;;;;AAIA,OAAO,MAAMM,UAAU,GAAOP,EAAY,IAAO;EAC/C,MAAMD,QAAQ,GAAGN,KAAK,CAACe,UAAU,CAACd,eAAe,CAAC;EAClD,MAAMe,KAAK,GAAGhB,KAAK,CAACiB,MAAM,CAAaC,SAAgB,CAAC;EACxD,IAAIF,KAAK,CAACG,OAAO,KAAKD,SAAS,EAAE;IAC/BF,KAAK,CAACG,OAAO,GAAG,IAAIf,OAAO,CAACE,QAAQ,EAAEC,EAAE,CAAC;;EAE3C,OAAOP,KAAK,CAACoB,oBAAoB,CAACJ,KAAK,CAACG,OAAO,CAACT,SAAS,EAAEM,KAAK,CAACG,OAAO,CAACN,QAAQ,CAAC;AACpF,CAAC;AAED;;;;AAIA,OAAO,MAAMQ,QAAQ,GAAUd,EAAsB,IAAoB;EACvE,MAAMD,QAAQ,GAAGN,KAAK,CAACe,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"}
1
+ {"version":3,"file":"index.mjs","names":["Registry","React","Result","Rx","RegistryContext","createContext","make","RxStore","constructor","registry","rx","subscribe","f","value","get","a","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","set","useUpdateRx","useRx","useRxUpdate"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,QAAQ,MAAM,wBAAwB;AAElD,OAAO,KAAKC,KAAK,MAAM,OAAO;4BAEJ,wBAAwB;uBAAtCD,QAAQ;0BACI,sBAAsB;q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AAK,CAACiB,UAAU,CAACd,eAAe,CAAC;EAClD,OAAOH,KAAK,CAACwB,WAAW,CAAEZ,KAAK,IAAKJ,QAAQ,CAACiB,GAAG,CAAChB,EAAE,EAAEG,KAAK,CAAC,EAAE,CAACJ,QAAQ,EAAEC,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;;AAIA,OAAO,MAAMiB,WAAW,GAAUjB,EAAsB,IAA8B;EACpF,MAAMD,QAAQ,GAAGR,KAAK,CAACiB,UAAU,CAACd,eAAe,CAAC;EAClD,OAAOH,KAAK,CAACwB,WAAW,CAAEb,CAAC,IAAKH,QAAQ,CAACiB,GAAG,CAAChB,EAAE,EAAEE,CAAC,CAACH,QAAQ,CAACK,GAAG,CAACJ,EAAE,CAAC,CAAC,CAAC,EAAE,CAACD,QAAQ,EAAEC,EAAE,CAAC,CAAC;AACxF,CAAC;AAED;;;;AAIA,OAAO,MAAMkB,KAAK,GAAUlB,EAAsB,IAChD,CACEO,UAAU,CAACP,EAAE,CAAC,EACdc,QAAQ,CAACd,EAAE,CAAC,CACJ;AAEZ;;;;AAIA,OAAO,MAAMmB,WAAW,GAAUnB,EAAsB,IACtD,CACEO,UAAU,CAACP,EAAE,CAAC,EACdiB,WAAW,CAACjB,EAAE,CAAC,CACP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-rx/rx-react",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Reactive toolkit for Effect",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "sideEffects": [],
36
36
  "author": "Effect contributors",
37
37
  "dependencies": {
38
- "@effect-rx/rx": "^0.1.0"
38
+ "@effect-rx/rx": "^0.1.2"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@effect/data": "^0.18.5",
package/src/index.ts CHANGED
@@ -5,6 +5,10 @@ import * as Registry from "@effect-rx/rx/Registry"
5
5
  import type * as Rx from "@effect-rx/rx/Rx"
6
6
  import * as React from "react"
7
7
 
8
+ export * as Registry from "@effect-rx/rx/Registry"
9
+ export * as Result from "@effect-rx/rx/Result"
10
+ export * as Rx from "@effect-rx/rx/Rx"
11
+
8
12
  /**
9
13
  * @since 1.0.0
10
14
  * @category context
@@ -17,7 +21,7 @@ class RxStore<A> {
17
21
  readonly rx: Rx.Rx<A>
18
22
  ) {}
19
23
 
20
- value = this.registry.get(this.rx)
24
+ value!: A
21
25
 
22
26
  subscribe = (f: () => void): () => void => {
23
27
  this.value = this.registry.get(this.rx)
@@ -37,7 +41,7 @@ class RxStore<A> {
37
41
  export const useRxValue = <A>(rx: Rx.Rx<A>): A => {
38
42
  const registry = React.useContext(RegistryContext)
39
43
  const store = React.useRef<RxStore<A>>(undefined as any)
40
- if (store.current === undefined) {
44
+ if (store.current?.rx !== rx || store.current?.registry !== registry) {
41
45
  store.current = new RxStore(registry, rx)
42
46
  }
43
47
  return React.useSyncExternalStore(store.current.subscribe, store.current.snapshot)
@@ -56,7 +60,27 @@ export const useSetRx = <R, W>(rx: Rx.Writeable<R, W>): (_: W) => void => {
56
60
  * @since 1.0.0
57
61
  * @category hooks
58
62
  */
59
- export const useRx = <R, W>(rx: Rx.Writeable<R, W>): readonly [R, (_: W) => void] => [
60
- useRxValue(rx),
61
- useSetRx(rx)
62
- ]
63
+ export const useUpdateRx = <R, W>(rx: Rx.Writeable<R, W>): (f: (_: R) => W) => void => {
64
+ const registry = React.useContext(RegistryContext)
65
+ return React.useCallback((f) => registry.set(rx, f(registry.get(rx))), [registry, rx])
66
+ }
67
+
68
+ /**
69
+ * @since 1.0.0
70
+ * @category hooks
71
+ */
72
+ export const useRx = <R, W>(rx: Rx.Writeable<R, W>): readonly [R, (_: W) => void] =>
73
+ [
74
+ useRxValue(rx),
75
+ useSetRx(rx)
76
+ ] as const
77
+
78
+ /**
79
+ * @since 1.0.0
80
+ * @category hooks
81
+ */
82
+ export const useRxUpdate = <R, W>(rx: Rx.Writeable<R, W>): readonly [R, (f: (_: R) => W) => void] =>
83
+ [
84
+ useRxValue(rx),
85
+ useUpdateRx(rx)
86
+ ] as const
package/Registry.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- export * from "@effect-rx/rx/Registry";
5
- //# sourceMappingURL=Registry.d.ts.map
package/Registry.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["./src/Registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,wBAAwB,CAAA"}
package/Registry.js DELETED
@@ -1,17 +0,0 @@
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
package/Registry.js.map DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- export * from "@effect-rx/rx/Result";
5
- //# sourceMappingURL=Result.d.ts.map
package/Result.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["./src/Result.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,sBAAsB,CAAA"}
package/Result.js DELETED
@@ -1,17 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Rx.d.ts","sourceRoot":"","sources":["./src/Rx.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAA"}
package/Rx.js DELETED
@@ -1,17 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
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/mjs/Registry.mjs DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- export * from "@effect-rx/rx/Registry";
5
- //# sourceMappingURL=Registry.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Registry.mjs","names":[],"sources":["../src/Registry.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA,cAAc,wBAAwB"}
package/mjs/Result.mjs DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- export * from "@effect-rx/rx/Result";
5
- //# sourceMappingURL=Result.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Result.mjs","names":[],"sources":["../src/Result.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA,cAAc,sBAAsB"}
package/mjs/Rx.mjs DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- export * from "@effect-rx/rx/Rx";
5
- //# sourceMappingURL=Rx.mjs.map
package/mjs/Rx.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Rx.mjs","names":[],"sources":["../src/Rx.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA,cAAc,kBAAkB"}
package/src/Registry.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- export * from "@effect-rx/rx/Registry"
package/src/Result.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- export * from "@effect-rx/rx/Result"
package/src/Rx.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- export * from "@effect-rx/rx/Rx"