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; pending$: Observable; error$: Observable; constructor( protected store: Store, 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 { } }