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

100% Statements 17/17
66.67% Branches 2/3
100% Functions 3/3
100% Lines 14/14

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
    3110x
    10x

    10x
    10x

    10x

    10x
    21x
    21x

    21x
    21x
    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';

    import { ServicesModule } from './services.module';

    export type FeatureTogglesMap = Map<string, boolean>;
    export type FeatureTogglesMap$ = Observable<FeatureTogglesMap>;

    @Injectable({
      providedIn: ServicesModule
    })
    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$;
      }
    }