Skip to content

Commit cc1e2c7

Browse files
committed
[types] Missing type in setValue hook
1 parent 9a7342f commit cc1e2c7

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/ui-react.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
CellIdsListener,
3030
CellListener,
3131
MapCell,
32+
MapValue,
3233
Row,
3334
RowIdsListener,
3435
RowListener,
@@ -2088,10 +2089,10 @@ export function useSetPartialValuesCallback<Parameter>(
20882089
*/
20892090
export function useSetValueCallback<Parameter>(
20902091
valueId: Id,
2091-
getValue: (parameter: Parameter, store: Store) => Value,
2092+
getValue: (parameter: Parameter, store: Store) => Value | MapValue,
20922093
getValueDeps?: React.DependencyList,
20932094
storeOrStoreId?: StoreOrStoreId,
2094-
then?: (store: Store, value: Value) => void,
2095+
then?: (store: Store, value: Value | MapValue) => void,
20952096
thenDeps?: React.DependencyList,
20962097
): ParameterizedCallback<Parameter>;
20972098

src/ui-react/hooks.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
CellIdsListener,
2222
CellListener,
2323
MapCell,
24+
MapValue,
2425
Row,
2526
RowIdsListener,
2627
RowListener,
@@ -235,21 +236,21 @@ const useListener = (
235236
// eslint-disable-next-line react-hooks/exhaustive-deps
236237
}, [thing, ...preArgs, ...listenerDeps, ...postArgs]);
237238

238-
const useSetCallback = <Parameter, Value>(
239+
const useSetCallback = <Parameter, Thing>(
239240
storeOrStoreId: StoreOrStoreId | undefined,
240241
settable: string,
241-
get: (parameter: Parameter, store: Store) => Value,
242+
get: (parameter: Parameter, store: Store) => Thing,
242243
getDeps: React.DependencyList = [],
243-
then: (store: Store, value: Value) => void = getUndefined,
244+
then: (store: Store, thing: Thing) => void = getUndefined,
244245
thenDeps: React.DependencyList = [],
245246
...args: Ids
246247
): ParameterizedCallback<Parameter> => {
247248
const store = useStoreOrStoreId(storeOrStoreId);
248249
return useCallback(
249250
(parameter) =>
250251
ifNotUndefined(store, (store: any) =>
251-
ifNotUndefined(get(parameter as any, store), (value: Value) =>
252-
then(store['set' + settable](...args, value), value),
252+
ifNotUndefined(get(parameter as any, store), (thing: Thing) =>
253+
then(store['set' + settable](...args, thing), thing),
253254
),
254255
),
255256
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -534,10 +535,10 @@ export const useSetPartialValuesCallback: typeof useSetPartialValuesCallbackDecl
534535

535536
export const useSetValueCallback: typeof useSetValueCallbackDecl = <Parameter>(
536537
valueId: Id,
537-
getValue: (parameter: Parameter, store: Store) => Value,
538+
getValue: (parameter: Parameter, store: Store) => Value | MapValue,
538539
getValueDeps?: React.DependencyList,
539540
storeOrStoreId?: StoreOrStoreId,
540-
then?: (store: Store, value: Value) => void,
541+
then?: (store: Store, value: Value | MapValue) => void,
541542
thenDeps?: React.DependencyList,
542543
): ParameterizedCallback<Parameter> =>
543544
useSetCallback(

test/unit/hooks.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Checkpoints,
66
Id,
77
MapCell,
8+
MapValue,
89
Persister,
910
Row,
1011
Store,
@@ -2064,13 +2065,13 @@ describe('Write Hooks', () => {
20642065
});
20652066

20662067
test('useSetValueCallback', () => {
2067-
const then = jest.fn((_store?: Store, _value?: Value) => null);
2068+
const then = jest.fn((_store?: Store, _value?: Value | MapValue) => null);
20682069
const Test = ({
20692070
value,
20702071
then,
20712072
}: {
20722073
value: number;
2073-
then: (store?: Store, value?: Value) => void;
2074+
then: (store?: Store, value?: Value | MapValue) => void;
20742075
}) => {
20752076
return (
20762077
<div

0 commit comments

Comments
 (0)