Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export const densityPlugin: TableFeature = {
const newState = functionalUpdate(updater, old)
return newState
}
return table.options.onDensityChange?.(safeUpdater)
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
table_toggleDensity: {
Expand All @@ -93,7 +95,9 @@ export const densityPlugin: TableFeature = {
if (value) return value
return old === 'lg' ? 'md' : old === 'md' ? 'sm' : 'lg' // cycle through the 3 options
}
return table.options.onDensityChange?.(safeUpdater)
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
})
Expand Down
8 changes: 6 additions & 2 deletions examples/preact/custom-plugin/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export const densityPlugin: TableFeature = {
const newState = functionalUpdate(updater, old)
return newState
}
return table.options.onDensityChange?.(safeUpdater)
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
table_toggleDensity: {
Expand All @@ -111,7 +113,9 @@ export const densityPlugin: TableFeature = {
if (value) return value
return old === 'lg' ? 'md' : old === 'md' ? 'sm' : 'lg' // cycle through the 3 options
}
return table.options.onDensityChange?.(safeUpdater)
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
})
Expand Down
8 changes: 6 additions & 2 deletions examples/react/custom-plugin/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export const densityPlugin: TableFeature = {
const newState = functionalUpdate(updater, old)
return newState
}
return table.options.onDensityChange?.(safeUpdater)
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
table_toggleDensity: {
Expand All @@ -112,7 +114,9 @@ export const densityPlugin: TableFeature = {
if (value) return value
return old === 'lg' ? 'md' : old === 'md' ? 'sm' : 'lg' // cycle through the 3 options
}
return table.options.onDensityChange?.(safeUpdater)
return (table.options as TableOptions_Density).onDensityChange?.(
safeUpdater,
)
},
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { callMemoOrStaticFn } from '../../utils'
import { callMemoOrStaticFn, makeObjectMap } from '../../utils'
import { table_getOrderColumnsFn } from '../../features/column-ordering/columnOrderingFeature.utils'
import { constructColumn } from './constructColumn'
import type { Table_Internal } from '../../types/Table'
Expand Down Expand Up @@ -185,7 +185,7 @@ export function table_getAllFlatColumnsById<
>(
table: Table_Internal<TFeatures, TData>,
): Record<string, Column<TFeatures, TData, unknown>> {
const result: Record<string, Column<TFeatures, TData, unknown>> = {}
const result = makeObjectMap<Column<TFeatures, TData, unknown>>()
const flatColumns = table.getAllFlatColumns()
for (let i = 0; i < flatColumns.length; i++) {
const column = flatColumns[i]!
Expand Down Expand Up @@ -238,7 +238,7 @@ export function table_getAllLeafColumnsById<
>(
table: Table_Internal<TFeatures, TData>,
): Record<string, Column<TFeatures, TData, unknown>> {
const result: Record<string, Column<TFeatures, TData, unknown>> = {}
const result = makeObjectMap<Column<TFeatures, TData, unknown>>()
const leafColumns = table.getAllLeafColumns()
for (let i = 0; i < leafColumns.length; i++) {
const column = leafColumns[i]!
Expand Down
4 changes: 2 additions & 2 deletions packages/table-core/src/core/row-models/createCoreRowModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { constructRow } from '../rows/constructRow'
import { tableMemo } from '../../utils'
import { makeObjectMap, tableMemo } from '../../utils'
import { table_autoResetPageIndex } from '../../features/row-pagination/rowPaginationFeature.utils'
import type { Table_Internal } from '../../types/Table'
import type { RowModel } from './coreRowModelsFeature.types'
Expand Down Expand Up @@ -44,7 +44,7 @@ function _createCoreRowModel<
const rowModel: RowModel<TFeatures, TData> = {
rows: [],
flatRows: [],
rowsById: {},
rowsById: makeObjectMap(),
}

const accessRows = (
Expand Down
5 changes: 3 additions & 2 deletions packages/table-core/src/core/rows/constructRow.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { makeObjectMap } from '../../utils'
import type { Table_Internal } from '../../types/Table'
import type { RowData } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
Expand Down Expand Up @@ -47,8 +48,8 @@ export const constructRow = <
>

// Only assign instance-specific properties
row._uniqueValuesCache = {}
row._valuesCache = {}
row._uniqueValuesCache = makeObjectMap()
row._valuesCache = makeObjectMap()
row.depth = depth
row.id = id
row.index = rowIndex
Expand Down
8 changes: 4 additions & 4 deletions packages/table-core/src/core/rows/coreRowsFeature.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flattenBy } from '../../utils'
import { flattenBy, hasOwn, makeObjectMap } from '../../utils'
import { constructCell } from '../cells/constructCell'
import type { Table_Internal } from '../../types/Table'
import type { RowData } from '../../types/type-utils'
Expand All @@ -21,7 +21,7 @@ export function row_getValue<
TFeatures extends TableFeatures,
TData extends RowData,
>(row: Row<TFeatures, TData>, columnId: string) {
if (row._valuesCache.hasOwnProperty(columnId)) {
if (hasOwn(row._valuesCache, columnId)) {
return row._valuesCache[columnId]
}

Expand Down Expand Up @@ -51,7 +51,7 @@ export function row_getUniqueValues<
TFeatures extends TableFeatures,
TData extends RowData,
>(row: Row<TFeatures, TData>, columnId: string) {
if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
if (hasOwn(row._uniqueValuesCache, columnId)) {
return row._uniqueValuesCache[columnId]
}

Expand Down Expand Up @@ -192,7 +192,7 @@ export function row_getAllCellsByColumnId<
TFeatures extends TableFeatures,
TData extends RowData,
>(row: Row<TFeatures, TData>) {
const result: Record<string, Cell<TFeatures, TData, unknown>> = {}
const result = makeObjectMap<Cell<TFeatures, TData, unknown>>()
const cells = row.getAllCells()
for (let i = 0; i < cells.length; i++) {
const cell = cells[i]!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
assignPrototypeAPIs,
assignTableAPIs,
makeObjectMap,
makeStateUpdater,
} from '../../utils'
import {
Expand Down Expand Up @@ -69,8 +70,8 @@ export const columnFilteringFeature: TableFeature = {
},

initRowInstanceData: (row) => {
;(row as any).columnFilters = {}
;(row as any).columnFiltersMeta = {}
;(row as any).columnFilters = makeObjectMap()
;(row as any).columnFiltersMeta = makeObjectMap()
},

constructTableAPIs: (table) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tableMemo } from '../../utils'
import { makeObjectMap, tableMemo } from '../../utils'
import { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'
import {
column_getCanGlobalFilter,
Expand Down Expand Up @@ -60,8 +60,8 @@ function _createFilteredRowModel<
>
for (let i = 0; i < flatRows.length; i++) {
const row = flatRows[i]!
row.columnFilters = {}
row.columnFiltersMeta = {}
row.columnFilters = makeObjectMap()
row.columnFiltersMeta = makeObjectMap()
}
return rowModel
}
Expand Down Expand Up @@ -115,7 +115,8 @@ function _createFilteredRowModel<
>
for (let i = 0; i < flatRows.length; i++) {
const row = flatRows[i]!
row.columnFilters = {}
row.columnFilters = makeObjectMap()
row.columnFiltersMeta = makeObjectMap()

if (resolvedColumnFilters.length) {
for (let j = 0; j < resolvedColumnFilters.length; j++) {
Expand All @@ -128,9 +129,10 @@ function _createFilteredRowModel<
id,
currentColumnFilter.resolvedValue,
(filterMeta) => {
!row.columnFiltersMeta
? (row.columnFiltersMeta = {})
: (row.columnFiltersMeta[id] = filterMeta)
if (!row.columnFiltersMeta) {
row.columnFiltersMeta = makeObjectMap()
}
row.columnFiltersMeta[id] = filterMeta
},
)
}
Expand All @@ -147,9 +149,10 @@ function _createFilteredRowModel<
id,
currentGlobalFilter.resolvedValue,
(filterMeta) => {
!row.columnFiltersMeta
? (row.columnFiltersMeta = {})
: (row.columnFiltersMeta[id] = filterMeta)
if (!row.columnFiltersMeta) {
row.columnFiltersMeta = makeObjectMap()
}
row.columnFiltersMeta[id] = filterMeta
},
)
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { constructRow } from '../../core/rows/constructRow'
import { makeObjectMap } from '../../utils'
import type { Row_ColumnFiltering } from './columnFilteringFeature.types'
import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
import type { Row } from '../../types/Row'
Expand Down Expand Up @@ -37,7 +38,7 @@ function filterRowModelFromLeafs<
table: Table_Internal<TFeatures, TData>,
): RowModel<TFeatures, TData> {
const newFilteredFlatRows: Array<Row<TFeatures, TData>> = []
const newFilteredRowsById: Record<string, Row<TFeatures, TData>> = {}
const newFilteredRowsById = makeObjectMap<Row<TFeatures, TData>>()
const maxDepth = table.options.maxLeafRowFilterDepth ?? 100

const recurseFilterRows = (
Expand Down Expand Up @@ -109,7 +110,7 @@ function filterRowModelFromRoot<
table: Table_Internal<TFeatures, TData>,
): RowModel<TFeatures, TData> {
const newFilteredFlatRows: Array<Row<TFeatures, TData>> = []
const newFilteredRowsById: Record<string, Row<TFeatures, TData>> = {}
const newFilteredRowsById = makeObjectMap<Row<TFeatures, TData>>()
const maxDepth = table.options.maxLeafRowFilterDepth ?? 100

// Filters top level and nested rows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
assignPrototypeAPIs,
assignTableAPIs,
makeObjectMap,
makeStateUpdater,
} from '../../utils'
import {
Expand Down Expand Up @@ -99,7 +100,7 @@ export const columnGroupingFeature: TableFeature = {
},

initRowInstanceData: (row) => {
;(row as any)._groupingValuesCache = {}
;(row as any)._groupingValuesCache = makeObjectMap()
},

constructTableAPIs: (table) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneState, isFunction } from '../../utils'
import { cloneState, hasOwn, isFunction } from '../../utils'
import type { Column_Internal } from '../../types/Column'
import type { CellData, RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
Expand Down Expand Up @@ -268,7 +268,7 @@ export function row_getGroupingValue<
TFeatures extends TableFeatures,
TData extends RowData,
>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {
if (row._groupingValuesCache?.hasOwnProperty(columnId)) {
if (row._groupingValuesCache && hasOwn(row._groupingValuesCache, columnId)) {
return row._groupingValuesCache[columnId]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flattenBy, tableMemo } from '../../utils'
import { flattenBy, hasOwn, makeObjectMap, tableMemo } from '../../utils'
import { constructRow } from '../../core/rows/constructRow'
import { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'
import { table_autoResetExpanded } from '../row-expanding/rowExpandingFeature.utils'
Expand Down Expand Up @@ -69,7 +69,7 @@ function _createGroupedRowModel<

const groupedFlatRows: Array<Row<TFeatures, TData>> &
Partial<Row_ColumnGrouping> = []
const groupedRowsById: Record<string, Row<TFeatures, TData>> = {}
const groupedRowsById = makeObjectMap<Row<TFeatures, TData>>()

// Recursively group the data
const groupUpRecursively = (
Expand Down Expand Up @@ -135,7 +135,7 @@ function _createGroupedRowModel<
getValue: (colId: string) => {
// Don't aggregate columns that are in the grouping
if (existingGrouping.includes(colId)) {
if (row._valuesCache.hasOwnProperty(colId)) {
if (hasOwn(row._valuesCache, colId)) {
return row._valuesCache[colId]
}

Expand All @@ -147,7 +147,10 @@ function _createGroupedRowModel<
return row._valuesCache[colId]
}

if (row._groupingValuesCache?.hasOwnProperty(colId)) {
if (
row._groupingValuesCache &&
hasOwn(row._groupingValuesCache, colId)
) {
return row._groupingValuesCache[colId]
}

Expand All @@ -157,7 +160,9 @@ function _createGroupedRowModel<
column as Column<TFeatures, TData, unknown>,
)

if (!row._groupingValuesCache) row._groupingValuesCache = {}
if (!row._groupingValuesCache) {
row._groupingValuesCache = makeObjectMap()
}

if (aggregateFn) {
row._groupingValuesCache[colId] = aggregateFn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
header_getSize,
table_setColumnSizing,
} from '../column-sizing/columnSizingFeature.utils'
import { cloneState } from '../../utils'
import { cloneState, makeObjectMap } from '../../utils'
import type { CellData, RowData, Updater } from '../../types/type-utils'
import type { TableFeatures } from '../../types/TableFeatures'
import type { Table_Internal } from '../../types/Table'
Expand Down Expand Up @@ -123,7 +123,7 @@ export function header_getResizeHandler<
? Math.round(event.touches[0]!.clientX)
: (event as MouseEvent).clientX

const newColumnSizing: ColumnSizingState = {}
const newColumnSizing: ColumnSizingState = makeObjectMap()

const updateOffset = (eventType: 'move' | 'end', clientXPos?: number) => {
if (typeof clientXPos !== 'number') {
Expand Down Expand Up @@ -164,10 +164,9 @@ export function header_getResizeHandler<
column.table.options.columnResizeMode === 'onChange' ||
eventType === 'end'
) {
table_setColumnSizing(column.table, (old) => ({
...old,
...newColumnSizing,
}))
table_setColumnSizing(column.table, (old) =>
Object.assign(makeObjectMap<number>(), old, newColumnSizing),
)
}
}

Expand Down
Loading
Loading