1- import { NgZone } from 'angular2/src/core/zone/ng_zone' ;
1+ import { NgZone , NgZone_ } from 'angular2/src/core/zone/ng_zone' ;
22import { Type , isBlank , isPresent , assertionsEnabled } from 'angular2/src/core/facade/lang' ;
33import { bind , Binding , Injector , OpaqueToken } from 'angular2/src/core/di' ;
44import {
@@ -17,11 +17,12 @@ import {
1717import {
1818 BaseException ,
1919 WrappedException ,
20- ExceptionHandler
20+ ExceptionHandler ,
21+ unimplemented
2122} from 'angular2/src/core/facade/exceptions' ;
2223import { DOM } from 'angular2/src/core/dom/dom_adapter' ;
2324import { internalView } from 'angular2/src/core/linker/view_ref' ;
24- import { LifeCycle } from 'angular2/src/core/life_cycle/life_cycle' ;
25+ import { LifeCycle , LifeCycle_ } from 'angular2/src/core/life_cycle/life_cycle' ;
2526import {
2627 IterableDiffers ,
2728 defaultIterableDiffers ,
@@ -98,7 +99,7 @@ export function applicationCommonBindings(): Array<Type | Binding | any[]> {
9899 DirectiveResolver ,
99100 PipeResolver ,
100101 DynamicComponentLoader ,
101- bind ( LifeCycle ) . toFactory ( ( exceptionHandler ) => new LifeCycle ( null , assertionsEnabled ( ) ) ,
102+ bind ( LifeCycle ) . toFactory ( ( exceptionHandler ) => new LifeCycle_ ( null , assertionsEnabled ( ) ) ,
102103 [ ExceptionHandler ] ) ,
103104 ] ;
104105}
@@ -107,7 +108,7 @@ export function applicationCommonBindings(): Array<Type | Binding | any[]> {
107108 * Create an Angular zone.
108109 */
109110export function createNgZone ( ) : NgZone {
110- return new NgZone ( { enableLongStackTrace : assertionsEnabled ( ) } ) ;
111+ return new NgZone_ ( { enableLongStackTrace : assertionsEnabled ( ) } ) ;
111112}
112113
113114var _platform : PlatformRef ;
@@ -131,7 +132,7 @@ export function platformCommon(bindings?: Array<Type | Binding | any[]>, initial
131132 if ( isBlank ( bindings ) ) {
132133 bindings = platformBindings ( ) ;
133134 }
134- _platform = new PlatformRef ( Injector . resolveAndCreate ( bindings ) , ( ) => { _platform = null ; } ) ;
135+ _platform = new PlatformRef_ ( Injector . resolveAndCreate ( bindings ) , ( ) => { _platform = null ; } ) ;
135136 return _platform ;
136137}
137138
@@ -143,22 +144,12 @@ export function platformCommon(bindings?: Array<Type | Binding | any[]>, initial
143144 * A page's platform is initialized implicitly when {@link bootstrap}() is called, or
144145 * explicitly by calling {@link platform}().
145146 */
146- export class PlatformRef {
147- /**
148- * @internal
149- */
150- _applications : ApplicationRef [ ] = [ ] ;
151-
152- /**
153- * @internal
154- */
155- constructor ( private _injector : Injector , private _dispose : ( ) => void ) { }
156-
147+ export abstract class PlatformRef {
157148 /**
158149 * Retrieve the platform {@link Injector}, which is the parent injector for
159150 * every Angular application on the page and provides singleton bindings.
160151 */
161- get injector ( ) : Injector { return this . _injector ; }
152+ get injector ( ) : Injector { return unimplemented ( ) ; } ;
162153
163154 /**
164155 * Instantiate a new Angular application on the page.
@@ -188,10 +179,7 @@ export class PlatformRef {
188179 *
189180 * See the {@link bootstrap} documentation for more details.
190181 */
191- application ( bindings : Array < Type | Binding | any [ ] > ) : ApplicationRef {
192- var app = this . _initApp ( createNgZone ( ) , bindings ) ;
193- return app ;
194- }
182+ abstract application ( bindings : Array < Type | Binding | any [ ] > ) : ApplicationRef ;
195183
196184 /**
197185 * Instantiate a new Angular application on the page, using bindings which
@@ -205,6 +193,27 @@ export class PlatformRef {
205193 * new application. Once this promise resolves, the application will be
206194 * constructed in the same manner as a normal `application()`.
207195 */
196+ abstract asyncApplication ( bindingFn : ( zone : NgZone ) => Promise < Array < Type | Binding | any [ ] > > ) :
197+ Promise < ApplicationRef > ;
198+
199+ /**
200+ * Destroy the Angular platform and all Angular applications on the page.
201+ */
202+ abstract dispose ( ) : void ;
203+ }
204+
205+ export class PlatformRef_ extends PlatformRef {
206+ _applications : ApplicationRef [ ] = [ ] ;
207+
208+ constructor ( private _injector : Injector , private _dispose : ( ) => void ) { super ( ) ; }
209+
210+ get injector ( ) : Injector { return this . _injector ; }
211+
212+ application ( bindings : Array < Type | Binding | any [ ] > ) : ApplicationRef {
213+ var app = this . _initApp ( createNgZone ( ) , bindings ) ;
214+ return app ;
215+ }
216+
208217 asyncApplication ( bindingFn : ( zone : NgZone ) =>
209218 Promise < Array < Type | Binding | any [ ] > > ) : Promise < ApplicationRef > {
210219 var zone = createNgZone ( ) ;
@@ -227,7 +236,7 @@ export class PlatformRef {
227236 try {
228237 injector = this . injector . resolveAndCreateChild ( bindings ) ;
229238 exceptionHandler = injector . get ( ExceptionHandler ) ;
230- zone . overrideOnErrorHandler ( ( e , s ) => exceptionHandler . call ( e , s ) ) ;
239+ ( < NgZone_ > zone ) . overrideOnErrorHandler ( ( e , s ) => exceptionHandler . call ( e , s ) ) ;
231240 } catch ( e ) {
232241 if ( isPresent ( exceptionHandler ) ) {
233242 exceptionHandler . call ( e , e . stack ) ;
@@ -236,23 +245,16 @@ export class PlatformRef {
236245 }
237246 }
238247 } ) ;
239- var app = new ApplicationRef ( this , zone , injector ) ;
248+ var app = new ApplicationRef_ ( this , zone , injector ) ;
240249 this . _applications . push ( app ) ;
241250 return app ;
242251 }
243252
244-
245- /**
246- * Destroy the Angular platform and all Angular applications on the page.
247- */
248253 dispose ( ) : void {
249254 this . _applications . forEach ( ( app ) => app . dispose ( ) ) ;
250255 this . _dispose ( ) ;
251256 }
252257
253- /**
254- * @internal
255- */
256258 _applicationDisposed ( app : ApplicationRef ) : void { ListWrapper . remove ( this . _applications , app ) ; }
257259}
258260
@@ -261,22 +263,12 @@ export class PlatformRef {
261263 *
262264 * For more about Angular applications, see the documentation for {@link bootstrap}.
263265 */
264- export class ApplicationRef {
265- private _bootstrapListeners : Function [ ] = [ ] ;
266- private _rootComponents : ComponentRef [ ] = [ ] ;
267-
268- /**
269- * @internal
270- */
271- constructor ( private _platform : PlatformRef , private _zone : NgZone , private _injector : Injector ) { }
272-
266+ export abstract class ApplicationRef {
273267 /**
274268 * Register a listener to be called each time `bootstrap()` is called to bootstrap
275269 * a new root component.
276270 */
277- registerBootstrapListener ( listener : ( ref : ComponentRef ) => void ) : void {
278- this . _bootstrapListeners . push ( listener ) ;
279- }
271+ abstract registerBootstrapListener ( listener : ( ref : ComponentRef ) => void ) : void ;
280272
281273 /**
282274 * Bootstrap a new component at the root level of the application.
@@ -300,6 +292,37 @@ export class ApplicationRef {
300292 * app.bootstrap(SecondRootComponent, [bind(OverrideBinding).toClass(OverriddenBinding)]);
301293 * ```
302294 */
295+ abstract bootstrap ( componentType : Type , bindings ?: Array < Type | Binding | any [ ] > ) :
296+ Promise < ComponentRef > ;
297+
298+ /**
299+ * Retrieve the application {@link Injector}.
300+ */
301+ get injector ( ) : Injector { return unimplemented ( ) ; } ;
302+
303+ /**
304+ * Retrieve the application {@link NgZone}.
305+ */
306+ get zone ( ) : NgZone { return unimplemented ( ) ; } ;
307+
308+ /**
309+ * Dispose of this application and all of its components.
310+ */
311+ abstract dispose ( ) : void ;
312+ }
313+
314+ export class ApplicationRef_ extends ApplicationRef {
315+ private _bootstrapListeners : Function [ ] = [ ] ;
316+ private _rootComponents : ComponentRef [ ] = [ ] ;
317+
318+ constructor ( private _platform : PlatformRef_ , private _zone : NgZone , private _injector : Injector ) {
319+ super ( ) ;
320+ }
321+
322+ registerBootstrapListener ( listener : ( ref : ComponentRef ) => void ) : void {
323+ this . _bootstrapListeners . push ( listener ) ;
324+ }
325+
303326 bootstrap ( componentType : Type , bindings ?: Array < Type | Binding | any [ ] > ) : Promise < ComponentRef > {
304327 var completer = PromiseWrapper . completer ( ) ;
305328 this . _zone . run ( ( ) => {
@@ -334,19 +357,10 @@ export class ApplicationRef {
334357 return completer . promise ;
335358 }
336359
337- /**
338- * Retrieve the application {@link Injector}.
339- */
340360 get injector ( ) : Injector { return this . _injector ; }
341361
342- /**
343- * Retrieve the application {@link NgZone}.
344- */
345362 get zone ( ) : NgZone { return this . _zone ; }
346363
347- /**
348- * Dispose of this application and all of its components.
349- */
350364 dispose ( ) : void {
351365 // TODO(alxhub): Dispose of the NgZone.
352366 this . _rootComponents . forEach ( ( ref ) => ref . dispose ( ) ) ;
0 commit comments