Skip to content

Commit 1b7b4d6

Browse files
committed
feat: use ReadonlyArray in props
1 parent 4cf7ec0 commit 1b7b4d6

File tree

15 files changed

+39
-41
lines changed

15 files changed

+39
-41
lines changed

src/Body/BodyRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export interface BodyRowProps<RecordType> {
2424
childrenColumnName: string;
2525
}
2626

27-
function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowProps<RecordType>) {
27+
function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
28+
props: BodyRowProps<RecordType>,
29+
) {
2830
const {
2931
className,
3032
style,

src/Body/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ResizeContext from '../context/ResizeContext';
99
import MeasureCell from './MeasureCell';
1010

1111
export interface BodyProps<RecordType> {
12-
data: RecordType[];
12+
data: readonly RecordType[];
1313
getRowKey: GetRowKey<RecordType>;
1414
measureColumnWidth: boolean;
1515
expandedKeys: Set<Key>;

src/ColGroup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { ColumnType } from './interface';
33
import { INTERNAL_COL_DEFINE } from './utils/legacyUtil';
44

55
export interface ColGroupProps<RecordType> {
6-
colWidths: (number | string)[];
7-
columns?: ColumnType<RecordType>[];
6+
colWidths: readonly (number | string)[];
7+
columns?: readonly ColumnType<RecordType>[];
88
columCount?: number;
99
}
1010

src/Header/FixedHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ColGroup from '../ColGroup';
77
import { ColumnsType, ColumnType } from '../interface';
88
import TableContext from '../context/TableContext';
99

10-
function useColumnWidth(colWidths: number[], columCount: number) {
10+
function useColumnWidth(colWidths: readonly number[], columCount: number) {
1111
return useMemo(() => {
1212
const cloneColumns: number[] = [];
1313
for (let i = 0; i < columCount; i += 1) {
@@ -24,7 +24,7 @@ function useColumnWidth(colWidths: number[], columCount: number) {
2424

2525
export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> {
2626
noData: boolean;
27-
colWidths: number[];
27+
colWidths: readonly number[];
2828
columCount: number;
2929
direction: 'ltr' | 'rtl';
3030
fixHeader: boolean;
@@ -92,7 +92,7 @@ const FixedHeader = React.forwardRef<HTMLDivElement, FixedHeaderProps<unknown>>(
9292
[combinationScrollBarSize, columns],
9393
);
9494

95-
const flattenColumnsWithScrollbar = useMemo<ColumnType<unknown>[]>(
95+
const flattenColumnsWithScrollbar = useMemo(
9696
() => (combinationScrollBarSize ? [...flattenColumns, ScrollBarColumn] : flattenColumns),
9797
[combinationScrollBarSize, flattenColumns],
9898
);

src/Header/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ function parseHeaderRows<RecordType>(
8383

8484
export interface HeaderProps<RecordType> {
8585
columns: ColumnsType<RecordType>;
86-
flattenColumns: ColumnType<RecordType>[];
86+
flattenColumns: readonly ColumnType<RecordType>[];
8787
stickyOffsets: StickyOffsets;
88-
onHeaderRow: GetComponentProps<ColumnType<RecordType>[]>;
88+
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
8989
}
9090

9191
function Header<RecordType>({

src/Header/HeaderRow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { getCellFixedInfo } from '../utils/fixUtil';
1212
import { getColumnsKey } from '../utils/valueUtil';
1313

1414
export interface RowProps<RecordType> {
15-
cells: CellType<RecordType>[];
15+
cells: readonly CellType<RecordType>[];
1616
stickyOffsets: StickyOffsets;
17-
flattenColumns: ColumnType<RecordType>[];
17+
flattenColumns: readonly ColumnType<RecordType>[];
1818
rowComponent: CustomizeComponent;
1919
cellComponent: CustomizeComponent;
20-
onHeaderRow: GetComponentProps<ColumnType<RecordType>[]>;
20+
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
2121
index: number;
2222
}
2323

src/Table.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface TableProps<RecordType = unknown> extends LegacyExpandableProps<
106106
className?: string;
107107
style?: React.CSSProperties;
108108
children?: React.ReactNode;
109-
data?: RecordType[];
109+
data?: readonly RecordType[];
110110
columns?: ColumnsType<RecordType>;
111111
rowKey?: string | GetRowKey<RecordType>;
112112
tableLayout?: TableLayout;
@@ -123,14 +123,14 @@ export interface TableProps<RecordType = unknown> extends LegacyExpandableProps<
123123
// Additional Part
124124
title?: PanelRender<RecordType>;
125125
footer?: PanelRender<RecordType>;
126-
summary?: (data: RecordType[]) => React.ReactNode;
126+
summary?: (data: readonly RecordType[]) => React.ReactNode;
127127

128128
// Customize
129129
id?: string;
130130
showHeader?: boolean;
131131
components?: TableComponents<RecordType>;
132132
onRow?: GetComponentProps<RecordType>;
133-
onHeaderRow?: GetComponentProps<ColumnType<RecordType>[]>;
133+
onHeaderRow?: GetComponentProps<readonly ColumnType<RecordType>[]>;
134134
emptyText?: React.ReactNode | (() => React.ReactNode);
135135

136136
direction?: 'ltr' | 'rtl';
@@ -303,7 +303,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
303303
return false;
304304
}, [!!expandedRowRender, mergedData]);
305305

306-
const [innerExpandedKeys, setInnerExpandedKeys] = React.useState<Key[]>(() => {
306+
const [innerExpandedKeys, setInnerExpandedKeys] = React.useState(() => {
307307
if (defaultExpandedRowKeys) {
308308
return defaultExpandedRowKeys;
309309
}

src/context/BodyContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface BodyContextProps<RecordType = DefaultRecordType> {
1616
expandedRowClassName: RowClassName<RecordType>;
1717

1818
columns: ColumnsType<RecordType>;
19-
flattenColumns: ColumnType<RecordType>[];
19+
flattenColumns: readonly ColumnType<RecordType>[];
2020

2121
componentWidth: number;
2222
tableLayout: TableLayout;

src/context/TableContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface TableContextProps {
1212

1313
direction: 'ltr' | 'rtl';
1414

15-
fixedInfoList: FixedInfo[];
15+
fixedInfoList: readonly FixedInfo[];
1616

1717
isSticky: boolean;
1818
}

src/hooks/useColumns.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function flatColumns<RecordType>(columns: ColumnsType<RecordType>): ColumnType<R
6060
}, []);
6161
}
6262

63-
function warningFixed(flattenColumns: { fixed?: FixedType }[]) {
63+
function warningFixed(flattenColumns: readonly { fixed?: FixedType }[]) {
6464
let allFixLeft = true;
6565
for (let i = 0; i < flattenColumns.length; i += 1) {
6666
const col = flattenColumns[i];
@@ -136,7 +136,7 @@ function useColumns<RecordType>(
136136
columnWidth?: number | string;
137137
},
138138
transformColumns: (columns: ColumnsType<RecordType>) => ColumnsType<RecordType>,
139-
): [ColumnsType<RecordType>, ColumnType<RecordType>[]] {
139+
): [ColumnsType<RecordType>, readonly ColumnType<RecordType>[]] {
140140
const baseColumns = React.useMemo<ColumnsType<RecordType>>(
141141
() => columns || convertChildrenToColumns(children),
142142
[columns, children],

0 commit comments

Comments
 (0)