File

libs/pfe-connector/src/lib/pfe-resources.service.ts

Index

Methods

Constructor

constructor()

Methods

handleResources
handleResources(buildingBlock: BuildingBlockInterface, resourcesMap?: BuildingBlockResourceMap)
Parameters :
Name Type Optional
buildingBlock BuildingBlockInterface No
resourcesMap BuildingBlockResourceMap Yes
Returns : Observable<StaticResourceList>
import { PfeBusinessService } from '@allianz/ngx-pfe';
import { BuildingBlockInterface, TalyResourcesService } from '@allianz/taly-core';
import { inject, Injectable, Injector } from '@angular/core';
import { merge, Observable, of } from 'rxjs';
import { takeUntil, tap } from 'rxjs/operators';
import { BuildingBlockResourceMap, StaticResourceList } from './types';
import * as pfeResources from './utils/pfe-resources';

@Injectable()
export class PfeResourcesService implements TalyResourcesService {
  private _pfeBusinessService: PfeBusinessService;

  constructor() {
    const injector = inject<Injector>(Injector);

    this._pfeBusinessService = injector.get(PfeBusinessService);
  }

  handleResources(
    buildingBlock: BuildingBlockInterface,
    resourcesMap?: BuildingBlockResourceMap
  ): Observable<StaticResourceList> {
    if (!resourcesMap) {
      // When the resources are not configured, should return an empty value
      return of({});
    }

    const pfeResourceUpdates$ = [];
    // prepare a curried version of the PFE store methods
    // to keep the dependency from the actual createResourceUpdateStream
    const pfeExpressionObservableQuery = pfeResources.pfeObservableExpressionBuilder(
      this._pfeBusinessService
    );

    pfeResourceUpdates$.push(
      pfeResources.createResourceUpdateStream(resourcesMap, {
        pfeExpressionObservableQuery
      })
    );

    // kick off the resource update stream
    return merge(...pfeResourceUpdates$).pipe(
      takeUntil(buildingBlock.disconnected$),
      tap((resources: StaticResourceList) => {
        buildingBlock.resources = resources;
      })
    );
  }
}

results matching ""

    No results matching ""