refactor(ApplicationRef): Move ApplicationRef to its own file

Closes #3763
This commit is contained in:
Jason Teplitz
2015-08-20 17:18:27 -07:00
parent 65344fcac9
commit 764726d78e
10 changed files with 60 additions and 54 deletions

View File

@ -6,8 +6,9 @@ import 'package:angular2/src/reflection/reflection.dart' show reflector;
import 'package:angular2/src/reflection/reflection_capabilities.dart'
show ReflectionCapabilities;
import 'application_common.dart';
import 'application_ref.dart';
export 'application_common.dart' show ApplicationRef;
export 'application_ref.dart' show ApplicationRef;
/// Starts an application from a root component. This implementation uses
/// mirrors. Angular 2 transformer automatically replaces this method with a

View File

@ -1 +1,2 @@
export {ApplicationRef, commonBootstrap as bootstrap} from './application_common';
export {commonBootstrap as bootstrap} from './application_common';
export {ApplicationRef} from './application_ref';

View File

@ -76,6 +76,7 @@ import {internalView} from 'angular2/src/core/compiler/view_ref';
import {APP_COMPONENT_REF_PROMISE, APP_COMPONENT} from './application_tokens';
import {wtfInit} from '../profile/wtf_init';
import {EXCEPTION_BINDING} from './platform_bindings';
import {ApplicationRef} from './application_ref';
var _rootInjector: Injector;
@ -337,51 +338,6 @@ export function commonBootstrap(
return bootstrapProcess.promise;
}
/**
* Represents a Angular's representation of an Application.
*
* `ApplicationRef` represents a running application instance. Use it to retrieve the host
* component, injector,
* or dispose of an application.
*/
export class ApplicationRef {
_hostComponent: ComponentRef;
_injector: Injector;
_hostComponentType: Type;
/**
* @private
*/
constructor(hostComponent: ComponentRef, hostComponentType: Type, injector: Injector) {
this._hostComponent = hostComponent;
this._injector = injector;
this._hostComponentType = hostComponentType;
}
/**
* Returns the current {@link ComponentMetadata} type.
*/
get hostComponentType(): Type { return this._hostComponentType; }
/**
* Returns the current {@link ComponentMetadata} instance.
*/
get hostComponent(): any { return this._hostComponent.instance; }
/**
* Dispose (un-load) the application.
*/
dispose(): void {
// TODO: We also need to clean up the Zone, ... here!
this._hostComponent.dispose();
}
/**
* Returns the root application {@link Injector}.
*/
get injector(): Injector { return this._injector; }
}
function _createAppInjector(appComponentType: Type, bindings: List<Type | Binding | List<any>>,
zone: NgZone): Injector {
if (isBlank(_rootInjector)) _rootInjector = Injector.resolveAndCreate(_rootBindings);

View File

@ -0,0 +1,47 @@
import {ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
import {Injector} from 'angular2/di';
import {Type} from 'angular2/src/facade/lang';
/**
* Represents a Angular's representation of an Application.
*
* `ApplicationRef` represents a running application instance. Use it to retrieve the host
* component, injector,
* or dispose of an application.
*/
export class ApplicationRef {
_hostComponent: ComponentRef;
_injector: Injector;
_hostComponentType: Type;
/**
* @private
*/
constructor(hostComponent: ComponentRef, hostComponentType: Type, injector: Injector) {
this._hostComponent = hostComponent;
this._injector = injector;
this._hostComponentType = hostComponentType;
}
/**
* Returns the current {@link ComponentMetadata} type.
*/
get hostComponentType(): Type { return this._hostComponentType; }
/**
* Returns the current {@link ComponentMetadata} instance.
*/
get hostComponent(): any { return this._hostComponent.instance; }
/**
* Dispose (un-load) the application.
*/
dispose(): void {
// TODO: We also need to clean up the Zone, ... here!
this._hostComponent.dispose();
}
/**
* Returns the root application {@link Injector}.
*/
get injector(): Injector { return this._injector; }
}

View File

@ -2,6 +2,7 @@ library angular2.application_static;
import 'dart:async';
import 'application_common.dart';
import 'application_ref.dart';
/// Starts an application from a root component.
///