mirror of
https://github.com/valitydev/partial-fetcher.git
synced 2024-11-06 00:55:17 +00:00
1.4 KiB
1.4 KiB
Partial-fetcher
The library for fetching data from endpoints that uses continuationToken.
API answers something like this?
Response {
result: any[];
continuationToken?: string;
}
Use a partial-fetcher
!
Why partial-fetcher
so great? Because supports things like doAction
, hasMore
, fetchMore
.
Installation
- Add
.npmrc
file into your root directory in your project with this line
@rbkmoney:registry=https://npm.pkg.github.com/
-
Login into github npm registry (Guide)
-
Install
partial-fetcher
via
npm i --save @rbkmoney/partial-fetcher
Usage
- Extend your service class with
PartialFetcher
like this whereR
is result type andP
search params type
Service extends PartialFetcher<R, P>
- Declare protected fetch method
fetch(params: P, continuationToken: string): Observable<FetchResult<R>>
-
Search your items with
search
method, update items withrefresh
, load more withfetchMore
. -
Get your items from
searchResult$
, check if it has more withhasMore$
, get loading state fromdoAction$
and subscribe to errors witherrors$
. -
You're awesome!