rask-ui 0.26.0 → 0.27.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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/useLookup.d.ts +2 -0
- package/dist/useLookup.d.ts.map +1 -0
- package/dist/useLookup.js +22 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ export { useAsync, Async } from "./useAsync";
|
|
|
7
7
|
export { useAction, Action } from "./useAction";
|
|
8
8
|
export { useSuspend } from "./useSuspend";
|
|
9
9
|
export { useCatchError } from "./useCatchError";
|
|
10
|
-
export { useRef } from "./useRef";
|
|
10
|
+
export { useRef, assignRef, Ref } from "./useRef";
|
|
11
11
|
export { useView } from "./useView";
|
|
12
12
|
export { useEffect } from "./useEffect";
|
|
13
13
|
export { useDerived, Derived } from "./useDerived";
|
|
14
14
|
export { syncBatch } from "./batch";
|
|
15
15
|
export { inspect } from "./inspect";
|
|
16
16
|
export { Router, useRouter } from "./useRouter";
|
|
17
|
+
export { useLookup } from "./useLookup";
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,11 @@ export { useAsync } from "./useAsync";
|
|
|
8
8
|
export { useAction } from "./useAction";
|
|
9
9
|
export { useSuspend } from "./useSuspend";
|
|
10
10
|
export { useCatchError } from "./useCatchError";
|
|
11
|
-
export { useRef } from "./useRef";
|
|
11
|
+
export { useRef, assignRef } from "./useRef";
|
|
12
12
|
export { useView } from "./useView";
|
|
13
13
|
export { useEffect } from "./useEffect";
|
|
14
14
|
export { useDerived } from "./useDerived";
|
|
15
15
|
export { syncBatch } from "./batch";
|
|
16
16
|
export { inspect } from "./inspect";
|
|
17
17
|
export { useRouter } from "./useRouter";
|
|
18
|
+
export { useLookup } from "./useLookup";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLookup.d.ts","sourceRoot":"","sources":["../src/useLookup.ts"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAC3D,QAAQ,EAAE,MAAM,CAAC,EAAE,EACnB,GAAG,EAAE,CAAC,IAsBE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAG,CAAC,GAAG,SAAS,CAGlC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useCleanup } from "./component";
|
|
2
|
+
import { Observer } from "./observation";
|
|
3
|
+
import { useState } from "./useState";
|
|
4
|
+
export function useLookup(getArray, key) {
|
|
5
|
+
const state = useState({
|
|
6
|
+
lookup: {},
|
|
7
|
+
});
|
|
8
|
+
function updateMap() {
|
|
9
|
+
const disposeObserve = observer.observe();
|
|
10
|
+
state.lookup = getArray().reduce((aggr, item) => {
|
|
11
|
+
aggr[item[key]] = item;
|
|
12
|
+
return aggr;
|
|
13
|
+
}, {});
|
|
14
|
+
disposeObserve();
|
|
15
|
+
}
|
|
16
|
+
const observer = new Observer(updateMap, false);
|
|
17
|
+
updateMap();
|
|
18
|
+
useCleanup(() => observer.dispose());
|
|
19
|
+
return (key) => {
|
|
20
|
+
return state.lookup[key];
|
|
21
|
+
};
|
|
22
|
+
}
|