Commit e63ae823 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Suppression de Configuration au profit d'InjectionTokens.

No related merge requests found
Showing with 10 additions and 17 deletions
+10 -17
......@@ -7,8 +7,6 @@ import {
Output,
} from '@angular/core';
// TODO injecter
import { Configuration } from '../configuration';
import { DebugStateService } from '../debug-state.service';
import { ApiDebugInterceptor, DebugEvent } from './api-debug.interceptor';
......@@ -28,6 +26,8 @@ interface ResponseInfo {
tokenLink?: string;
}
export const ApiBaseUrlToken = new InjectionToken<string>('apiBaseUrl');
@Component({
selector: 'dbg-api-debug',
templateUrl: './api-debug.component.html',
......@@ -46,10 +46,8 @@ export class ApiDebugComponent {
interceptor: ApiDebugInterceptor,
public readonly debug: DebugStateService,
private readonly cd: ChangeDetectorRef,
conf: Configuration
@Inject(ApiBaseUrlToken) private readonly apiPrefix: string,
) {
this.apiPrefix = conf.apiBaseURL;
interceptor.events$.subscribe(ev => {
this.handle(ev);
});
......
......@@ -9,9 +9,6 @@ import * as _ from 'lodash';
import { Observable, ReplaySubject } from 'rxjs';
import { finalize, tap } from 'rxjs/operators';
// TODO injecter
import { Configuration } from '../configuration';
export interface RequestDebugEvent {
id: string;
type: 'request';
......@@ -37,11 +34,7 @@ export type DebugEvent =
export class ApiDebugInterceptor implements HttpInterceptor {
private readonly sink$ = new ReplaySubject<DebugEvent>(10);
public readonly events$ = this.sink$.asObservable();
private readonly enabled: boolean;
constructor(conf: Configuration) {
this.enabled = conf.debug;
}
private readonly enabled = true;
public intercept(
request: HttpRequest<any>,
......
import { Injectable } from '@angular/core';
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';
......@@ -8,6 +8,8 @@ export const enum DebugState {
ENABLED = 1,
}
export const ProductionToken = new InjectionToken<boolean>('production');
@Injectable()
export class DebugStateService {
private readonly state$: BehaviorSubject<DebugState>;
......@@ -26,7 +28,9 @@ export class DebugStateService {
return this.state === DebugState.ENABLED;
}
public constructor(production: boolean = false) {
public constructor(
@Inject(ProductionToken) @Optional() production: boolean = false
) {
this.state$ = new BehaviorSubject<DebugState>(
production ? DebugState.UNAVAILABLE : DebugState.ENABLED
);
......
......@@ -15,7 +15,6 @@ import { TreeModule } from 'primeng/tree';
import { TreeTableModule } from 'primeng/treetable';
import { ApiDebugComponent } from './api/api-debug.component';
import { Configuration, configurationFactory } from './configuration';
import { DebugStateService } from './debug-state.service';
import { DebugToggleComponent } from './debug-toggle.component';
import { DumpPanelComponent } from './dump-panel.component';
......@@ -51,7 +50,6 @@ const EXPORTED_COMPONENTS = [
providers: [
WatchService,
DebugStateService,
{ provide: Configuration, useFactory: configurationFactory },
{ provide: LOCALE_ID, useValue: 'fr' },
],
declarations: [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment