Skip to content

Commit

Permalink
feat(ajax-flow): fetch data by ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 16, 2020
1 parent ae08885 commit 14904e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/@dataflow/core/ajax-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AjaxFlow } from './ajax-flow';

describe('AjaxFlow', () => {
// xit('should create an instance', () => {
// expect(new AjaxFlow()).toBeTruthy();
// });
});
22 changes: 22 additions & 0 deletions src/app/@dataflow/core/ajax-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CacheFlow } from './cache-flow';
import { DataFlowNode, BareFlowPreNode } from './bare-flow';
import { Observable, of } from 'rxjs';
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
import { catchError, map } from 'rxjs/operators';

export type AjaxFlowNode = [AjaxResponse | object, Error[]];

export abstract class AjaxFlow<Tpre extends BareFlowPreNode> extends CacheFlow<Tpre> {
// protected cacheSupport: boolean;
// protected cachePath: string;

protected abstract requestAjax(pre: DataFlowNode): AjaxRequest;
protected abstract reconstructAjaxResult(x: AjaxFlowNode): DataFlowNode;
protected requestCache(pre: DataFlowNode): Observable<DataFlowNode> {
return ajax(this.requestAjax(pre)).pipe(
map((x) => [x, []] as AjaxFlowNode),
catchError((err): Observable<AjaxFlowNode> => of([{}, [err]])),
map((x) => this.reconstructAjaxResult(x))
);
}
}

0 comments on commit 14904e8

Please sign in to comment.