Skip to content

Commit

Permalink
InfiniteLoader resetLoadMoreRowsCache: reload last batch feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
tyupaev committed Jun 15, 2017
1 parent 881c22e commit 6939a08
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/InfiniteLoader.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ This is an advanced component and can be confusing in certain situations.

### Public Methods

##### resetLoadMoreRowsCache
Reset any cached data about already-loaded rows. This method should be called if any/all loaded data needs to be refetched (eg a filtered list where the search criteria changes).
##### resetLoadMoreRowsCache (callLoadMoreRows: boolean)
Reset any cached data about already-loaded rows. This method should be called if any/all loaded data needs to be refetched (eg a filtered list where the search criteria changes). If `callLoadMoreRows` passed as true, the last loaded batch would be automatically reloaded.

### Children function

Expand Down
17 changes: 17 additions & 0 deletions source/InfiniteLoader/InfiniteLoader.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,25 @@ describe('InfiniteLoader', () => {
innerOnRowsRendered({ startIndex: 0, stopIndex: 15 })
expect(loadMoreRowsCalls).toEqual([{ startIndex: 0, stopIndex: 19 }])
})

it('resetLoadMoreRowsCache should call :loadMoreRows if parameter passed', () => {
const component = render(getMarkup({
isRowLoaded: () => false,
minimumBatchSize: 20,
threshold: 0
}));
expect(loadMoreRowsCalls).toEqual([{ startIndex: 0, stopIndex: 19 }])
innerOnRowsRendered({ startIndex: 0, stopIndex: 15 })
loadMoreRowsCalls.splice(0)
expect(loadMoreRowsCalls).toEqual([])
component.resetLoadMoreRowsCache(true)
expect(loadMoreRowsCalls).toEqual([{ startIndex: 0, stopIndex: 15 }])
})

})



describe('scanForUnloadedRanges', () => {
function createIsRowLoaded (rows) {
return ({ index }) => rows[index]
Expand Down
6 changes: 5 additions & 1 deletion source/InfiniteLoader/InfiniteLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ export default class InfiniteLoader extends PureComponent {
this._registerChild = this._registerChild.bind(this)
}

resetLoadMoreRowsCache () {
resetLoadMoreRowsCache (callLoadMoreRows) {
const { loadMoreRows } = this.props
this._loadMoreRowsMemoizer = createCallbackMemoizer()
if (callLoadMoreRows) {
loadMoreRows({ startIndex: this._lastRenderedStartIndex, stopIndex: this._lastRenderedStopIndex })
}
}

render () {
Expand Down

0 comments on commit 6939a08

Please sign in to comment.