1- import { JsonRipper } from './services/json-ripper' ;
1+ import { IStoreService } from './sources/store-service.interface' ;
2+ import { IRipper } from './services/json-ripper.interface' ;
3+ import { Injector , Injectable , Optional , isDevMode } from '@angular/core' ;
24import { CacheMemory } from './services/cachememory' ;
3- import { Injectable , Optional , isDevMode } from '@angular/core' ;
45import { serviceIsRegistered } from './common' ;
56import { PathBuilder } from './services/path-builder' ;
67import { Service } from './service' ;
78import { Resource } from './resource' ;
89import { JsonapiConfig } from './jsonapi-config' ;
910import { Http as JsonapiHttpImported } from './sources/http.service' ;
10- import { StoreService as JsonapiStore } from './sources/store.service' ;
1111import { IDocumentResource } from './interfaces/data-object' ;
1212import { noop } from 'rxjs/internal/util/noop' ;
1313import { Observable , throwError } from 'rxjs' ;
1414import { tap , catchError } from 'rxjs/operators' ;
1515import { IDocumentData } from './interfaces/document' ;
1616
17+ export const JSONAPI_RIPPER_SERVICE = 'jsonapi_ripper_service' ;
18+ export const JSONAPI_STORE_SERVICE = 'jsonapi_store_service' ;
19+
1720@Injectable ( )
1821export class Core {
1922 public static me : Core ;
2023 public static injectedServices : {
21- JsonapiStoreService : JsonapiStore ;
24+ JsonapiStoreService : IStoreService ;
2225 JsonapiHttp : JsonapiHttpImported ;
26+ json_ripper : IRipper ;
2327 rsJsonapiConfig : JsonapiConfig ;
2428 } ;
2529 public loadingsCounter : number = 0 ;
@@ -31,16 +35,17 @@ export class Core {
3135
3236 private resourceServices : { [ type : string ] : Service } = { } ;
3337
34- public constructor ( @Optional ( ) user_config : JsonapiConfig , jsonapiStoreService : JsonapiStore , jsonapiHttp : JsonapiHttpImported ) {
38+ public constructor ( @Optional ( ) user_config : JsonapiConfig , jsonapiHttp : JsonapiHttpImported , injector : Injector ) {
3539 this . config = new JsonapiConfig ( ) ;
3640 for ( let k in this . config ) {
3741 ( < any > this . config ) [ k ] = user_config [ k ] !== undefined ? user_config [ k ] : ( < any > this . config ) [ k ] ;
3842 }
3943
4044 Core . me = this ;
4145 Core . injectedServices = {
42- JsonapiStoreService : jsonapiStoreService ,
46+ JsonapiStoreService : injector . get < IStoreService > ( < any > JSONAPI_STORE_SERVICE ) ,
4347 JsonapiHttp : jsonapiHttp ,
48+ json_ripper : injector . get < IRipper > ( < any > JSONAPI_RIPPER_SERVICE ) ,
4449 rsJsonapiConfig : this . config
4550 } ;
4651 }
@@ -110,17 +115,13 @@ export class Core {
110115 @serviceIsRegistered
111116 public static removeCachedResource ( resource_type : string , resource_id : string ) : void {
112117 CacheMemory . getInstance ( ) . removeResource ( resource_type , resource_id ) ;
113- if ( Core . injectedServices . rsJsonapiConfig . cachestore_support ) {
114- // TODO: FE-85 ---> add method on JsonRipper
115- }
118+ // TODO: FE-85 ---> add method on JsonRipper, if store is enabled
116119 }
117120
118121 @serviceIsRegistered
119122 public static setCachedResource ( resource : Resource ) : void {
120123 CacheMemory . getInstance ( ) . setResource ( resource , true ) ;
121- if ( Core . injectedServices . rsJsonapiConfig . cachestore_support ) {
122- // TODO: FE-85 ---> add method on JsonRipper
123- }
124+ // TODO: FE-85 ---> add method on JsonRipper, if store is enabled
124125 }
125126
126127 @serviceIsRegistered
@@ -129,9 +130,7 @@ export class Core {
129130 let path = new PathBuilder ( ) ;
130131 path . applyParams ( service ) ;
131132 CacheMemory . getInstance ( ) . deprecateCollections ( path . getForCache ( ) ) ;
132- if ( Core . injectedServices . rsJsonapiConfig . cachestore_support ) {
133- // TODO: FE-85 ---> add method on JsonRipper
134- }
133+ // TODO: FE-85 ---> add method on JsonRipper, if store is enabled
135134 }
136135
137136 public refreshLoadings ( factor : number ) : void {
@@ -146,9 +145,8 @@ export class Core {
146145 public async clearCache ( ) : Promise < boolean > {
147146 Core . injectedServices . JsonapiStoreService . clearCache ( ) ;
148147 CacheMemory . getInstance ( ) . clearCache ( ) ;
149- let json_ripper = new JsonRipper ( ) ;
150148
151- return json_ripper . deprecateCollection ( '' ) . then ( ( ) => true ) ;
149+ return Core . injectedServices . json_ripper . deprecateCollection ( '' ) . then ( ( ) => true ) ;
152150 }
153151
154152 // just an helper
0 commit comments