Skip to content

Commit 078cbde

Browse files
committed
chore: separate row models as feature
1 parent f0a9f30 commit 078cbde

File tree

10 files changed

+69
-46
lines changed

10 files changed

+69
-46
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { table_getCoreRowModel, table_getRowModel } from './RowModels.utils'
2+
import type { RowData, Table, TableFeature } from '../../types'
3+
4+
export const RowModels: TableFeature = {
5+
_createTable: <TData extends RowData>(table: Table<TData>): void => {
6+
table.getCoreRowModel = () => table_getCoreRowModel(table)
7+
8+
table.getRowModel = () => table_getRowModel(table)
9+
},
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { RowData, RowModel, Table } from '../../types'
2+
3+
export interface TableOptions_RowModels<TData extends RowData> {
4+
/**
5+
* This required option is a factory for a function that computes and returns the core row model for the table.
6+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel)
7+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
8+
*/
9+
getCoreRowModel: (table: Table<TData>) => () => RowModel<any>
10+
}
11+
12+
export interface Table_RowModels<TData extends RowData> {
13+
_getCoreRowModel?: () => RowModel<TData>
14+
/**
15+
* Returns the core row model before any processing has been applied.
16+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel)
17+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
18+
*/
19+
getCoreRowModel: () => RowModel<TData>
20+
/**
21+
* Returns the final model after all processing from other used features has been applied. This is the row model that is most commonly used for rendering.
22+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getrowmodel)
23+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
24+
*/
25+
getRowModel: () => RowModel<TData>
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { table_getPaginationRowModel } from '../../features/row-pagination/RowPagination.utils'
2+
import type { RowData, RowModel, Table } from '../../types'
3+
4+
export function table_getCoreRowModel<TData extends RowData>(
5+
table: Table<TData>,
6+
): RowModel<TData> {
7+
if (!table._getCoreRowModel) {
8+
table._getCoreRowModel = table.options.getCoreRowModel(table)
9+
}
10+
11+
return table._getCoreRowModel()
12+
}
13+
14+
export function table_getRowModel<TData extends RowData>(
15+
table: Table<TData>,
16+
): RowModel<TData> {
17+
return table_getPaginationRowModel(table)
18+
}

packages/table-core/src/core/table/getCoreRowModel.ts renamed to packages/table-core/src/core/row-models/getCoreRowModel.ts

File renamed without changes.

packages/table-core/src/core/table/Tables.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {
2-
table_getCoreRowModel,
3-
table_getRowModel,
42
table_getState,
53
table_reset,
64
table_setOptions,
@@ -17,9 +15,5 @@ export const Tables: TableFeature = {
1715
table.getState = () => table_getState(table)
1816

1917
table.setState = (updater) => table_setState(table, updater)
20-
21-
table.getCoreRowModel = () => table_getCoreRowModel(table)
22-
23-
table.getRowModel = () => table_getRowModel(table)
2418
},
2519
}

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type {
22
RowData,
3-
RowModel,
4-
Table,
53
TableFeature,
64
TableMeta,
75
TableOptions,
@@ -42,12 +40,6 @@ export interface TableOptions_Core<TData extends RowData> {
4240
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
4341
*/
4442
debugTable?: boolean
45-
/**
46-
* This required option is a factory for a function that computes and returns the core row model for the table.
47-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel)
48-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
49-
*/
50-
getCoreRowModel: (table: Table<any>) => () => RowModel<any>
5143
/**
5244
* 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.
5345
*
@@ -105,20 +97,7 @@ export interface Table_CoreProperties<TData extends RowData> {
10597

10698
export interface Table_Core<TData extends RowData>
10799
extends Table_CoreProperties<TData> {
108-
_getCoreRowModel?: () => RowModel<TData>
109100
_queue: (cb: () => void) => void
110-
/**
111-
* Returns the core row model before any processing has been applied.
112-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getcorerowmodel)
113-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
114-
*/
115-
getCoreRowModel: () => RowModel<TData>
116-
/**
117-
* Returns the final model after all processing from other used features has been applied. This is the row model that is most commonly used for rendering.
118-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getrowmodel)
119-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
120-
*/
121-
getRowModel: () => RowModel<TData>
122101
/**
123102
* Call this function to get the table's current state. It's recommended to use this function and its state, especially when managing the table state manually. It is the exact same state used internally by the table for every feature and function it provides.
124103
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getstate)

packages/table-core/src/core/table/Tables.utils.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,3 @@ export function table_setState<TData extends RowData>(
5151
): void {
5252
table.options.onStateChange(updater)
5353
}
54-
55-
export function table_getCoreRowModel<TData extends RowData>(
56-
table: Table<TData>,
57-
): RowModel<TData> {
58-
if (!table._getCoreRowModel) {
59-
table._getCoreRowModel = table.options.getCoreRowModel(table)
60-
}
61-
62-
return table._getCoreRowModel()
63-
}
64-
65-
export function table_getRowModel<TData extends RowData>(
66-
table: Table<TData>,
67-
): RowModel<TData> {
68-
return table_getPaginationRowModel(table)
69-
}

packages/table-core/src/core/table/_createTable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Headers } from '../headers/Headers'
22
import { Rows } from '../rows/Rows'
33
import { Cells } from '../cells/Cells'
44
import { Columns } from '../columns/Columns'
5-
65
import { ColumnFaceting } from '../../features/column-faceting/ColumnFaceting'
76
import { ColumnFiltering } from '../../features/column-filtering/ColumnFiltering'
87
import { ColumnGrouping } from '../../features/column-grouping/ColumnGrouping'
@@ -18,6 +17,7 @@ import { RowPagination } from '../../features/row-pagination/RowPagination'
1817
import { RowPinning } from '../../features/row-pinning/RowPinning'
1918
import { RowSelection } from '../../features/row-selection/RowSelection'
2019
import { RowSorting } from '../../features/row-sorting/RowSorting'
20+
import { RowModels } from '../row-models/RowModels'
2121
import { Tables } from './Tables'
2222
import type { Table_CoreProperties } from './Tables.types'
2323
import type {
@@ -27,7 +27,7 @@ import type {
2727
TableState,
2828
} from '../../types'
2929

30-
const coreFeatures = [Tables, Rows, Headers, Columns, Cells]
30+
const coreFeatures = [Tables, RowModels, Rows, Headers, Columns, Cells]
3131

3232
const builtInFeatures = [
3333
ColumnFaceting,

packages/table-core/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* Core
33
*/
44

5-
export * from './core/table/getCoreRowModel'
65
export * from './helpers'
76
export * from './types'
87
export * from './utils'
8+
export * from './utils.types'
99

1010
//Cells
1111
export * from './core/cells/_createCell'
@@ -26,6 +26,12 @@ export * from './core/headers/Headers'
2626
export * from './core/headers/Headers.types'
2727
export * from './core/headers/Headers.utils'
2828

29+
//Row Models
30+
export * from './core/row-models/getCoreRowModel'
31+
export * from './core/row-models/RowModels'
32+
export * from './core/row-models/RowModels.types'
33+
export * from './core/row-models/RowModels.utils'
34+
2935
//Rows
3036
export * from './core/rows/_createRow'
3137
export * from './core/rows/Rows'

packages/table-core/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import type {
2+
TableOptions_RowModels,
3+
Table_RowModels,
4+
} from './core/row-models/RowModels.types'
15
import type { TableOptions_Core, Table_Core } from './core/table/Tables.types'
26
import type {
37
ColumnDef_ColumnVisibility,
@@ -157,6 +161,7 @@ export type AnyRender = (Comp: any, props: any) => any
157161
export interface Table<TData extends RowData>
158162
extends Table_Core<TData>,
159163
Table_Columns<TData>,
164+
Table_RowModels<TData>,
160165
Table_Rows<TData>,
161166
Table_Headers<TData>,
162167
Table_ColumnFiltering<TData>,
@@ -178,6 +183,7 @@ export interface TableOptionsResolved<TData extends RowData>
178183
extends TableOptions_Core<TData>,
179184
TableOptions_Cell,
180185
TableOptions_Columns<TData>,
186+
TableOptions_RowModels<TData>,
181187
TableOptions_Rows<TData>,
182188
TableOptions_Headers,
183189
TableOptions_ColumnFaceting<TData>,

0 commit comments

Comments
 (0)