integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { Observable, shareReplay } from 'rxjs';
|
||||
import { Dominio, IndicadorDatos, TipoPeriodo } from './indicadores.models';
|
||||
import { IndicadoresService } from './indicadores.service';
|
||||
import { IndicadoresRequests } from './indicadores-requests';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class IndicadoresKpiQueries {
|
||||
private readonly service = inject(IndicadoresService);
|
||||
private readonly requests = inject(IndicadoresRequests);
|
||||
// Only resolved KPI payloads survive navigation. Errors and cancelled requests reset.
|
||||
private readonly cache = new Map<string, Observable<IndicadorDatos>>();
|
||||
datos(domain: Dominio, id: string, tipo: TipoPeriodo, period: string) {
|
||||
const key = JSON.stringify([domain, id, tipo, period]);
|
||||
let request = this.cache.get(key);
|
||||
if (!request) {
|
||||
request = this.requests.run(() => this.service.datos(domain, id, tipo, [period])).pipe(
|
||||
shareReplay({ bufferSize: 1, refCount: true }));
|
||||
this.cache.set(key, request);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user