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 { ...@@ -7,8 +7,6 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
// TODO injecter
import { Configuration } from '../configuration';
import { DebugStateService } from '../debug-state.service'; import { DebugStateService } from '../debug-state.service';
import { ApiDebugInterceptor, DebugEvent } from './api-debug.interceptor'; import { ApiDebugInterceptor, DebugEvent } from './api-debug.interceptor';
...@@ -28,6 +26,8 @@ interface ResponseInfo { ...@@ -28,6 +26,8 @@ interface ResponseInfo {
tokenLink?: string; tokenLink?: string;
} }
export const ApiBaseUrlToken = new InjectionToken<string>('apiBaseUrl');
@Component({ @Component({
selector: 'dbg-api-debug', selector: 'dbg-api-debug',
templateUrl: './api-debug.component.html', templateUrl: './api-debug.component.html',
...@@ -46,10 +46,8 @@ export class ApiDebugComponent { ...@@ -46,10 +46,8 @@ export class ApiDebugComponent {
interceptor: ApiDebugInterceptor, interceptor: ApiDebugInterceptor,
public readonly debug: DebugStateService, public readonly debug: DebugStateService,
private readonly cd: ChangeDetectorRef, private readonly cd: ChangeDetectorRef,
conf: Configuration @Inject(ApiBaseUrlToken) private readonly apiPrefix: string,
) { ) {
this.apiPrefix = conf.apiBaseURL;
interceptor.events$.subscribe(ev => { interceptor.events$.subscribe(ev => {
this.handle(ev); this.handle(ev);
}); });
......
...@@ -9,9 +9,6 @@ import * as _ from 'lodash'; ...@@ -9,9 +9,6 @@ import * as _ from 'lodash';
import { Observable, ReplaySubject } from 'rxjs'; import { Observable, ReplaySubject } from 'rxjs';
import { finalize, tap } from 'rxjs/operators'; import { finalize, tap } from 'rxjs/operators';
// TODO injecter
import { Configuration } from '../configuration';
export interface RequestDebugEvent { export interface RequestDebugEvent {
id: string; id: string;
type: 'request'; type: 'request';
...@@ -37,11 +34,7 @@ export type DebugEvent = ...@@ -37,11 +34,7 @@ export type DebugEvent =
export class ApiDebugInterceptor implements HttpInterceptor { export class ApiDebugInterceptor implements HttpInterceptor {
private readonly sink$ = new ReplaySubject<DebugEvent>(10); private readonly sink$ = new ReplaySubject<DebugEvent>(10);
public readonly events$ = this.sink$.asObservable(); public readonly events$ = this.sink$.asObservable();
private readonly enabled: boolean; private readonly enabled = true;
constructor(conf: Configuration) {
this.enabled = conf.debug;
}
public intercept( public intercept(
request: HttpRequest<any>, request: HttpRequest<any>,
......
import { Injectable } from '@angular/core'; import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs'; import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators'; import { distinctUntilChanged, map } from 'rxjs/operators';
...@@ -8,6 +8,8 @@ export const enum DebugState { ...@@ -8,6 +8,8 @@ export const enum DebugState {
ENABLED = 1, ENABLED = 1,
} }
export const ProductionToken = new InjectionToken<boolean>('production');
@Injectable() @Injectable()
export class DebugStateService { export class DebugStateService {
private readonly state$: BehaviorSubject<DebugState>; private readonly state$: BehaviorSubject<DebugState>;
...@@ -26,7 +28,9 @@ export class DebugStateService { ...@@ -26,7 +28,9 @@ export class DebugStateService {
return this.state === DebugState.ENABLED; return this.state === DebugState.ENABLED;
} }
public constructor(production: boolean = false) { public constructor(
@Inject(ProductionToken) @Optional() production: boolean = false
) {
this.state$ = new BehaviorSubject<DebugState>( this.state$ = new BehaviorSubject<DebugState>(
production ? DebugState.UNAVAILABLE : DebugState.ENABLED production ? DebugState.UNAVAILABLE : DebugState.ENABLED
); );
......
...@@ -15,7 +15,6 @@ import { TreeModule } from 'primeng/tree'; ...@@ -15,7 +15,6 @@ import { TreeModule } from 'primeng/tree';
import { TreeTableModule } from 'primeng/treetable'; import { TreeTableModule } from 'primeng/treetable';
import { ApiDebugComponent } from './api/api-debug.component'; import { ApiDebugComponent } from './api/api-debug.component';
import { Configuration, configurationFactory } from './configuration';
import { DebugStateService } from './debug-state.service'; import { DebugStateService } from './debug-state.service';
import { DebugToggleComponent } from './debug-toggle.component'; import { DebugToggleComponent } from './debug-toggle.component';
import { DumpPanelComponent } from './dump-panel.component'; import { DumpPanelComponent } from './dump-panel.component';
...@@ -51,7 +50,6 @@ const EXPORTED_COMPONENTS = [ ...@@ -51,7 +50,6 @@ const EXPORTED_COMPONENTS = [
providers: [ providers: [
WatchService, WatchService,
DebugStateService, DebugStateService,
{ provide: Configuration, useFactory: configurationFactory },
{ provide: LOCALE_ID, useValue: 'fr' }, { provide: LOCALE_ID, useValue: 'fr' },
], ],
declarations: [ 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