partial-fetcher/README.md
2019-11-29 16:58:22 +03:00

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 where R is result type and P 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 with refresh, load more with fetchMore.

  • Get your items from searchResult$, check if it has more with hasMore$, get loading state from doAction$ and subscribe to errors with errors$.

  • You're awesome!