Skip to content

Commit f2ea279

Browse files
committed
chore: refactor unit test table construction
1 parent 8f4778d commit f2ea279

41 files changed

Lines changed: 1023 additions & 1441 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/react/kitchen-sink/src/routes/__root.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const Route = createRootRoute({
4545
{ title: 'TanStack Table Kitchen Sink (Start SSR)' },
4646
],
4747
links: [{ rel: 'stylesheet', href: appCss }],
48-
scripts: [{ children: consoleProbe }],
48+
scripts: [
49+
{ src: 'https://unpkg.com/react-scan/dist/auto.global.js' },
50+
{ children: consoleProbe },
51+
],
4952
}),
5053
component: RootComponent,
5154
})

examples/react/web-worker-row-models/src/routes/__root.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const Route = createRootRoute({
4545
{ title: 'TanStack Table Web Worker Row Models (Start SSR)' },
4646
],
4747
links: [{ rel: 'stylesheet', href: appCss }],
48-
scripts: [{ children: consoleProbe }],
48+
scripts: [
49+
{ src: 'https://unpkg.com/react-scan/dist/auto.global.js' },
50+
{ children: consoleProbe },
51+
],
4952
}),
5053
component: RootComponent,
5154
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ export type ExternalAtoms<TFeatures extends TableFeatures> = Partial<{
7474
* use optional chaining (`table.atoms.columnPinning?.get() ?? default`).
7575
*/
7676
export type BaseAtoms_All = {
77-
[K in keyof TableState_All]?: Atom<TableState_All[K]>
77+
[K in keyof TableState_All]?: Atom<Exclude<TableState_All[K], undefined>>
7878
}
7979
export type Atoms_All = {
8080
[K in keyof TableState_All]?: ReadonlyAtom<TableState_All[K]>
8181
}
8282
export type ExternalAtoms_All = Partial<{
83-
[K in keyof TableState_All]: Atom<TableState_All[K]>
83+
[K in keyof TableState_All]: Atom<Exclude<TableState_All[K], undefined>>
8484
}>
8585

8686
export interface TableOptions_Table<

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import type { CachedRowModel_Faceted } from '../features/column-faceting/columnFacetingFeature.types'
22
import type { CachedRowModel_Grouped } from '../features/column-grouping/columnGroupingFeature.types'
33
import type { CachedRowModel_Filtered } from '../features/column-filtering/columnFilteringFeature.types'
4-
import type {
5-
CachedRowModel_Core,
6-
RowModel,
7-
} from '../core/row-models/coreRowModelsFeature.types'
4+
import type { CachedRowModel_Core } from '../core/row-models/coreRowModelsFeature.types'
85
import type { CachedRowModel_Expanded } from '../features/row-expanding/rowExpandingFeature.types'
96
import type { CachedRowModel_Paginated } from '../features/row-pagination/rowPaginationFeature.types'
107
import type { CachedRowModel_Sorted } from '../features/row-sorting/rowSortingFeature.types'
@@ -26,12 +23,11 @@ export interface CachedRowModels_FeatureMap<
2623
export type CachedRowModels<
2724
TFeatures extends TableFeatures,
2825
TData extends RowData,
29-
> = {
30-
CachedRowModel_Core: () => RowModel<TFeatures, TData>
31-
} & ExtractFeatureMapTypes<
32-
TFeatures,
33-
CachedRowModels_FeatureMap<TFeatures, TData>
34-
>
26+
> = Partial<CachedRowModel_Core<TFeatures, TData>> &
27+
ExtractFeatureMapTypes<
28+
TFeatures,
29+
CachedRowModels_FeatureMap<TFeatures, TData>
30+
>
3531

3632
export interface CachedRowModel_All<
3733
in out TFeatures extends TableFeatures,

packages/table-core/src/worker/initTableWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function initTableWorker<
7979
...config.features,
8080
},
8181
data: message.data,
82-
}) as unknown as Table_Internal<TFeatures, TData>
82+
})
8383
// Only columns with an explicit aggregation get eagerly aggregated
8484
// per group. Sync tables aggregate lazily (visible cells only), so
8585
// auto-aggregating every column would explode on high-cardinality

packages/table-core/src/worker/rebuildRowModel.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { constructRow } from '../core/rows/constructRow'
22
import { hasOwn } from '../utils'
33
import type { RowModel } from '../core/row-models/coreRowModelsFeature.types'
44
import type { Table_Internal } from '../types/Table'
5+
import type { TableFeatures } from '../types/TableFeatures'
6+
import type { RowData } from '../types/type-utils'
57
import type {
68
TableWorkerRowNode,
79
TableWorkerStagePayload,
@@ -13,8 +15,6 @@ export type TableWorkerDataPayload = Exclude<
1315
{ kind: 'unchanged' }
1416
>
1517

16-
type AnyTable = Table_Internal<any, any>
17-
1818
// Main-thread side: payload + this table's core rows -> RowModel. Mirrors how
1919
// the sync row models treat rows: data rows are reused (with depth/parentId
2020
// rewritten, exactly like createGroupedRowModel does), synthetic group rows
@@ -32,8 +32,11 @@ function collectLeafRows(subRows: Array<any>, out: Array<any>) {
3232
}
3333
}
3434

35-
export function rebuildRowModel(
36-
table: AnyTable,
35+
export function rebuildRowModel<
36+
TFeatures extends TableFeatures,
37+
TData extends RowData,
38+
>(
39+
table: Table_Internal<TFeatures, TData>,
3740
payload: TableWorkerDataPayload,
3841
/**
3942
* Whether a flat payload should rewrite row depth/parentId. Mirrors core:
@@ -42,7 +45,7 @@ export function rebuildRowModel(
4245
* depths a grouped/sorted tree rebuild just assigned to shared row objects.
4346
*/
4447
resetDepths: boolean,
45-
): RowModel<any, any> {
48+
): RowModel<TFeatures, TData> {
4649
const core = table.getCoreRowModel()
4750

4851
if (payload.kind === 'flat') {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { coreFeatures } from '../../src'
2+
import { storeReactivityBindings } from '../../src/store-reactivity-bindings'
3+
import type {
4+
CoreFeatures,
5+
TableFeatures,
6+
ValidateFeatureSlots,
7+
} from '../../src'
8+
9+
/**
10+
* `tableFeatures` for tests: injects the core features plus the store
11+
* reactivity bindings that `constructTable` requires, so each test file only
12+
* declares the features, row model factories, and fn registries it tests.
13+
*/
14+
export function testFeatures<TFeatures extends TableFeatures>(
15+
features: TFeatures & ValidateFeatureSlots<TFeatures>,
16+
): CoreFeatures & TFeatures {
17+
return {
18+
...coreFeatures,
19+
coreReactivityFeature: storeReactivityBindings(),
20+
...features,
21+
}
22+
}

packages/table-core/tests/helpers/generateTestRows.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

packages/table-core/tests/helpers/generateTestTable.ts

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)