From 0426325ef7f85176aeb922a091a0722fd99e1c42 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 13 Jul 2016 10:39:16 -0700 Subject: [PATCH] fix(router): merge SystemJsAppModuleFactoryLoader and SystemJsAllModuleLoader --- modules/@angular/core/src/linker.ts | 2 +- .../system_js_app_module_factory_loader.ts | 24 +++++++++---------- .../src/linker/systemjs_component_resolver.ts | 2 +- modules/@angular/router/src/router.ts | 8 +++---- modules/@angular/router/test/router.spec.ts | 10 ++++---- tools/public_api_guard/core/index.d.ts | 5 ---- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/modules/@angular/core/src/linker.ts b/modules/@angular/core/src/linker.ts index 0c9aedb00e..345f916b41 100644 --- a/modules/@angular/core/src/linker.ts +++ b/modules/@angular/core/src/linker.ts @@ -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'; diff --git a/modules/@angular/core/src/linker/system_js_app_module_factory_loader.ts b/modules/@angular/core/src/linker/system_js_app_module_factory_loader.ts index 1f7d8334f3..f070bc518b 100644 --- a/modules/@angular/core/src/linker/system_js_app_module_factory_loader.ts +++ b/modules/@angular/core/src/linker/system_js_app_module_factory_loader.ts @@ -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> { + return this._compiler ? this.loadAndCompile(path) : this.loadFactory(path); + } + + private loadAndCompile(path: string): Promise> { 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> { + private loadFactory(path: string): Promise> { let [module, exportName] = path.split(_SEPARATOR); if (exportName === undefined) exportName = 'default'; diff --git a/modules/@angular/core/src/linker/systemjs_component_resolver.ts b/modules/@angular/core/src/linker/systemjs_component_resolver.ts index e32feadf34..6383520792 100644 --- a/modules/@angular/core/src/linker/systemjs_component_resolver.ts +++ b/modules/@angular/core/src/linker/systemjs_component_resolver.ts @@ -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. */ diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index 782ebf44e2..63cbaa4320 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -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; }); } diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index f456142c71..dfbe2200d2 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -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', () => { (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 => {}) diff --git a/tools/public_api_guard/core/index.d.ts b/tools/public_api_guard/core/index.d.ts index 2e9e566ea4..ee4e59b9c9 100644 --- a/tools/public_api_guard/core/index.d.ts +++ b/tools/public_api_guard/core/index.d.ts @@ -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>; -} - /** @experimental */ export declare class SystemJsAppModuleLoader implements AppModuleFactoryLoader { constructor(_compiler: Compiler);