diff --git a/docs/InfiniteLoader.md b/docs/InfiniteLoader.md index 90eae66a1..eb7fa384f 100644 --- a/docs/InfiniteLoader.md +++ b/docs/InfiniteLoader.md @@ -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 diff --git a/source/InfiniteLoader/InfiniteLoader.jest.js b/source/InfiniteLoader/InfiniteLoader.jest.js index c651c8334..cb4703b8b 100644 --- a/source/InfiniteLoader/InfiniteLoader.jest.js +++ b/source/InfiniteLoader/InfiniteLoader.jest.js @@ -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] diff --git a/source/InfiniteLoader/InfiniteLoader.js b/source/InfiniteLoader/InfiniteLoader.js index 1d8d418f1..645319162 100644 --- a/source/InfiniteLoader/InfiniteLoader.js +++ b/source/InfiniteLoader/InfiniteLoader.js @@ -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 () {