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

Tentative de configuration DebugModule.forRoot().

No related merge requests found
Showing with 56 additions and 22 deletions
+56 -22
......@@ -2003,6 +2003,7 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@devatscience/ngx-rxtools/-/ngx-rxtools-1.1.0.tgz",
"integrity": "sha512-UCIavkf2dYoeScSiYk3iBRkXPnqL2FJ5WlVZepOehaUgy7RPLIomWMh0wLGLYHTFLlvy1v3V1FLyDmS8GDOz2w==",
"dev": true,
"requires": {
"tslib": "^1.9.0"
}
......@@ -6001,9 +6002,9 @@
"dev": true
},
"handlebars": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.2.0.tgz",
"integrity": "sha512-Kb4xn5Qh1cxAKvQnzNWZ512DhABzyFNmsaJf3OAkWNa4NkaqWcNI8Tao8Tasi0/F4JD9oyG0YxuFyvyR57d+Gw==",
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.3.tgz",
"integrity": "sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw==",
"dev": true,
"requires": {
"neo-async": "^2.6.0",
......@@ -12204,13 +12205,13 @@
"dev": true
},
"uglify-js": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz",
"integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==",
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz",
"integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==",
"dev": true,
"optional": true,
"requires": {
"commander": "~2.20.0",
"commander": "2.20.0",
"source-map": "~0.6.1"
},
"dependencies": {
......
......@@ -16,6 +16,9 @@
"type": "git",
"url": "https://gitlab.irstea.fr/pole-is/packages/ngx-debug.git"
},
"dependencies": {
"tslib": "^1.10.0"
},
"peerDependencies": {
"@angular/common": "^8",
"@angular/core": "^8",
......
......@@ -2,8 +2,12 @@
* Public API Surface of ngx-debug
*/
export * from './lib/debug.module';
export * from './lib/spy/spy.operator';
export * from './lib/api/api-debug.interceptor';
export * from './lib/api/api-debug.component';
export * from './lib/debug.module';
export * from './lib/dump-value.component';
export * from './lib/watch/watch.component';
export * from './lib/watch/watch.service';
export * from './lib/debug-toggle.component';
export * from './lib/debug-state.service';
export * from './lib/spy/spy.operator';
import { HttpRequest, HttpResponseBase } from '@angular/common/http';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Inject, InjectionToken, Output } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Inject,
InjectionToken,
Output,
} from '@angular/core';
import { DebugStateService } from '../debug-state.service';
......@@ -38,7 +46,7 @@ export class ApiDebugComponent {
interceptor: ApiDebugInterceptor,
public readonly debug: DebugStateService,
private readonly cd: ChangeDetectorRef,
@Inject(ApiBaseUrlToken) private readonly apiPrefix: string,
@Inject(ApiBaseUrlToken) private readonly apiPrefix: string
) {
interceptor.events$.subscribe(ev => {
this.handle(ev);
......@@ -78,7 +86,7 @@ export class ApiDebugComponent {
private addRequest(
id: string,
{ urlWithParams, method }: HttpRequest<any>,
{ urlWithParams, method }: HttpRequest<any>
): void {
if (urlWithParams.startsWith(this.apiPrefix)) {
urlWithParams = new URL(urlWithParams).pathname;
......@@ -96,7 +104,7 @@ export class ApiDebugComponent {
private setResponse(
request: RequestInfo,
{ status, statusText, headers }: HttpResponseBase,
{ status, statusText, headers }: HttpResponseBase
): void {
request.response = {
status,
......@@ -124,7 +132,7 @@ export class ApiDebugComponent {
}
public get last(): RequestInfo | null {
return this.ids.length ? this.requests.get(this.ids[ 0 ]) : null;
return this.ids.length ? this.requests.get(this.ids[0]) : null;
}
public get previous(): RequestInfo[] {
......
export * from './api-debug.component';
export * from './api-debug.interceptor';
import { CommonModule } from '@angular/common';
import { LOCALE_ID, NgModule } from '@angular/core';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LOCALE_ID, ModuleWithProviders, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {
ButtonModule,
......@@ -14,8 +15,9 @@ import {
import { TreeModule } from 'primeng/tree';
import { TreeTableModule } from 'primeng/treetable';
import { ApiDebugComponent } from './api';
import { DebugStateService } from './debug-state.service';
import { ApiBaseUrlToken, ApiDebugComponent } from './api/api-debug.component';
import { ApiDebugInterceptor } from './api/api-debug.interceptor';
import { DebugStateService, ProductionToken } from './debug-state.service';
import { DebugToggleComponent } from './debug-toggle.component';
import { DumpPanelComponent } from './dump-panel.component';
import { DumpValueComponent } from './dump-value.component';
......@@ -61,4 +63,23 @@ const EXPORTED_COMPONENTS = [
],
exports: [...EXPORTED_COMPONENTS],
})
export class DebugModule {}
export class DebugModule {
public static forRoot(
apiBaseUrl: string,
production: boolean
): ModuleWithProviders {
// TODO: fournir un module différent en prod (+ léger) et en dev (complet)
return {
ngModule: DebugModule,
providers: [
{ provide: ProductionToken, useValue: production },
{ provide: ApiBaseUrlToken, useValue: apiBaseUrl },
{
provide: HTTP_INTERCEPTORS,
useClass: ApiDebugInterceptor,
multi: true,
},
],
};
}
}
......@@ -20,6 +20,6 @@
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"files": ["src/**/*.ts"],
"include": ["src/**/*.ts"],
"exclude": ["src/test.ts", "**/*.spec.ts"]
}
......@@ -4,6 +4,5 @@
"outDir": "out-tsc/spec",
"types": ["jasmine", "node"]
},
"files": ["src/test.ts"],
"exclude": []
}
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