Skip to content

Commit

Permalink
feat: static type check about getSupersetOutput
Browse files Browse the repository at this point in the history
using generic to define return type of getSupersetOutput
  • Loading branch information
ElonH committed May 17, 2020
1 parent fdce810 commit 217700a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/app/@dataflow/core/ajax-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { DataFlowNode, BareFlowInNode, BareFlowOutNode, CombErr } from './bare-f
import { Observable, of } from 'rxjs';
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
import { catchError, map } from 'rxjs/operators';
import { FlowSupNode } from './superset-flow';

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

export abstract class AjaxFlow<
Tin extends BareFlowInNode,
Tout extends BareFlowOutNode
> extends CacheFlow<Tin, Tout> {
Tout extends BareFlowOutNode,
Tsup extends FlowSupNode = Tin & Tout
> extends CacheFlow<Tin, Tout, Tsup> {
// protected cacheSupport: boolean;
// protected cachePath: string;

Expand Down
7 changes: 4 additions & 3 deletions src/app/@dataflow/core/cache-flow.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DataFlowNode, BareFlowInNode, BareFlowOutNode, CombErr } from './bare-flow';
import { Observable, iif, of } from 'rxjs';
import { SupersetFlow } from './superset-flow';
import { SupersetFlow, FlowSupNode } from './superset-flow';
import { tap, take, map } from 'rxjs/operators';

export abstract class CacheFlow<
Tin extends BareFlowInNode,
Tout extends BareFlowOutNode
> extends SupersetFlow<Tin, Tout> {
Tout extends BareFlowOutNode,
Tsup extends FlowSupNode = Tin & Tout
> extends SupersetFlow<Tin, Tout, Tsup> {
protected abstract requestCache(pre: CombErr<Tin>): Observable<CombErr<Tout>>;
protected request(pre: CombErr<Tin>): Observable<CombErr<Tout>> {
return iif(
Expand Down
17 changes: 10 additions & 7 deletions src/app/@dataflow/core/superset-flow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BareFlow, DataFlowNode, BareFlowInNode, BareFlowOutNode } from './bare-flow';
import { BareFlow, BareFlowInNode, BareFlowOutNode, CombErr } from './bare-flow';
import { Observable } from 'rxjs';
import {
tap,
Expand All @@ -10,24 +10,27 @@ import {
map,
} from 'rxjs/operators';

export interface FlowSupNode {}

export abstract class SupersetFlow<
Tin extends BareFlowInNode,
Tout extends BareFlowOutNode
Tout extends BareFlowOutNode,
Tsup extends FlowSupNode = Tin & Tout
> extends BareFlow<Tin, Tout> {
private boostrapPrerequest$: Observable<DataFlowNode>;
private boostrapPrerequest: DataFlowNode;
private boostrapPrerequest$: Observable<CombErr<Tin>>;
private boostrapPrerequest: CombErr<Tin>;
public deploy() {
super.deploy();
this.boostrapPrerequest$ = this.prerequest$.pipe(tap((x) => (this.boostrapPrerequest = x)));
this.boostrapPrerequest$.pipe(take(1)).subscribe();
}
protected generateSuperset(current: DataFlowNode, previous: DataFlowNode): DataFlowNode {
protected generateSuperset(current: CombErr<Tout>, previous: CombErr<Tin>): CombErr<Tsup> {
return [
{ ...current[0], ...previous[0] },
({ ...current[0], ...previous[0] } as any) as Tsup, // if Tsup is not Tin & Tout, need to override generateSupreset
[].concat(current[1], previous[1]).filter((x, i, a) => a.indexOf(x) === i),
];
}
public getSupersetOutput(): Observable<DataFlowNode> {
public getSupersetOutput(): Observable<CombErr<Tsup>> {
return this.getOutput().pipe(
withLatestFrom(
this.boostrapPrerequest$.pipe(
Expand Down

0 comments on commit 217700a

Please sign in to comment.