Skip to content

Instantly share code, notes, and snippets.

Avatar

David Fairbanks david-fairbanks42

View GitHub Profile
@david-fairbanks42
david-fairbanks42 / observable-expand.ts
Created Apr 10, 2018
This is an example of Rx Observable expand method usage. The idea here is to divide large requests into paged results, then combine the results on the front end. This example will continue to request chunks of data from the backend until it receives a response that says there is no more results to get.
View observable-expand.ts
export class ProductService {
constructor(private authHttp: AuthHttp) {}
get(): Observable<any> {
this.products = [];
return this.authHttp.get('/api/products', {search: {limit: 100}})
// Take information from first response and make subsequent responses
// Response body contains: {hasMore: (boolean), nextOffset: (int), data: (array)}
.expand((response) => {
let obj = response.json();