Update to Immer 9 for better type inference
Summary: Per title Reviewed By: passy Differential Revision: D27202660 fbshipit-source-id: 074c44275a93c3fb35d2f491b51d82aa9792dd70
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8f90deda55
commit
ea0cc7f15b
@@ -36,7 +36,7 @@
|
||||
"flipper-plugin": "0.0.0",
|
||||
"flipper-plugin-lib": "0.0.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"immer": "^8.0.1",
|
||||
"immer": "^9.0.0",
|
||||
"immutable": "^4.0.0-rc.12",
|
||||
"invariant": "^2.2.2",
|
||||
"lodash": "^4.17.19",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"dependencies": {
|
||||
"@emotion/css": "^11.0.0",
|
||||
"@emotion/react": "^11.1.1",
|
||||
"immer": "^8.0.1",
|
||||
"immer": "^9.0.0",
|
||||
"lodash": "^4.17.20",
|
||||
"react-element-to-jsx-string": "^14.3.2",
|
||||
"react-virtual": "^2.4.0"
|
||||
|
||||
@@ -87,7 +87,7 @@ type OutputChange =
|
||||
};
|
||||
|
||||
export class DataSource<
|
||||
T,
|
||||
T = any,
|
||||
KEY extends keyof T = any,
|
||||
KEY_TYPE extends string | number | never = ExtractKeyType<T, KEY>
|
||||
> implements Persistable {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {Percentage} from '../../utils/widthUtils';
|
||||
import {MutableRefObject, Reducer} from 'react';
|
||||
import {DataSource} from '../../state/DataSource';
|
||||
import {DataSourceVirtualizer} from './DataSourceRenderer';
|
||||
import produce, {immerable, original} from 'immer';
|
||||
import produce, {castDraft, immerable, original} from 'immer';
|
||||
|
||||
export type OnColumnResize = (id: string, size: number | Percentage) => void;
|
||||
export type Sorting<T = any> = {
|
||||
@@ -107,17 +107,17 @@ export type DataTableReducer<T> = Reducer<
|
||||
>;
|
||||
export type DataTableDispatch<T = any> = React.Dispatch<DataManagerActions<T>>;
|
||||
|
||||
export const dataTableManagerReducer = produce(function <T>(
|
||||
draft: DataManagerState<T>,
|
||||
action: DataManagerActions<T>,
|
||||
) {
|
||||
export const dataTableManagerReducer = produce<
|
||||
DataManagerState<any>,
|
||||
[DataManagerActions<any>]
|
||||
>(function (draft, action) {
|
||||
const config = original(draft.config)!;
|
||||
switch (action.type) {
|
||||
case 'reset': {
|
||||
draft.columns = computeInitialColumns(config.defaultColumns);
|
||||
draft.sorting = undefined;
|
||||
draft.searchValue = '';
|
||||
draft.selection = emptySelection;
|
||||
draft.selection = castDraft(emptySelection);
|
||||
break;
|
||||
}
|
||||
case 'resizeColumn': {
|
||||
@@ -151,25 +151,20 @@ export const dataTableManagerReducer = produce(function <T>(
|
||||
}
|
||||
case 'selectItem': {
|
||||
const {nextIndex, addToSelection} = action;
|
||||
draft.selection = computeSetSelection(
|
||||
draft.selection,
|
||||
nextIndex,
|
||||
addToSelection,
|
||||
draft.selection = castDraft(
|
||||
computeSetSelection(draft.selection, nextIndex, addToSelection),
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'addRangeToSelection': {
|
||||
const {start, end, allowUnselect} = action;
|
||||
draft.selection = computeAddRangeToSelection(
|
||||
draft.selection,
|
||||
start,
|
||||
end,
|
||||
allowUnselect,
|
||||
draft.selection = castDraft(
|
||||
computeAddRangeToSelection(draft.selection, start, end, allowUnselect),
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'clearSelection': {
|
||||
draft.selection = emptySelection;
|
||||
draft.selection = castDraft(emptySelection);
|
||||
break;
|
||||
}
|
||||
case 'addColumnFilter': {
|
||||
@@ -195,7 +190,10 @@ export const dataTableManagerReducer = produce(function <T>(
|
||||
break;
|
||||
}
|
||||
case 'setColumnFilterFromSelection': {
|
||||
const items = getSelectedItems(config.dataSource, draft.selection);
|
||||
const items = getSelectedItems(
|
||||
config.dataSource as DataSource,
|
||||
draft.selection,
|
||||
);
|
||||
items.forEach((item, index) => {
|
||||
addColumnFilter(
|
||||
draft.columns,
|
||||
@@ -214,7 +212,7 @@ export const dataTableManagerReducer = produce(function <T>(
|
||||
throw new Error('Unknown action ' + (action as any).type);
|
||||
}
|
||||
}
|
||||
}) as any;
|
||||
});
|
||||
|
||||
/**
|
||||
* Public only imperative convienience API for DataTable
|
||||
|
||||
@@ -6765,10 +6765,10 @@ immediate@~3.0.5:
|
||||
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
|
||||
integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=
|
||||
|
||||
immer@^8.0.1:
|
||||
version "8.0.1"
|
||||
resolved "https://registry.yarnpkg.com/immer/-/immer-8.0.1.tgz#9c73db683e2b3975c424fb0572af5889877ae656"
|
||||
integrity sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA==
|
||||
immer@^9.0.0:
|
||||
version "9.0.1"
|
||||
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.1.tgz#1116368e051f9a0fd188c5136b6efb74ed69c57f"
|
||||
integrity sha512-7CCw1DSgr8kKYXTYOI1qMM/f5qxT5vIVMeGLDCDX8CSxsggr1Sjdoha4OhsP0AZ1UvWbyZlILHvLjaynuu02Mg==
|
||||
|
||||
immutable@^4.0.0-rc.12:
|
||||
version "4.0.0-rc.12"
|
||||
|
||||
Reference in New Issue
Block a user