44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||
|
import { Store, select } from '@ngrx/store';
|
||
|
import { Observable, of, Subscription } from 'rxjs';
|
||
|
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
||
|
|
||
|
import { RPCClientError } from '@loafer/ng-rpc';
|
||
|
|
||
|
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
||
|
|
||
|
import { MetaCrawlerEntitySelector } from '../../store';
|
||
|
import * as MetaCrawlerEntityStore from '../../store/entity/meta-crawler';
|
||
|
import { MetaCrawlerService } from '../../service/meta-crawler.service';
|
||
|
|
||
|
export abstract class MetaCrawlerComponent implements OnInit, OnDestroy {
|
||
|
metaCrawlers$: Observable<MetaCrawler[]>;
|
||
|
pending$: Observable<boolean>;
|
||
|
error$: Observable<any>;
|
||
|
|
||
|
constructor(
|
||
|
protected store: Store<any>,
|
||
|
protected metaCrawlerService: MetaCrawlerService,
|
||
|
) {
|
||
|
}
|
||
|
|
||
|
ngOnInit() {
|
||
|
this.metaCrawlers$ = this.store.pipe(select(MetaCrawlerEntitySelector.selectAll));
|
||
|
this.pending$ = this.store.pipe(select(MetaCrawlerEntitySelector.selectPending));
|
||
|
this.error$ = this.store.pipe(select(MetaCrawlerEntitySelector.selectError));
|
||
|
|
||
|
this.store.pipe(
|
||
|
select(MetaCrawlerEntitySelector.selectAll),
|
||
|
map((metaCrawlers: MetaCrawler[]) => {
|
||
|
if (0 < metaCrawlers.length) {
|
||
|
return;
|
||
|
}
|
||
|
this.store.dispatch(new MetaCrawlerEntityStore.ReadAll());
|
||
|
}),
|
||
|
).take(1).subscribe();
|
||
|
}
|
||
|
|
||
|
ngOnDestroy(): void {
|
||
|
}
|
||
|
}
|