Skip to content

Commit f502ef4

Browse files
committed
Immutablely decorate with _viewIndex
TanStack#203
1 parent c58c96c commit f502ef4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/index.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,31 @@ export default React.createClass({
8787
// Pagination
8888
const startRow = pageSize * page
8989
const endRow = startRow + pageSize
90-
const pageRows = manual ? resolvedData : sortedData.slice(startRow, endRow)
90+
let pageRows = manual ? resolvedData : sortedData.slice(startRow, endRow)
9191
const minRows = this.getMinRows()
9292
const padRows = _.range(Math.max(minRows - pageRows.length, 0))
9393

9494
const hasColumnFooter = allVisibleColumns.some(d => d.footer)
9595

9696
const recurseRowsViewIndex = (rows, path = [], index = -1) => {
97-
rows.forEach((row, i) => {
98-
index++
99-
row._viewIndex = index
100-
const newPath = path.concat([i])
101-
if (row[subRowsKey] && _.get(expandedRows, newPath)) {
102-
index = recurseRowsViewIndex(row[subRowsKey], newPath, index)
103-
}
104-
})
105-
return index
97+
return [
98+
rows.map((row, i) => {
99+
index++
100+
const rowWithViewIndex = {
101+
...row,
102+
_viewIndex: index
103+
}
104+
const newPath = path.concat([i])
105+
if (rowWithViewIndex[subRowsKey] && _.get(expandedRows, newPath)) {
106+
[rowWithViewIndex[subRowsKey], index] = recurseRowsViewIndex(rowWithViewIndex[subRowsKey], newPath, index)
107+
}
108+
return rowWithViewIndex
109+
}),
110+
index
111+
]
106112
}
107113

108-
recurseRowsViewIndex(pageRows)
114+
[pageRows] = recurseRowsViewIndex(pageRows)
109115

110116
const canPrevious = page > 0
111117
const canNext = page + 1 < pages

0 commit comments

Comments
 (0)