fix(router): merge SystemJsAppModuleFactoryLoader and SystemJsAllModuleLoader

This commit is contained in:
vsavkin
2016-07-13 10:39:16 -07:00
parent 0b54e3cf0a
commit 0426325ef7
6 changed files with 21 additions and 30 deletions

View File

@ -7,7 +7,7 @@
*/
import {Injectable} from '../di';
import {Injectable, Optional} from '../di';
import {global} from '../facade/lang';
import {AppModuleFactory} from './app_module_factory';
@ -16,15 +16,22 @@ import {Compiler} from './compiler';
const _SEPARATOR = '#';
const FACTORY_MODULE_SUFFIX = '.ngfactory';
const FACTORY_CLASS_SUFFIX = 'NgFactory';
/**
* AppModuleFactoryLoader that uses SystemJS to load AppModule type and then compiles them.
* AppModuleFactoryLoader that uses SystemJS to load AppModuleFactory
* @experimental
*/
@Injectable()
export class SystemJsAppModuleLoader implements AppModuleFactoryLoader {
constructor(private _compiler: Compiler) {}
constructor(@Optional() private _compiler: Compiler) {}
load(path: string): Promise<AppModuleFactory<any>> {
return this._compiler ? this.loadAndCompile(path) : this.loadFactory(path);
}
private loadAndCompile(path: string): Promise<AppModuleFactory<any>> {
let [module, exportName] = path.split(_SEPARATOR);
if (exportName === undefined) exportName = 'default';
@ -34,17 +41,8 @@ export class SystemJsAppModuleLoader implements AppModuleFactoryLoader {
.then((type: any) => checkNotEmpty(type, module, exportName))
.then((type: any) => this._compiler.compileAppModuleAsync(type));
}
}
const FACTORY_MODULE_SUFFIX = '.ngfactory';
const FACTORY_CLASS_SUFFIX = 'NgFactory';
/**
* AppModuleFactoryLoader that uses SystemJS to load AppModuleFactories
* @experimental
*/
export class SystemJsAppModuleFactoryLoader implements AppModuleFactoryLoader {
load(path: string): Promise<AppModuleFactory<any>> {
private loadFactory(path: string): Promise<AppModuleFactory<any>> {
let [module, exportName] = path.split(_SEPARATOR);
if (exportName === undefined) exportName = 'default';

View File

@ -53,7 +53,7 @@ const FACTORY_CLASS_SUFFIX = 'NgFactory';
/**
* Component resolver that can load component factories lazily
*
* @deprecated Lazy loading of components is deprecated. Use {@link SystemJsAppModuleFactoryLoader}
* @deprecated Lazy loading of components is deprecated. Use {@link SystemJsAppModuleLoader}
* to lazy
* load {@link AppModuleFactory}s instead.
*/