From f2512990f150f450bd40f379e1b669206d143354 Mon Sep 17 00:00:00 2001 From: supamiu Date: Tue, 25 Sep 2018 14:43:50 +0200 Subject: [PATCH] fix: fixed aot error with forRoot method --- index.ts | 2 -- package.json | 2 +- public_api.ts | 3 +- src/xivapi-client.module.ts | 17 +++++---- src/{index.ts => xivapi-client.ts} | 2 +- src/xivapi-service-factory.ts | 6 ++++ src/xivapi.service.ts | 5 ++- test/xivapi.service.spec.ts | 2 +- tsconfig-build.json | 58 +++++++++++++++--------------- 9 files changed, 50 insertions(+), 47 deletions(-) delete mode 100644 index.ts rename src/{index.ts => xivapi-client.ts} (52%) create mode 100644 src/xivapi-service-factory.ts diff --git a/index.ts b/index.ts deleted file mode 100644 index 01ffa83..0000000 --- a/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -// Public classes. -export * from './src/index'; diff --git a/package.json b/package.json index 8f048f8..b897c1f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "docs:generate": "npm run docs:clean && typedoc --out docs --excludePrivate --mode file --exclude \"**/*+(index|spec|entry).ts\" ./src", "docs:clean": "del-cli docs/" }, - "typings": "./angular-client.d.ts", + "typings": "./xivapi-client.d.ts", "author": "Supamiu", "repository": { "type": "git", diff --git a/public_api.ts b/public_api.ts index ea465c2..0ab75ec 100644 --- a/public_api.ts +++ b/public_api.ts @@ -1 +1,2 @@ -export * from './index'; +// Public classes. +export * from './src/xivapi-client'; diff --git a/src/xivapi-client.module.ts b/src/xivapi-client.module.ts index 8e54ccf..37ef7af 100644 --- a/src/xivapi-client.module.ts +++ b/src/xivapi-client.module.ts @@ -1,12 +1,8 @@ -import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core'; +import { ModuleWithProviders, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { XivapiService } from './xivapi.service'; -import { HttpClientModule } from '@angular/common/http'; - -/** - * @hidden - */ -export const XIVAPI_KEY: InjectionToken = new InjectionToken('XIVAPI_KEY'); +import { HttpClient, HttpClientModule } from '@angular/common/http'; +import { XivapiServiceFactory } from './xivapi-service-factory'; @NgModule({ imports: [ @@ -21,8 +17,11 @@ export class XivapiClientModule { return { ngModule: XivapiClientModule, providers: [ - XivapiService, - {provide: XIVAPI_KEY, useValue: key} + { + provide: XivapiService, + useFactory: XivapiServiceFactory, + deps: [key, HttpClient] + } ] }; } diff --git a/src/index.ts b/src/xivapi-client.ts similarity index 52% rename from src/index.ts rename to src/xivapi-client.ts index 5258263..11d699b 100644 --- a/src/index.ts +++ b/src/xivapi-client.ts @@ -1,3 +1,3 @@ -export { XivapiClientModule, XIVAPI_KEY } from './xivapi-client.module'; +export { XivapiClientModule } from './xivapi-client.module'; export { XivapiService } from './xivapi.service'; export * from './model/index'; diff --git a/src/xivapi-service-factory.ts b/src/xivapi-service-factory.ts new file mode 100644 index 0000000..717529d --- /dev/null +++ b/src/xivapi-service-factory.ts @@ -0,0 +1,6 @@ +import { XivapiService } from './xivapi.service'; +import { HttpClient } from '@angular/common/http'; + +export function XivapiServiceFactory(key: string, http: HttpClient): XivapiService { + return new XivapiService(key, http); +} diff --git a/src/xivapi.service.ts b/src/xivapi.service.ts index a26725e..115d2a9 100644 --- a/src/xivapi.service.ts +++ b/src/xivapi.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable } from '@angular/core'; +import { Inject, Injectable, Optional } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { @@ -11,7 +11,6 @@ import { XivapiRequestOptions, XivapiSearchOptions } from './model'; -import { XIVAPI_KEY } from './xivapi-client.module'; import { CharacterResponse, CharacterVerification } from './model/schema/character'; @Injectable() @@ -22,7 +21,7 @@ export class XivapiService { */ public static readonly API_BASE_URL: string = 'https://xivapi.com'; - constructor(@Inject(XIVAPI_KEY) protected readonly apiKey: string, private http: HttpClient) { + constructor(@Inject('XIVAPI_KEY') protected readonly apiKey: string, private http: HttpClient) { } /** diff --git a/test/xivapi.service.spec.ts b/test/xivapi.service.spec.ts index d0a05c0..0424811 100644 --- a/test/xivapi.service.spec.ts +++ b/test/xivapi.service.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@angular/core/testing'; -import { SearchIndex, XivapiService } from '../src'; +import { SearchIndex, XivapiService } from '../src/xivapi-client'; import { HttpClientTestingModule, HttpTestingController, TestRequest } from '@angular/common/http/testing'; import { HttpClient } from '@angular/common/http'; diff --git a/tsconfig-build.json b/tsconfig-build.json index e36fd84..0b90502 100644 --- a/tsconfig-build.json +++ b/tsconfig-build.json @@ -1,31 +1,31 @@ { - "compilerOptions": { - "baseUrl": ".", - "declaration": true, - "experimentalDecorators": true, - "strict": true, - "module": "es2015", - "moduleResolution": "node", - "outDir": "dist", - "rootDir": ".", - "sourceMap": true, - "inlineSources": true, - "target": "es2015", - "skipLibCheck": true, - "lib": [ - "es2015", - "dom" - ] - }, - "files": [ - "public_api.ts", - "node_modules/zone.js/dist/zone.js.d.ts" - ], - "angularCompilerOptions": { - "skipTemplateCodegen": true, - "annotateForClosureCompiler": true, - "strictMetadataEmit": true, - "flatModuleOutFile": "xivapi-client.js", - "flatModuleId": "@xivapi/angular-client" - } + "compilerOptions": { + "baseUrl": ".", + "declaration": true, + "experimentalDecorators": true, + "strict": true, + "module": "es2015", + "moduleResolution": "node", + "outDir": "dist", + "rootDir": ".", + "sourceMap": true, + "inlineSources": true, + "target": "es2015", + "skipLibCheck": true, + "lib": [ + "es2015", + "dom" + ] + }, + "files": [ + "public_api.ts", + "node_modules/zone.js/dist/zone.js.d.ts" + ], + "angularCompilerOptions": { + "skipTemplateCodegen": true, + "annotateForClosureCompiler": true, + "strictMetadataEmit": true, + "flatModuleOutFile": "xivapi-client.js", + "flatModuleId": "@xivapi/angular-client" + } }