Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfiniteLoader resetLoadMoreRowsCache: reload last batch feature added #704

Merged
merged 2 commits into from
Jul 8, 2017
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
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
14 changes: 14 additions & 0 deletions source/InfiniteLoader/InfiniteLoader.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ 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', () => {
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