diff --git a/src/api/pagination.ts b/src/api/pagination.ts index 19cf5ef..d00531f 100644 --- a/src/api/pagination.ts +++ b/src/api/pagination.ts @@ -33,6 +33,21 @@ export class Paginator { }; } + /** + * Retrieves up to the next `pageSize` elements that satisfy the provided + * `filterCallback`. If a `startAfter` value is specified the elements + * starting _after_ `startAfter` are returned. Otherwise the 1st page is + * returned. + * + * Returns only array of items rather than Page data structure. + */ + private getItemsWithFilter(filterCallback: (item: T) => boolean, pageSize: number, startAfter?: T): T[] { + // PART TWO + // Implement filtering of relevant items from store. + + return this.source.getItems(pageSize, startAfter); // TODO + } + /** * Retrieves up to the next `pageSize` elements that satisfy the provided * `filterCallback`. If a `startAfter` value is specified the elements @@ -40,10 +55,13 @@ export class Paginator { * returned. */ getNextPageWithFilter(filterCallback: (item: T) => boolean, pageSize: number, startAfter?: T): Page { - // PART TWO - // Implement routine to return filtered page. + // PART THREE + // Implement hasMoreResults for filtered pages. - return this.getNextPage(pageSize, startAfter); + return { + results: this.getItemsWithFilter(filterCallback, pageSize, startAfter), + hasMoreResults: false, // TODO + }; } }