chem-rx 0.0.13 → 0.0.14
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/dist/useSelectAtom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseAtom, NullableBaseAtom } from "./Atom";
|
|
2
|
-
export declare function useSelectAtom<T extends
|
|
3
|
-
[key in K]:
|
|
4
|
-
}, K extends keyof V>(atom: T
|
|
2
|
+
export declare function useSelectAtom<T extends {
|
|
3
|
+
[key in K]: V;
|
|
4
|
+
}, K extends keyof T, V = T[K]>(atom: NullableBaseAtom<T> | BaseAtom<T>, key: K): T[K];
|
|
5
5
|
//# sourceMappingURL=useSelectAtom.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectAtom.d.ts","sourceRoot":"","sources":["../src/useSelectAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAEpD,wBAAgB,aAAa,CAC3B,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"useSelectAtom.d.ts","sourceRoot":"","sources":["../src/useSelectAtom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAEpD,wBAAgB,aAAa,CAC3B,CAAC,SAAS;KACP,GAAG,IAAI,CAAC,GAAG,CAAC;CACd,EACD,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACR,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAcvD"}
|
package/package.json
CHANGED
package/src/useSelectAtom.ts
CHANGED
|
@@ -2,17 +2,17 @@ import { useEffect, useState } from "react";
|
|
|
2
2
|
import { BaseAtom, NullableBaseAtom } from "./Atom";
|
|
3
3
|
|
|
4
4
|
export function useSelectAtom<
|
|
5
|
-
T extends
|
|
6
|
-
|
|
7
|
-
[key in K]: infer W;
|
|
5
|
+
T extends {
|
|
6
|
+
[key in K]: V;
|
|
8
7
|
},
|
|
9
|
-
K extends keyof
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
K extends keyof T,
|
|
9
|
+
V = T[K]
|
|
10
|
+
>(atom: NullableBaseAtom<T> | BaseAtom<T>, key: K): T[K] {
|
|
11
|
+
const [value, setValue] = useState<T[K]>(atom.get(key)!);
|
|
12
12
|
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
const subscription = atom.select(key).subscribe((val) => {
|
|
15
|
-
setValue(val as
|
|
15
|
+
setValue(val as T[K]);
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
return () => {
|
package/tests/atom.test.ts
CHANGED
|
@@ -449,7 +449,8 @@ test("Test select nullable object", () => {
|
|
|
449
449
|
};
|
|
450
450
|
}>();
|
|
451
451
|
|
|
452
|
-
//
|
|
452
|
+
// TODO: This errors
|
|
453
|
+
const newVal = nestedData.select("stacy");
|
|
453
454
|
|
|
454
455
|
nestedData.next(seedData);
|
|
455
456
|
const stacy = nestedData.select("stacy");
|