mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
* CB-6308 fix: grid auto-size * CB-6308 fix: grid auto size * CB-6308 fix: icons sizing in grid * CB-6308 fix: grid header * CB-6308 fix: types * fix: min-width for columns --------- Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com> Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useMemo, useSyncExternalStore } from 'react';
|
|
import type { IGridReactiveValue } from './IGridReactiveValue.js';
|
|
|
|
export function useGridReactiveValue<P extends IGridReactiveValue<any, any[]> | undefined>(
|
|
value: P,
|
|
...args: P extends IGridReactiveValue<any, infer T> ? T : never[]
|
|
): P extends IGridReactiveValue<infer T, any[]> ? T : undefined {
|
|
const mappedValue = useMemo(
|
|
() => ({
|
|
cache: null as any,
|
|
cacheInvalidated: true,
|
|
subscribe: (onValueChange: () => void) => {
|
|
if (value) {
|
|
return value.subscribe(
|
|
() => {
|
|
mappedValue.cacheInvalidated = true;
|
|
return onValueChange();
|
|
},
|
|
...args,
|
|
);
|
|
}
|
|
|
|
return () => {};
|
|
},
|
|
get: () => {
|
|
if (mappedValue.cacheInvalidated) {
|
|
mappedValue.cache = value?.get(...args);
|
|
mappedValue.cacheInvalidated = false;
|
|
}
|
|
return mappedValue.cache;
|
|
},
|
|
}),
|
|
[value, ...args],
|
|
);
|
|
return useSyncExternalStore(mappedValue.subscribe, mappedValue.get);
|
|
}
|