Skip to content

Commit

Permalink
Only cache styles if not scrolling AND offsets are not adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan power authored and nathan power committed Jul 7, 2017
1 parent 8136a16 commit fe3a3cb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,43 @@ describe('Grid', () => {
])
})

it('should not cache cells if the offsets are not adjusted', () => {
const cellRendererCalls = []
function cellRenderer ({ columnIndex, key, rowIndex, style }) {
cellRendererCalls.push({ columnIndex, rowIndex })
return defaultCellRenderer({ columnIndex, key, rowIndex, style })
}
const props = {
cellRenderer,
columnWidth: 100,
height: 40,
rowHeight: 20,
rowCount: 100000,
scrollToRow: 0,
width: 100
}

render(getMarkup({
...props,
scrollToRow: 0
}))
expect(cellRendererCalls).toEqual([
{ columnIndex: 0, rowIndex: 0 },
{ columnIndex: 0, rowIndex: 1 }
])

cellRendererCalls.splice(0)

render(getMarkup({
...props,
scrollToRow: 1
}))
expect(cellRendererCalls).toEqual([
{ columnIndex: 0, rowIndex: 0 },
{ columnIndex: 0, rowIndex: 1 }
])
})

it('should cache a cell once it has been rendered while scrolling', () => {
const cellRendererCalls = []
function cellRenderer ({ columnIndex, key, rowIndex, style }) {
Expand Down
2 changes: 1 addition & 1 deletion source/Grid/defaultCellRangeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function defaultCellRangeRenderer ({
rowSizeAndPositionManager.areOffsetsAdjusted()
)

const canCacheStyle = !isScrolling || !areOffsetsAdjusted
const canCacheStyle = !isScrolling && !areOffsetsAdjusted;

for (let rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
let rowDatum = rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex)
Expand Down

0 comments on commit fe3a3cb

Please sign in to comment.