Skip to content

Commit 3ff61a3

Browse files
authored
feat: make data and columns readonly (#6183)
1 parent 0bfc658 commit 3ff61a3

9 files changed

Lines changed: 15 additions & 12 deletions

File tree

packages/angular-table/src/helpers/createTableHook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type AppGroupColumnDef<
154154
footer?: AppColumnDefTemplate<
155155
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
156156
>
157-
columns?: Array<ColumnDef<TFeatures, TData, unknown>>
157+
columns?: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>
158158
}
159159

160160
// =============================================================================

packages/table-core/src/core/columns/coreColumnsFeature.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface TableOptions_Columns<
6565
/**
6666
* The array of column defs to use for the table.
6767
*/
68-
columns: Array<ColumnDef<TFeatures, TData, TValue>>
68+
columns: ReadonlyArray<ColumnDef<TFeatures, TData, TValue>>
6969
/**
7070
* Default column options to use for all column defs supplied to the table.
7171
*/

packages/table-core/src/core/columns/coreColumnsFeature.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function table_getAllColumns<
7979
table: Table_Internal<TFeatures, TData>,
8080
): Array<Column<TFeatures, TData, unknown>> {
8181
const recurseColumns = (
82-
colDefs: Array<ColumnDef<TFeatures, TData, unknown>>,
82+
colDefs: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>,
8383
parent?: Column<TFeatures, TData, unknown>,
8484
depth = 0,
8585
): Array<Column<TFeatures, TData, unknown>> => {

packages/table-core/src/core/row-models/createCoreRowModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function _createCoreRowModel<
2929
TData extends RowData,
3030
>(
3131
table: Table_Internal<TFeatures, TData>,
32-
data: Array<TData>,
32+
data: ReadonlyArray<TData>,
3333
): {
3434
rows: Array<Row<TFeatures, TData>>
3535
flatRows: Array<Row<TFeatures, TData>>
@@ -42,7 +42,7 @@ function _createCoreRowModel<
4242
}
4343

4444
const accessRows = (
45-
originalRows: Array<TData>,
45+
originalRows: ReadonlyArray<TData>,
4646
depth = 0,
4747
parentRow?: Row<TFeatures, TData>,
4848
): Array<Row<TFeatures, TData>> => {

packages/table-core/src/core/rows/coreRowsFeature.types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface Row_CoreProperties<
2929
/**
3030
* An array of the original subRows as returned by the `options.getSubRows` option.
3131
*/
32-
originalSubRows?: Array<TData>
32+
originalSubRows?: ReadonlyArray<TData>
3333
/**
3434
* If nested, this row's parent row id.
3535
*/
@@ -96,7 +96,10 @@ export interface TableOptions_Rows<
9696
* This optional function is used to access the sub rows for any given row. If you are using nested rows, you will need to use this function to return the sub rows object (or undefined) from the row.
9797
* @example getSubRows: row => row.subRows
9898
*/
99-
getSubRows?: (originalRow: TData, index: number) => undefined | Array<TData>
99+
getSubRows?: (
100+
originalRow: TData,
101+
index: number,
102+
) => undefined | ReadonlyArray<TData>
100103
}
101104

102105
export interface Table_Rows<

packages/table-core/src/core/table/coreTablesFeature.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface TableOptions_Table<
3131
/**
3232
* The data for the table to display. When the `data` option changes reference, the table will reprocess the data.
3333
*/
34-
data: Array<TData>
34+
data: ReadonlyArray<TData>
3535
/**
3636
* Use this option to optionally pass initial state to the table. This state will be used when resetting various table states either automatically by the table (eg. `options.autoResetPageIndex`) or via functions like `table.resetRowSelection()`. Most reset function allow you optionally pass a flag to reset to a blank/default state instead of the initial state.
3737
* Table state will not be reset when this object changes, which also means that the initial state object does not need to be stable.

packages/table-core/src/types/ColumnDef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ type GroupColumnDefBase<
150150
TData extends RowData,
151151
TValue extends CellData = CellData,
152152
> = ColumnDefBase<TFeatures, TData, TValue> & {
153-
columns?: Array<ColumnDef<TFeatures, TData, unknown>>
153+
columns?: ReadonlyArray<ColumnDef<TFeatures, TData, unknown>>
154154
}
155155

156156
export type GroupColumnDef<

packages/table-devtools/src/components/RowsPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function RowsPanel() {
6262
'No table instance is connected. Pass a table instance to TableDevtoolsPanel.',
6363
}
6464
}
65-
const data = tableInstance.options.data as Array<unknown>
65+
const data = tableInstance.options.data as ReadonlyArray<unknown>
6666
if (!Array.isArray(data)) return data
6767
if (data.length <= ROW_LIMIT) return data as unknown
6868
return data.slice(0, ROW_LIMIT) as unknown
@@ -71,7 +71,7 @@ export function RowsPanel() {
7171
const getRawDataTotalCount = (): number => {
7272
tableState?.()
7373
if (!tableInstance) return 0
74-
const data = tableInstance.options.data as Array<unknown>
74+
const data = tableInstance.options.data as ReadonlyArray<unknown>
7575
return Array.isArray(data) ? data.length : 0
7676
}
7777

packages/vue-table/src/useTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type TableOptionsWithReactiveData<
1616
TFeatures extends TableFeatures,
1717
TData extends RowData,
1818
> = Omit<TableOptions<TFeatures, TData>, 'data'> & {
19-
data: MaybeRef<Array<TData>>
19+
data: MaybeRef<ReadonlyArray<TData>>
2020
}
2121

2222
function getOptionsWithReactiveData<

0 commit comments

Comments
 (0)