Skip to content

Commit 7fd4ffb

Browse files
committed
[common] getArg
1 parent 074df6d commit 7fd4ffb

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

src/common/other.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export const getUndefined = (): undefined => undefined;
8787

8888
export const noop = () => {};
8989

90+
export const getArg = <T>(value: T): T => value;
91+
9092
export const promiseNew = <Value>(
9193
resolver: (
9294
resolve: (value: Value) => void,

src/ui-react/hooks.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ import {
266266
import {ListenerArgument} from '../common/listeners.ts';
267267
import {IdObj, isObject, objIsEqual} from '../common/obj.ts';
268268
import {
269+
getArg,
269270
getUndefined,
270271
ifNotUndefined,
271272
isFunction,
@@ -651,7 +652,7 @@ export const useTablesState: typeof useTablesStateDecl = (
651652
storeOrStoreId?: StoreOrStoreId,
652653
): [Tables, (tables: Tables) => void] => [
653654
useTables(storeOrStoreId),
654-
useSetTablesCallback((tables) => tables, [], storeOrStoreId),
655+
useSetTablesCallback(getArg, [], storeOrStoreId),
655656
];
656657

657658
export const useTableIds: typeof useTableIdsDecl = (
@@ -687,7 +688,7 @@ export const useTableState: typeof useTableStateDecl = (
687688
storeOrStoreId?: StoreOrStoreId,
688689
): [Table, (table: Table) => void] => [
689690
useTable(tableId, storeOrStoreId),
690-
useSetTableCallback(tableId, (table) => table, [], storeOrStoreId),
691+
useSetTableCallback(tableId, getArg, [], storeOrStoreId),
691692
];
692693

693694
export const useTableCellIds: typeof useTableCellIdsDecl = (
@@ -789,7 +790,7 @@ export const useRowState: typeof useRowStateDecl = (
789790
storeOrStoreId?: StoreOrStoreId,
790791
): [Row, (row: Row) => void] => [
791792
useRow(tableId, rowId, storeOrStoreId),
792-
useSetRowCallback(tableId, rowId, (row) => row, [], storeOrStoreId),
793+
useSetRowCallback(tableId, rowId, getArg, [], storeOrStoreId),
793794
];
794795

795796
export const useCellIds: typeof useCellIdsDecl = (
@@ -836,14 +837,7 @@ export const useCellState: typeof useCellStateDecl = (
836837
storeOrStoreId?: StoreOrStoreId,
837838
): [CellOrUndefined, (cell: Cell) => void] => [
838839
useCell(tableId, rowId, cellId, storeOrStoreId),
839-
useSetCellCallback(
840-
tableId,
841-
rowId,
842-
cellId,
843-
(cell) => cell,
844-
[],
845-
storeOrStoreId,
846-
),
840+
useSetCellCallback(tableId, rowId, cellId, getArg, [], storeOrStoreId),
847841
];
848842

849843
export const useHasValues: typeof useHasValuesDecl = (
@@ -865,7 +859,7 @@ export const useValuesState: typeof useValuesStateDecl = (
865859
storeOrStoreId?: StoreOrStoreId,
866860
): [Values, (values: Values) => void] => [
867861
useValues(storeOrStoreId),
868-
useSetValuesCallback((values) => values, [], storeOrStoreId),
862+
useSetValuesCallback(getArg, [], storeOrStoreId),
869863
];
870864

871865
export const useValueIds: typeof useValueIdsDecl = (
@@ -904,7 +898,7 @@ export const useValueState: typeof useValueStateDecl = (
904898
storeOrStoreId?: StoreOrStoreId,
905899
): [ValueOrUndefined, (value: Value) => void] => [
906900
useValue(valueId, storeOrStoreId),
907-
useSetValueCallback(valueId, (value) => value, [], storeOrStoreId),
901+
useSetValueCallback(valueId, getArg, [], storeOrStoreId),
908902
];
909903

910904
export const useSetTablesCallback: typeof useSetTablesCallbackDecl = <
@@ -2038,7 +2032,7 @@ export const useResultCellListener: typeof useResultCellListenerDecl = (
20382032
export const useParamValues: typeof useParamValuesDecl = (
20392033
queryId: Id,
20402034
queriesOrQueriesId?: QueriesOrQueriesId,
2041-
): ParamValues | undefined =>
2035+
): ParamValues =>
20422036
useListenable(
20432037
'ParamValues',
20442038
useQueriesOrQueriesById(queriesOrQueriesId),
@@ -2049,14 +2043,9 @@ export const useParamValues: typeof useParamValuesDecl = (
20492043
export const useParamValuesState: typeof useParamValuesStateDecl = (
20502044
queryId: Id,
20512045
queriesOrQueriesId?: QueriesOrQueriesId,
2052-
): [ParamValues | undefined, (paramValues: ParamValues) => void] => [
2046+
): [ParamValues, (paramValues: ParamValues) => void] => [
20532047
useParamValues(queryId, queriesOrQueriesId),
2054-
useSetParamValuesCallback(
2055-
queryId,
2056-
(paramValues) => paramValues,
2057-
[],
2058-
queriesOrQueriesId,
2059-
),
2048+
useSetParamValuesCallback(queryId, getArg, [], queriesOrQueriesId),
20602049
];
20612050

20622051
export const useParamValue: typeof useParamValueDecl = (
@@ -2077,13 +2066,7 @@ export const useParamValueState: typeof useParamValueStateDecl = (
20772066
queriesOrQueriesId?: QueriesOrQueriesId,
20782067
): [ParamValue | undefined, (paramValue: ParamValue) => void] => [
20792068
useParamValue(queryId, paramId, queriesOrQueriesId),
2080-
useSetParamValueCallback(
2081-
queryId,
2082-
paramId,
2083-
(paramValue) => paramValue,
2084-
[],
2085-
queriesOrQueriesId,
2086-
),
2069+
useSetParamValueCallback(queryId, paramId, getArg, [], queriesOrQueriesId),
20872070
];
20882071

20892072
export const useParamValuesListener: typeof useParamValuesListenerDecl = (

0 commit comments

Comments
 (0)