Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 9x 9x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { isEqual, omit } from 'lodash-es';
import { makeAutoObservable, observable, runInAction } from 'mobx';
import { catchError, EMPTY, Subscription } from 'rxjs';
import { Ext } from '../model/ext';
import { Page } from '../model/page';
import { TagPageArgs } from '../model/tag';
import { ExtService } from '../service/api/ext.service';
@Injectable({
providedIn: 'root'
})
export class ExtStore {
args?: TagPageArgs = {} as any;
page?: Page<Ext> = {} as any;
error?: HttpErrorResponse = {} as any;
private running?: Subscription;
constructor(
private exts: ExtService,
) {
makeAutoObservable(this, {
args: observable.struct,
page: observable.ref,
});
this.clear(); // Initial observables may not be null for MobX
}
clear() {
this.args = undefined;
this.page = undefined;
this.error = undefined;
this.running?.unsubscribe();
}
close() {
Iif (this.running && !this.running.closed) this.clear();
}
setArgs(args: TagPageArgs) {
Eif (!isEqual(omit(this.args, 'search'), omit(args, 'search'))) this.clear();
this.args = args;
this.refresh();
}
refresh() {
Iif (!this.args) return;
this.running?.unsubscribe();
this.running = this.exts.page(this.args).pipe(
catchError((err: HttpErrorResponse) => {
runInAction(() => this.error = err);
return EMPTY;
}),
).subscribe(p => runInAction(() => this.page = p));
}
}
|