Paginator

public class Paginator<BaseRequestType, PaginationType>
where BaseRequestType: Request, PaginationType: PaginatedData,
    PaginationType.DataType == BaseRequestType.Result

A paginator is returned whenever a request is scheduled for pagination (see Request.schedule(forPaginationWith:chunk:zeroBasedPageIndex:decode:) or JsonRequest.schedule(forPaginationWith:chunk:zeroBasedPageIndex:paginatedType:)).

In contrast to the Response publisher, this instance is no publisher itself. The Paginator.connect(with:) needs to be called which yields a publisher that emits the responses for successive pagination requests. See the method’s documentation for details.

Instance Methods

  • This method is used to initiate pagination calls. Once subscribed, the request for the initial page is sent automatically. Every subsequent request is sent when the given publisher emits an item. In case the publisher emits an item while a request is running, the “tick” is simply ignored.

    The returned publisher emits the requests’ responses (one for each page, strictly chronological), i.e. the first response yields the contents of page 0, the second the one of page 1, etc. In case any request fails, the returned publisher errors out and no more pages can be requested. In case all pages have been successfully received, the publisher completes. Note that the returned publisher is shared and can therefore be subscribed to arbitraily often.

    A common use case for calling this function is to function as data source for a (seemingly) infinite List in SwiftUI. The publisher given to the function emits values once the user hits the bottom of the list while scrolling and the returned publisher emits ever new items.

    Note that this method can be called multiple times and yields independent publishers.

    Declaration

    Swift

    public func connect<P>(with ticks: P) -> AnyPublisher<BaseRequestType.Result, Squid.Error>
    where P: Publisher, P.Failure == Never

    Parameters

    ticks

    The publisher that indicates the need for requesting the next page.