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-07-18 06:50:31 -04:00
|
|
|
import {Compiler, Injectable, Injector, NgModuleMetadata, Type} from '@angular/core';
|
|
|
|
|
2016-08-30 21:07:40 -04:00
|
|
|
import {Map} from './facade/collection';
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class MockNgModuleResolver extends NgModuleResolver {
|
2016-08-10 21:21:28 -04:00
|
|
|
private _ngModules = new Map<Type<any>, NgModuleMetadata>();
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
constructor(private _injector: Injector) { super(); }
|
|
|
|
|
|
|
|
private get _compiler(): Compiler { return this._injector.get(Compiler); }
|
|
|
|
|
2016-08-10 21:21:28 -04:00
|
|
|
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides the {@link NgModuleMetadata} for a module.
|
|
|
|
*/
|
2016-08-10 21:21:28 -04:00
|
|
|
setNgModule(type: Type<any>, metadata: NgModuleMetadata): void {
|
2016-07-18 06:50:31 -04:00
|
|
|
this._ngModules.set(type, metadata);
|
|
|
|
this._clearCacheFor(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@link NgModuleMetadata} for a module:
|
|
|
|
* - Set the {@link NgModuleMetadata} to the overridden view when it exists or fallback to the
|
|
|
|
* default
|
|
|
|
* `NgModuleResolver`, see `setNgModule`.
|
|
|
|
*/
|
2016-08-10 21:21:28 -04:00
|
|
|
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata {
|
2016-07-18 06:50:31 -04:00
|
|
|
var metadata = this._ngModules.get(type);
|
|
|
|
if (!metadata) {
|
|
|
|
metadata = super.resolve(type, throwIfNotFound);
|
|
|
|
}
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
}
|