2016-07-18 06:50:31 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-30 21:07:40 -04:00
|
|
|
import {NgModuleResolver} from '@angular/compiler';
|
2016-09-12 22:14:17 -04:00
|
|
|
import {Compiler, Injectable, Injector, NgModule, Type} from '@angular/core';
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class MockNgModuleResolver extends NgModuleResolver {
|
2016-09-12 22:14:17 -04:00
|
|
|
private _ngModules = new Map<Type<any>, NgModule>();
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
constructor(private _injector: Injector) { super(); }
|
|
|
|
|
|
|
|
/**
|
2016-09-12 22:14:17 -04:00
|
|
|
* Overrides the {@link NgModule} for a module.
|
2016-07-18 06:50:31 -04:00
|
|
|
*/
|
2016-09-12 22:14:17 -04:00
|
|
|
setNgModule(type: Type<any>, metadata: NgModule): void {
|
2016-07-18 06:50:31 -04:00
|
|
|
this._ngModules.set(type, metadata);
|
|
|
|
this._clearCacheFor(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-12 22:14:17 -04:00
|
|
|
* Returns the {@link NgModule} for a module:
|
|
|
|
* - Set the {@link NgModule} to the overridden view when it exists or fallback to the
|
2016-07-18 06:50:31 -04:00
|
|
|
* default
|
|
|
|
* `NgModuleResolver`, see `setNgModule`.
|
|
|
|
*/
|
2016-09-12 22:14:17 -04:00
|
|
|
resolve(type: Type<any>, throwIfNotFound = true): NgModule {
|
2016-09-19 20:15:57 -04:00
|
|
|
return this._ngModules.get(type) || super.resolve(type, throwIfNotFound);
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|
2016-09-19 20:15:57 -04:00
|
|
|
|
|
|
|
private get _compiler(): Compiler { return this._injector.get(Compiler); }
|
|
|
|
|
|
|
|
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|