@effect-rx/rx-react 0.1.4 → 0.1.5
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 +3 -8
- package/index.d.ts.map +1 -1
- package/index.js +14 -11
- package/index.js.map +1 -1
- package/mjs/index.mjs +12 -8
- package/mjs/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +14 -15
package/index.d.ts
CHANGED
|
@@ -21,20 +21,15 @@ export declare const useRxValue: <A>(rx: Rx.Rx<A>) => A;
|
|
|
21
21
|
* @since 1.0.0
|
|
22
22
|
* @category hooks
|
|
23
23
|
*/
|
|
24
|
-
export declare const useSetRx: <R, W>(rx: Rx.Writeable<R, W>) => (_: W) => void;
|
|
24
|
+
export declare const useSetRx: <R, W>(rx: Rx.Writeable<R, W>) => (_: W | ((_: R) => W)) => void;
|
|
25
25
|
/**
|
|
26
26
|
* @since 1.0.0
|
|
27
27
|
* @category hooks
|
|
28
28
|
*/
|
|
29
|
-
export declare const
|
|
29
|
+
export declare const useRefreshRx: <A>(rx: Rx.Rx<A> & Rx.Refreshable) => () => void;
|
|
30
30
|
/**
|
|
31
31
|
* @since 1.0.0
|
|
32
32
|
* @category hooks
|
|
33
33
|
*/
|
|
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];
|
|
34
|
+
export declare const useRx: <R, W>(rx: Rx.Writeable<R, W>) => readonly [value: R, setOrUpdate: (_: W | ((_: R) => W)) => void];
|
|
40
35
|
//# 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,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;AAwBtF;;;GAGG;AACH,eAAO,MAAM,UAAU,wBAOtB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,
|
|
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;AAwBtF;;;GAGG;AACH,eAAO,MAAM,UAAU,wBAOtB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,8DAA6D,IAUjF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,wCAAuC,MAAM,IAKrE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,+FAA8F,IAAI,CAIxG,CAAA"}
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.useSetRx = exports.useRxValue = exports.useRx = exports.useRefreshRx = exports.Rx = exports.Result = exports.RegistryContext = exports.Registry = void 0;
|
|
7
7
|
var Registry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-rx/rx/Registry"));
|
|
8
8
|
var Registry_1 = Registry;
|
|
9
9
|
exports.Registry = Registry;
|
|
@@ -62,28 +62,31 @@ const useRxValue = rx => {
|
|
|
62
62
|
exports.useRxValue = useRxValue;
|
|
63
63
|
const useSetRx = rx => {
|
|
64
64
|
const registry = React.useContext(RegistryContext);
|
|
65
|
-
return React.useCallback(value =>
|
|
65
|
+
return React.useCallback(value => {
|
|
66
|
+
if (typeof value === "function") {
|
|
67
|
+
registry.set(rx, value(registry.get(rx)));
|
|
68
|
+
return;
|
|
69
|
+
} else {
|
|
70
|
+
registry.set(rx, value);
|
|
71
|
+
}
|
|
72
|
+
}, [registry, rx]);
|
|
66
73
|
};
|
|
67
74
|
/**
|
|
68
75
|
* @since 1.0.0
|
|
69
76
|
* @category hooks
|
|
70
77
|
*/
|
|
71
78
|
exports.useSetRx = useSetRx;
|
|
72
|
-
const
|
|
79
|
+
const useRefreshRx = rx => {
|
|
73
80
|
const registry = React.useContext(RegistryContext);
|
|
74
|
-
return React.useCallback(
|
|
81
|
+
return React.useCallback(() => {
|
|
82
|
+
registry.refresh(rx);
|
|
83
|
+
}, [registry, rx]);
|
|
75
84
|
};
|
|
76
85
|
/**
|
|
77
86
|
* @since 1.0.0
|
|
78
87
|
* @category hooks
|
|
79
88
|
*/
|
|
80
|
-
exports.
|
|
89
|
+
exports.useRefreshRx = useRefreshRx;
|
|
81
90
|
const useRx = rx => [useRxValue(rx), useSetRx(rx)];
|
|
82
|
-
/**
|
|
83
|
-
* @since 1.0.0
|
|
84
|
-
* @category hooks
|
|
85
|
-
*/
|
|
86
91
|
exports.useRx = useRx;
|
|
87
|
-
const useRxUpdate = rx => [useRxValue(rx), useUpdateRx(rx)];
|
|
88
|
-
exports.useRxUpdate = useRxUpdate;
|
|
89
92
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","makeStore","registry","rx","getter","subscribe","f","unmount","subscribeGetter","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","value","
|
|
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","makeStore","registry","rx","getter","subscribe","f","unmount","subscribeGetter","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","value","useRefreshRx","refresh","useRx"],"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,YAAA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AC,CAAC;MAClD;KACD,MAAM;MACLD,QAAQ,CAACL,GAAG,CAACM,EAAE,EAAEgB,KAAK,CAAC;;EAE3B,CAAC,EAAE,CAACjB,QAAQ,EAAEC,EAAE,CAAC,CAAC;AACpB,CAAC;AAED;;;;AAAAjC,OAAA,CAAA+C,QAAA,GAAAA,QAAA;AAIO,MAAMG,YAAY,GAAOjB,EAA6B,IAAgB;EAC3E,MAAMD,QAAQ,GAAG/B,KAAK,CAACwC,UAAU,CAACb,eAAe,CAAC;EAClD,OAAO3B,KAAK,CAAC+C,WAAW,CAAC,MAAK;IAC5BhB,QAAQ,CAACmB,OAAO,CAAClB,EAAE,CAAC;EACtB,CAAC,EAAE,CAACD,QAAQ,EAAEC,EAAE,CAAC,CAAC;AACpB,CAAC;AAED;;;;AAAAjC,OAAA,CAAAkD,YAAA,GAAAA,YAAA;AAIO,MAAME,KAAK,GAAUnB,EAAsB,IAChD,CACEO,UAAU,CAACP,EAAE,CAAC,EACdc,QAAQ,CAACd,EAAE,CAAC,CACJ;AAAAjC,OAAA,CAAAoD,KAAA,GAAAA,KAAA"}
|
package/mjs/index.mjs
CHANGED
|
@@ -51,24 +51,28 @@ export const useRxValue = rx => {
|
|
|
51
51
|
*/
|
|
52
52
|
export const useSetRx = rx => {
|
|
53
53
|
const registry = React.useContext(RegistryContext);
|
|
54
|
-
return React.useCallback(value =>
|
|
54
|
+
return React.useCallback(value => {
|
|
55
|
+
if (typeof value === "function") {
|
|
56
|
+
registry.set(rx, value(registry.get(rx)));
|
|
57
|
+
return;
|
|
58
|
+
} else {
|
|
59
|
+
registry.set(rx, value);
|
|
60
|
+
}
|
|
61
|
+
}, [registry, rx]);
|
|
55
62
|
};
|
|
56
63
|
/**
|
|
57
64
|
* @since 1.0.0
|
|
58
65
|
* @category hooks
|
|
59
66
|
*/
|
|
60
|
-
export const
|
|
67
|
+
export const useRefreshRx = rx => {
|
|
61
68
|
const registry = React.useContext(RegistryContext);
|
|
62
|
-
return React.useCallback(
|
|
69
|
+
return React.useCallback(() => {
|
|
70
|
+
registry.refresh(rx);
|
|
71
|
+
}, [registry, rx]);
|
|
63
72
|
};
|
|
64
73
|
/**
|
|
65
74
|
* @since 1.0.0
|
|
66
75
|
* @category hooks
|
|
67
76
|
*/
|
|
68
77
|
export const useRx = rx => [useRxValue(rx), useSetRx(rx)];
|
|
69
|
-
/**
|
|
70
|
-
* @since 1.0.0
|
|
71
|
-
* @category hooks
|
|
72
|
-
*/
|
|
73
|
-
export const useRxUpdate = rx => [useRxValue(rx), useUpdateRx(rx)];
|
|
74
78
|
//# sourceMappingURL=index.mjs.map
|
package/mjs/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Registry","React","Result","Rx","RegistryContext","createContext","make","makeStore","registry","rx","getter","get","subscribe","f","unmount","subscribeGetter","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","value","set","
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Registry","React","Result","Rx","RegistryContext","createContext","make","makeStore","registry","rx","getter","get","subscribe","f","unmount","subscribeGetter","snapshot","useRxValue","useContext","store","useRef","undefined","current","useSyncExternalStore","useSetRx","useCallback","value","set","useRefreshRx","refresh","useRx"],"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;qBAAlCE,MAAM;sBACE,kBAAkB;iBAA1BC,EAAE;AAEd;;;;AAIA,OAAO,MAAMC,eAAe,gBAAGH,KAAK,CAACI,aAAa,eAAoBL,QAAQ,CAACM,IAAI,EAAE,CAAC;AAStF,SAASC,SAASA,CAAIC,QAA2B,EAAEC,EAAY;EAC7D,IAAIC,MAAM,GAAG,SAAAA,CAAA;IACX,OAAOF,QAAQ,CAACG,GAAG,CAACF,EA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AAEiB,KAAK,CAAC;;EAE3B,CAAC,EAAE,CAAClB,QAAQ,EAAEC,EAAE,CAAC,CAAC;AACpB,CAAC;AAED;;;;AAIA,OAAO,MAAMmB,YAAY,GAAOnB,EAA6B,IAAgB;EAC3E,MAAMD,QAAQ,GAAGP,KAAK,CAACiB,UAAU,CAACd,eAAe,CAAC;EAClD,OAAOH,KAAK,CAACwB,WAAW,CAAC,MAAK;IAC5BjB,QAAQ,CAACqB,OAAO,CAACpB,EAAE,CAAC;EACtB,CAAC,EAAE,CAACD,QAAQ,EAAEC,EAAE,CAAC,CAAC;AACpB,CAAC;AAED;;;;AAIA,OAAO,MAAMqB,KAAK,GAAUrB,EAAsB,IAChD,CACEQ,UAAU,CAACR,EAAE,CAAC,EACde,QAAQ,CAACf,EAAE,CAAC,CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-rx/rx-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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.
|
|
38
|
+
"@effect-rx/rx": "^0.1.5"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@effect/data": "^0.18.5",
|
package/src/index.ts
CHANGED
|
@@ -54,36 +54,35 @@ export const useRxValue = <A>(rx: Rx.Rx<A>): A => {
|
|
|
54
54
|
* @since 1.0.0
|
|
55
55
|
* @category hooks
|
|
56
56
|
*/
|
|
57
|
-
export const useSetRx = <R, W>(rx: Rx.Writeable<R, W>): (_: W) => void => {
|
|
57
|
+
export const useSetRx = <R, W>(rx: Rx.Writeable<R, W>): (_: W | ((_: R) => W)) => void => {
|
|
58
58
|
const registry = React.useContext(RegistryContext)
|
|
59
|
-
return React.useCallback((value) =>
|
|
59
|
+
return React.useCallback((value) => {
|
|
60
|
+
if (typeof value === "function") {
|
|
61
|
+
registry.set(rx, (value as any)(registry.get(rx)))
|
|
62
|
+
return
|
|
63
|
+
} else {
|
|
64
|
+
registry.set(rx, value)
|
|
65
|
+
}
|
|
66
|
+
}, [registry, rx])
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
/**
|
|
63
70
|
* @since 1.0.0
|
|
64
71
|
* @category hooks
|
|
65
72
|
*/
|
|
66
|
-
export const
|
|
73
|
+
export const useRefreshRx = <A>(rx: Rx.Rx<A> & Rx.Refreshable): () => void => {
|
|
67
74
|
const registry = React.useContext(RegistryContext)
|
|
68
|
-
return React.useCallback((
|
|
75
|
+
return React.useCallback(() => {
|
|
76
|
+
registry.refresh(rx)
|
|
77
|
+
}, [registry, rx])
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
/**
|
|
72
81
|
* @since 1.0.0
|
|
73
82
|
* @category hooks
|
|
74
83
|
*/
|
|
75
|
-
export const useRx = <R, W>(rx: Rx.Writeable<R, W>): readonly [R, (_: W) => void] =>
|
|
84
|
+
export const useRx = <R, W>(rx: Rx.Writeable<R, W>): readonly [value: R, setOrUpdate: (_: W | ((_: R) => W)) => void] =>
|
|
76
85
|
[
|
|
77
86
|
useRxValue(rx),
|
|
78
87
|
useSetRx(rx)
|
|
79
88
|
] as const
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @since 1.0.0
|
|
83
|
-
* @category hooks
|
|
84
|
-
*/
|
|
85
|
-
export const useRxUpdate = <R, W>(rx: Rx.Writeable<R, W>): readonly [R, (f: (_: R) => W) => void] =>
|
|
86
|
-
[
|
|
87
|
-
useRxValue(rx),
|
|
88
|
-
useUpdateRx(rx)
|
|
89
|
-
] as const
|