| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | import {ObservableWrapper, PromiseWrapper} from '../src/facade/async'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {ListWrapper} from '../src/facade/collection'; | 
					
						
							| 
									
										
										
										
											2016-05-01 22:50:37 -07:00
										 |  |  | import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions'; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | import {IS_DART, Type, assertionsEnabled, isBlank, isPresent, isPromise, lockMode} from '../src/facade/lang'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {APP_INITIALIZER, PLATFORM_INITIALIZER} from './application_tokens'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {ChangeDetectorRef} from './change_detection/change_detector_ref'; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | import {Console} from './console'; | 
					
						
							|  |  |  | import {Injectable, Injector} from './di'; | 
					
						
							|  |  |  | import {ComponentFactory, ComponentRef} from './linker/component_factory'; | 
					
						
							|  |  |  | import {ComponentResolver} from './linker/component_resolver'; | 
					
						
							|  |  |  | import {WtfScopeFn, wtfCreateScope, wtfLeave} from './profile/profile'; | 
					
						
							|  |  |  | import {Testability, TestabilityRegistry} from './testability/testability'; | 
					
						
							|  |  |  | import {NgZone, NgZoneError} from './zone/ng_zone'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Create an Angular zone. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | export function createNgZone(): NgZone { | 
					
						
							| 
									
										
										
										
											2015-10-08 13:33:22 -07:00
										 |  |  |   return new NgZone({enableLongStackTrace: assertionsEnabled()}); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var _platform: PlatformRef; | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | var _inPlatformCreate: boolean = false; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-13 11:21:16 -08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |  * Creates a platform. | 
					
						
							|  |  |  |  * Platforms have to be eagerly created via this function. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2015-11-13 11:21:16 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | export function createPlatform(injector: Injector): PlatformRef { | 
					
						
							|  |  |  |   if (_inPlatformCreate) { | 
					
						
							|  |  |  |     throw new BaseException('Already creating a platform...'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (isPresent(_platform) && !_platform.disposed) { | 
					
						
							|  |  |  |     throw new BaseException( | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         'There can be only one platform. Destroy the previous one to create a new one.'); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-15 08:34:44 -08:00
										 |  |  |   lockMode(); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   _inPlatformCreate = true; | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     _platform = injector.get(PlatformRef); | 
					
						
							|  |  |  |   } finally { | 
					
						
							|  |  |  |     _inPlatformCreate = false; | 
					
						
							| 
									
										
										
										
											2015-11-12 13:40:29 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   return _platform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Checks that there currently is a platform | 
					
						
							|  |  |  |  * which contains the given token as a provider. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | export function assertPlatform(requiredToken: any): PlatformRef { | 
					
						
							|  |  |  |   var platform = getPlatform(); | 
					
						
							|  |  |  |   if (isBlank(platform)) { | 
					
						
							| 
									
										
										
										
											2016-05-20 11:18:08 -07:00
										 |  |  |     throw new BaseException('No platform exists!'); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (isPresent(platform) && isBlank(platform.injector.get(requiredToken, null))) { | 
					
						
							|  |  |  |     throw new BaseException( | 
					
						
							|  |  |  |         'A platform with a different configuration has been created. Please destroy it first.'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return platform; | 
					
						
							| 
									
										
										
										
											2015-11-13 11:21:16 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-12 13:40:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 09:18:37 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Dispose the existing platform. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2015-11-18 09:18:37 -08:00
										 |  |  |  */ | 
					
						
							|  |  |  | export function disposePlatform(): void { | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   if (isPresent(_platform) && !_platform.disposed) { | 
					
						
							| 
									
										
										
										
											2015-11-18 09:18:37 -08:00
										 |  |  |     _platform.dispose(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Returns the current platform. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | export function getPlatform(): PlatformRef { | 
					
						
							|  |  |  |   return isPresent(_platform) && !_platform.disposed ? _platform : null; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Shortcut for ApplicationRef.bootstrap. | 
					
						
							| 
									
										
										
										
											2016-05-20 11:18:08 -07:00
										 |  |  |  * Requires a platform to be created first. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | export function coreBootstrap<C>( | 
					
						
							|  |  |  |     componentFactory: ComponentFactory<C>, injector: Injector): ComponentRef<C> { | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   var appRef: ApplicationRef = injector.get(ApplicationRef); | 
					
						
							|  |  |  |   return appRef.bootstrap(componentFactory); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Resolves the componentFactory for the given component, | 
					
						
							|  |  |  |  * waits for asynchronous initializers and bootstraps the component. | 
					
						
							| 
									
										
										
										
											2016-05-20 11:18:08 -07:00
										 |  |  |  * Requires a platform to be created first. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | export function coreLoadAndBootstrap( | 
					
						
							|  |  |  |     componentType: Type, injector: Injector): Promise<ComponentRef<any>> { | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   var appRef: ApplicationRef = injector.get(ApplicationRef); | 
					
						
							|  |  |  |   return appRef.run(() => { | 
					
						
							|  |  |  |     var componentResolver: ComponentResolver = injector.get(ComponentResolver); | 
					
						
							|  |  |  |     return PromiseWrapper | 
					
						
							|  |  |  |         .all([componentResolver.resolveComponent(componentType), appRef.waitForAsyncInitializers()]) | 
					
						
							|  |  |  |         .then((arr) => appRef.bootstrap(arr[0])); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-11-18 09:18:37 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |  * The Angular platform is the entry point for Angular on a web page. Each page | 
					
						
							|  |  |  |  * has exactly one platform, and services (such as reflection) which are common | 
					
						
							|  |  |  |  * to every Angular application running on the page are bound in its scope. | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |  * A page's platform is initialized implicitly when {@link bootstrap}() is called, or | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |  * explicitly by calling {@link createPlatform}(). | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @stable | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | export abstract class PlatformRef { | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Register a listener to be called when the platform is disposed. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract registerDisposeListener(dispose: () => void): void; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   /** | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |    * Retrieve the platform {@link Injector}, which is the parent injector for | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |    * every Angular application on the page and provides singleton providers. | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 |  |  |   get injector(): Injector { throw unimplemented(); }; | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Destroy the Angular platform and all Angular applications on the page. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract dispose(): void; | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   get disposed(): boolean { throw unimplemented(); } | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | export class PlatformRef_ extends PlatformRef { | 
					
						
							| 
									
										
										
										
											2015-10-09 17:21:25 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |   _applications: ApplicationRef[] = []; | 
					
						
							| 
									
										
										
										
											2015-10-28 14:16:54 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |   _disposeListeners: Function[] = []; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   private _disposed: boolean = false; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   constructor(private _injector: Injector) { | 
					
						
							|  |  |  |     super(); | 
					
						
							|  |  |  |     if (!_inPlatformCreate) { | 
					
						
							|  |  |  |       throw new BaseException('Platforms have to be created via `createPlatform`!'); | 
					
						
							| 
									
										
										
										
											2015-12-20 18:10:36 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     let inits: Function[] = <Function[]>_injector.get(PLATFORM_INITIALIZER, null); | 
					
						
							|  |  |  |     if (isPresent(inits)) inits.forEach(init => init()); | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   registerDisposeListener(dispose: () => void): void { this._disposeListeners.push(dispose); } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   get injector(): Injector { return this._injector; } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   get disposed() { return this._disposed; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   addApplication(appRef: ApplicationRef) { this._applications.push(appRef); } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  |   dispose(): void { | 
					
						
							| 
									
										
										
										
											2015-11-18 09:18:37 -08:00
										 |  |  |     ListWrapper.clone(this._applications).forEach((app) => app.dispose()); | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |     this._disposeListeners.forEach((dispose) => dispose()); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     this._disposed = true; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-09 17:21:25 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   _applicationDisposed(app: ApplicationRef): void { ListWrapper.remove(this._applications, app); } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |  * A reference to an Angular application running on a page. | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |  * For more about Angular applications, see the documentation for {@link bootstrap}. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @stable | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | export abstract class ApplicationRef { | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   /** | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |    * Register a listener to be called each time `bootstrap()` is called to bootstrap | 
					
						
							|  |  |  |    * a new root component. | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   abstract registerBootstrapListener(listener: (ref: ComponentRef<any>) => void): void; | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Register a listener to be called when the application is disposed. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract registerDisposeListener(dispose: () => void): void; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Returns a promise that resolves when all asynchronous application initializers | 
					
						
							|  |  |  |    * are done. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract waitForAsyncInitializers(): Promise<any>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Runs the given callback in the zone and returns the result of the callback. | 
					
						
							|  |  |  |    * Exceptions will be forwarded to the ExceptionHandler and rethrown. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract run(callback: Function): any; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  |   /** | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |    * Bootstrap a new component at the root level of the application. | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2015-11-17 09:41:31 -08:00
										 |  |  |    * ### Bootstrap process | 
					
						
							| 
									
										
										
										
											2015-09-15 15:51:15 -07:00
										 |  |  |    * | 
					
						
							|  |  |  |    * When bootstrapping a new root component into an application, Angular mounts the | 
					
						
							|  |  |  |    * specified application component onto DOM elements identified by the [componentType]'s | 
					
						
							|  |  |  |    * selector and kicks off automatic change detection to finish initializing the component. | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2015-10-19 15:37:32 +01:00
										 |  |  |    * ### Example | 
					
						
							| 
									
										
										
										
											2015-11-30 08:28:54 -08:00
										 |  |  |    * {@example core/ts/platform/platform.ts region='longform'} | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   abstract bootstrap<C>(componentFactory: ComponentFactory<C>): ComponentRef<C>; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Retrieve the application {@link Injector}. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 |  |  |   get injector(): Injector { return <Injector>unimplemented(); }; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Retrieve the application {@link NgZone}. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 |  |  |   get zone(): NgZone { return <NgZone>unimplemented(); }; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Dispose of this application and all of its components. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract dispose(): void; | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Invoke this method to explicitly process change detection and its side-effects. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * In development mode, `tick()` also performs a second change detection cycle to ensure that no | 
					
						
							|  |  |  |    * further changes are detected. If additional changes are picked up during this second cycle, | 
					
						
							|  |  |  |    * bindings in the app have side-effects that cannot be resolved in a single change detection | 
					
						
							|  |  |  |    * pass. | 
					
						
							|  |  |  |    * In this case, Angular throws an error, since an Angular application can only have one change | 
					
						
							|  |  |  |    * detection pass during which all change detection must complete. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract tick(): void; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Get a list of component types registered to this application. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-02-19 11:49:31 -08:00
										 |  |  |   get componentTypes(): Type[] { return <Type[]>unimplemented(); }; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | export class ApplicationRef_ extends ApplicationRef { | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   /** @internal */ | 
					
						
							|  |  |  |   static _tickScope: WtfScopeFn = wtfCreateScope('ApplicationRef#tick()'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |   private _bootstrapListeners: Function[] = []; | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |   private _disposeListeners: Function[] = []; | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   private _rootComponents: ComponentRef<any>[] = []; | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  |   private _rootComponentTypes: Type[] = []; | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   /** @internal */ | 
					
						
							|  |  |  |   private _changeDetectorRefs: ChangeDetectorRef[] = []; | 
					
						
							|  |  |  |   /** @internal */ | 
					
						
							|  |  |  |   private _runningTick: boolean = false; | 
					
						
							|  |  |  |   /** @internal */ | 
					
						
							|  |  |  |   private _enforceNoNewChanges: boolean = false; | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   private _exceptionHandler: ExceptionHandler; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private _asyncInitDonePromise: Promise<any>; | 
					
						
							|  |  |  |   private _asyncInitDone: boolean; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) { | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |     super(); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     var zone: NgZone = _injector.get(NgZone); | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |     this._enforceNoNewChanges = assertionsEnabled(); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     zone.run(() => { this._exceptionHandler = _injector.get(ExceptionHandler); }); | 
					
						
							|  |  |  |     this._asyncInitDonePromise = this.run(() => { | 
					
						
							|  |  |  |       let inits: Function[] = _injector.get(APP_INITIALIZER, null); | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |       var asyncInitResults: any[] /** TODO #9100 */ = []; | 
					
						
							|  |  |  |       var asyncInitDonePromise: any /** TODO #9100 */; | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |       if (isPresent(inits)) { | 
					
						
							|  |  |  |         for (var i = 0; i < inits.length; i++) { | 
					
						
							|  |  |  |           var initResult = inits[i](); | 
					
						
							|  |  |  |           if (isPromise(initResult)) { | 
					
						
							|  |  |  |             asyncInitResults.push(initResult); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (asyncInitResults.length > 0) { | 
					
						
							|  |  |  |         asyncInitDonePromise = | 
					
						
							|  |  |  |             PromiseWrapper.all(asyncInitResults).then((_) => this._asyncInitDone = true); | 
					
						
							|  |  |  |         this._asyncInitDone = false; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         this._asyncInitDone = true; | 
					
						
							|  |  |  |         asyncInitDonePromise = PromiseWrapper.resolve(true); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return asyncInitDonePromise; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     ObservableWrapper.subscribe(zone.onError, (error: NgZoneError) => { | 
					
						
							|  |  |  |       this._exceptionHandler.call(error.error, error.stackTrace); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     ObservableWrapper.subscribe( | 
					
						
							|  |  |  |         this._zone.onMicrotaskEmpty, (_) => { this._zone.run(() => { this.tick(); }); }); | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   registerBootstrapListener(listener: (ref: ComponentRef<any>) => void): void { | 
					
						
							| 
									
										
										
										
											2015-10-06 06:53:39 -07:00
										 |  |  |     this._bootstrapListeners.push(listener); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |   registerDisposeListener(dispose: () => void): void { this._disposeListeners.push(dispose); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   registerChangeDetector(changeDetector: ChangeDetectorRef): void { | 
					
						
							|  |  |  |     this._changeDetectorRefs.push(changeDetector); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 10:40:33 -08:00
										 |  |  |   unregisterChangeDetector(changeDetector: ChangeDetectorRef): void { | 
					
						
							|  |  |  |     ListWrapper.remove(this._changeDetectorRefs, changeDetector); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   waitForAsyncInitializers(): Promise<any> { return this._asyncInitDonePromise; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   run(callback: Function): any { | 
					
						
							|  |  |  |     var zone = this.injector.get(NgZone); | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |     var result: any /** TODO #9100 */; | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     // Note: Don't use zone.runGuarded as we want to know about
 | 
					
						
							|  |  |  |     // the thrown exception!
 | 
					
						
							|  |  |  |     // Note: the completer needs to be created outside
 | 
					
						
							|  |  |  |     // of `zone.run` as Dart swallows rejected promises
 | 
					
						
							|  |  |  |     // via the onError callback of the promise.
 | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |     var completer = PromiseWrapper.completer(); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     zone.run(() => { | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |       try { | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |         result = callback(); | 
					
						
							|  |  |  |         if (isPromise(result)) { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |           PromiseWrapper.then( | 
					
						
							|  |  |  |               result, (ref) => { completer.resolve(ref); }, | 
					
						
							|  |  |  |               (err, stackTrace) => { | 
					
						
							|  |  |  |                 completer.reject(err, stackTrace); | 
					
						
							|  |  |  |                 this._exceptionHandler.call(err, stackTrace); | 
					
						
							|  |  |  |               }); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |       } catch (e) { | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |         this._exceptionHandler.call(e, e.stack); | 
					
						
							|  |  |  |         throw e; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     return isPromise(result) ? completer.promise : result; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   bootstrap<C>(componentFactory: ComponentFactory<C>): ComponentRef<C> { | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |     if (!this._asyncInitDone) { | 
					
						
							|  |  |  |       throw new BaseException( | 
					
						
							|  |  |  |           'Cannot bootstrap as there are still asynchronous initializers running. Wait for them using waitForAsyncInitializers().'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return this.run(() => { | 
					
						
							|  |  |  |       this._rootComponentTypes.push(componentFactory.componentType); | 
					
						
							|  |  |  |       var compRef = componentFactory.create(this._injector, [], componentFactory.selector); | 
					
						
							|  |  |  |       compRef.onDestroy(() => { this._unloadComponent(compRef); }); | 
					
						
							|  |  |  |       var testability = compRef.injector.get(Testability, null); | 
					
						
							|  |  |  |       if (isPresent(testability)) { | 
					
						
							|  |  |  |         compRef.injector.get(TestabilityRegistry) | 
					
						
							|  |  |  |             .registerApplication(compRef.location.nativeElement, testability); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       this._loadComponent(compRef); | 
					
						
							| 
									
										
										
										
											2016-04-25 21:31:46 -07:00
										 |  |  |       let c: Console = this._injector.get(Console); | 
					
						
							| 
									
										
										
										
											2016-02-03 11:47:53 -08:00
										 |  |  |       if (assertionsEnabled()) { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         let prodDescription = IS_DART ? 'Production mode is disabled in Dart.' : | 
					
						
							|  |  |  |                                         'Call enableProdMode() to enable the production mode.'; | 
					
						
							| 
									
										
										
										
											2016-05-20 10:01:39 -07:00
										 |  |  |         c.log(`Angular 2 is running in the development mode. ${prodDescription}`); | 
					
						
							| 
									
										
										
										
											2016-02-03 11:47:53 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |       return compRef; | 
					
						
							| 
									
										
										
										
											2015-12-15 08:34:44 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 10:40:33 -08:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   _loadComponent(componentRef: ComponentRef<any>): void { | 
					
						
							| 
									
										
										
										
											2016-04-13 17:05:17 -07:00
										 |  |  |     this._changeDetectorRefs.push(componentRef.changeDetectorRef); | 
					
						
							| 
									
										
										
										
											2015-11-10 10:40:33 -08:00
										 |  |  |     this.tick(); | 
					
						
							| 
									
										
										
										
											2016-02-11 17:01:17 -08:00
										 |  |  |     this._rootComponents.push(componentRef); | 
					
						
							|  |  |  |     this._bootstrapListeners.forEach((listener) => listener(componentRef)); | 
					
						
							| 
									
										
										
										
											2015-11-10 10:40:33 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  |   _unloadComponent(componentRef: ComponentRef<any>): void { | 
					
						
							| 
									
										
										
										
											2016-02-11 17:01:17 -08:00
										 |  |  |     if (!ListWrapper.contains(this._rootComponents, componentRef)) { | 
					
						
							| 
									
										
										
										
											2015-11-10 10:40:33 -08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-13 17:05:17 -07:00
										 |  |  |     this.unregisterChangeDetector(componentRef.changeDetectorRef); | 
					
						
							| 
									
										
										
										
											2016-02-11 17:01:17 -08:00
										 |  |  |     ListWrapper.remove(this._rootComponents, componentRef); | 
					
						
							| 
									
										
										
										
											2015-11-10 10:40:33 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  |   get injector(): Injector { return this._injector; } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   get zone(): NgZone { return this._zone; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |   tick(): void { | 
					
						
							|  |  |  |     if (this._runningTick) { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       throw new BaseException('ApplicationRef.tick is called recursively'); | 
					
						
							| 
									
										
										
										
											2015-10-28 10:34:13 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var s = ApplicationRef_._tickScope(); | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       this._runningTick = true; | 
					
						
							|  |  |  |       this._changeDetectorRefs.forEach((detector) => detector.detectChanges()); | 
					
						
							|  |  |  |       if (this._enforceNoNewChanges) { | 
					
						
							|  |  |  |         this._changeDetectorRefs.forEach((detector) => detector.checkNoChanges()); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } finally { | 
					
						
							|  |  |  |       this._runningTick = false; | 
					
						
							|  |  |  |       wtfLeave(s); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   dispose(): void { | 
					
						
							|  |  |  |     // TODO(alxhub): Dispose of the NgZone.
 | 
					
						
							| 
									
										
										
										
											2016-04-13 17:05:17 -07:00
										 |  |  |     ListWrapper.clone(this._rootComponents).forEach((ref) => ref.destroy()); | 
					
						
							| 
									
										
										
										
											2015-10-26 10:50:25 -07:00
										 |  |  |     this._disposeListeners.forEach((dispose) => dispose()); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |     this._platform._applicationDisposed(this); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-09 16:22:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 18:13:58 -08:00
										 |  |  |   get componentTypes(): Type[] { return this._rootComponentTypes; } | 
					
						
							| 
									
										
										
										
											2015-08-20 17:18:27 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const PLATFORM_CORE_PROVIDERS = | 
					
						
							| 
									
										
										
										
											2016-04-25 22:25:21 -07:00
										 |  |  |     /*@ts2dart_const*/[ | 
					
						
							|  |  |  |       PlatformRef_, | 
					
						
							| 
									
										
										
										
											2016-04-28 23:28:13 -07:00
										 |  |  |       /*@ts2dart_const*/ ( | 
					
						
							|  |  |  |           /* @ts2dart_Provider */ {provide: PlatformRef, useExisting: PlatformRef_}) | 
					
						
							| 
									
										
										
										
											2016-04-25 22:25:21 -07:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 21:47:33 -07:00
										 |  |  | export const APPLICATION_CORE_PROVIDERS = /*@ts2dart_const*/[ | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |   /* @ts2dart_Provider */ {provide: NgZone, useFactory: createNgZone, deps: [] as any}, | 
					
						
							| 
									
										
										
										
											2016-04-14 14:52:35 -07:00
										 |  |  |   ApplicationRef_, | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |   /* @ts2dart_Provider */ {provide: ApplicationRef, useExisting: ApplicationRef_}, | 
					
						
							| 
									
										
										
										
											2016-04-25 21:47:33 -07:00
										 |  |  | ]; |