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

@ -17,7 +17,7 @@ export {DynamicComponentLoader} from './linker/dynamic_component_loader';
export {ElementRef} from './linker/element_ref';
export {ExpressionChangedAfterItHasBeenCheckedException} from './linker/exceptions';
export {QueryList} from './linker/query_list';
export {SystemJsAppModuleFactoryLoader, SystemJsAppModuleLoader} from './linker/system_js_app_module_factory_loader';
export {SystemJsAppModuleLoader} from './linker/system_js_app_module_factory_loader';
export {SystemJsCmpFactoryResolver, SystemJsComponentResolver} from './linker/systemjs_component_resolver';
export {TemplateRef} from './linker/template_ref';
export {ViewContainerRef} from './linker/view_container_ref';

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.
*/

View File

@ -291,11 +291,9 @@ export class Router {
const tree = this.urlSerializer.parse(change['url']);
// we fire multiple events for a single URL change
// we should navigate only once
if (this.currentUrlTree.toString() !== tree.toString()) {
return this.scheduleNavigation(tree, change['pop']);
} else {
return null;
}
return this.currentUrlTree.toString() !== tree.toString() ?
this.scheduleNavigation(tree, change['pop']) :
null;
});
}

View File

@ -111,7 +111,7 @@ describe('Integration', () => {
children: [{path: 'user/:name', component: UserCmp}]
}]);
const recordedEvents: any = [];
const recordedEvents: any[] = [];
router.events.forEach(e => recordedEvents.push(e));
router.navigateByUrl('/team/22/user/victor');
@ -123,7 +123,7 @@ describe('Integration', () => {
(<any>location).simulateUrlPop('/team/22/user/fedor');
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { user fedor, right: }');
expect(fixture.debugElement.nativeElement).toHaveText('team 22 [ user fedor, right: ]');
expectEvents(recordedEvents, [
[NavigationStart, '/team/22/user/victor'], [RoutesRecognized, '/team/22/user/victor'],
@ -298,7 +298,7 @@ describe('Integration', () => {
router.resetConfig([{path: 'user/:name', component: UserCmp}]);
const recordedEvents: any = [];
const recordedEvents: any[] = [];
router.events.forEach(e => recordedEvents.push(e));
router.navigateByUrl('/user/init');
@ -335,7 +335,7 @@ describe('Integration', () => {
router.resetConfig([{path: 'user/:name', component: UserCmp}]);
const recordedEvents: any = [];
const recordedEvents: any[] = [];
router.events.forEach(e => recordedEvents.push(e));
let e: any;
@ -1217,7 +1217,7 @@ describe('Integration', () => {
router.resetConfig([{path: 'lazy', loadChildren: 'invalid'}]);
const recordedEvents: any = [];
const recordedEvents: any[] = [];
router.events.forEach(e => recordedEvents.push(e));
router.navigateByUrl('/lazy/loaded').catch(s => {})

View File

@ -1336,11 +1336,6 @@ export declare function style(tokens: string | {
[key: string]: string | number;
}>): AnimationStyleMetadata;
/** @experimental */
export declare class SystemJsAppModuleFactoryLoader implements AppModuleFactoryLoader {
load(path: string): Promise<AppModuleFactory<any>>;
}
/** @experimental */
export declare class SystemJsAppModuleLoader implements AppModuleFactoryLoader {
constructor(_compiler: Compiler);