All files / src/app/shared/services feature-toggles.service.ts

100% Statements 16/16
75% Branches 3/4
100% Functions 4/4
100% Lines 13/13

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 2910x 10x   10x 10x               10x 23x 23x     23x 23x 1x         10x 3x   10x  
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
 
import { Observable, timer } from 'rxjs';
import { flatMap, shareReplay } from 'rxjs/operators';
 
export type FeatureTogglesMap = Map<string, boolean>;
export type FeatureTogglesMap$ = Observable<FeatureTogglesMap>;
 
@Injectable({
  providedIn: 'root'
})
export class FeatureTogglesService {
  readonly API_URL: string = 'api/feature_toggles';
  readonly REFRESH_INTERVAL: number = 20000;
  private featureToggleMap$: FeatureTogglesMap$;
 
  constructor(private http: HttpClient) {
    this.featureToggleMap$ = timer(0, this.REFRESH_INTERVAL).pipe(
      flatMap(() => this.http.get<FeatureTogglesMap>(this.API_URL)),
      shareReplay(1)
    );
  }
 
  get(): FeatureTogglesMap$ {
    return this.featureToggleMap$;
  }
}