2020-09-28 17:56:59 +03:00
|
|
|
// #docplaster
|
|
|
|
|
/*
|
|
|
|
|
Because of how the code is merged together using the doc regions,
|
|
|
|
|
we need to indent the imports with the function below.
|
|
|
|
|
*/
|
|
|
|
|
/* tslint:disable:no-shadowed-variable */
|
|
|
|
|
/* tslint:disable:align */
|
2018-01-09 11:31:41 -08:00
|
|
|
// #docregion
|
2020-09-28 17:56:59 +03:00
|
|
|
import { of } from 'rxjs';
|
|
|
|
|
import { ajax } from 'rxjs/ajax';
|
|
|
|
|
import { map, retry, catchError } from 'rxjs/operators';
|
2018-01-09 11:31:41 -08:00
|
|
|
|
2020-09-28 17:56:59 +03:00
|
|
|
// #enddocregion
|
2018-01-09 11:31:41 -08:00
|
|
|
|
2020-09-28 17:56:59 +03:00
|
|
|
export function docRegionDefault(console, ajax) {
|
|
|
|
|
// #docregion
|
|
|
|
|
const apiData = ajax('/api/data').pipe(
|
|
|
|
|
map((res: any) => {
|
|
|
|
|
if (!res.response) {
|
|
|
|
|
console.log('Error occured.');
|
|
|
|
|
throw new Error('Value expected!');
|
|
|
|
|
}
|
|
|
|
|
return res.response;
|
|
|
|
|
}),
|
|
|
|
|
retry(3), // Retry up to 3 times before failing
|
|
|
|
|
catchError(err => of([]))
|
|
|
|
|
);
|
2018-01-09 11:31:41 -08:00
|
|
|
|
2020-09-28 17:56:59 +03:00
|
|
|
apiData.subscribe({
|
|
|
|
|
next(x) { console.log('data: ', x); },
|
|
|
|
|
error(err) { console.log('errors already caught... will not run'); }
|
|
|
|
|
});
|
2018-01-09 11:31:41 -08:00
|
|
|
|
2020-09-28 17:56:59 +03:00
|
|
|
// #enddocregion
|
|
|
|
|
}
|