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

@ -1,7 +1,7 @@
library angular2.core;
export 'package:angular2/src/core/application_tokens.dart' show APP_COMPONENT;
export 'package:angular2/src/core/application_common.dart' show ApplicationRef;
export 'package:angular2/src/core/application_ref.dart' show ApplicationRef;
// Compiler Related Dependencies.
export 'package:angular2/src/services/app_root_url.dart' show AppRootUrl;

View File

@ -4,8 +4,9 @@
* Define angular core API here.
*/
export {APP_COMPONENT} from 'angular2/src/core/application_tokens';
export {ApplicationRef, commonBootstrap as bootstrap} from 'angular2/src/core/application_common';
export {commonBootstrap as bootstrap} from 'angular2/src/core/application_common';
export {Type} from 'angular2/src/facade/lang';
export {ApplicationRef} from 'angular2/src/core/application_ref';
// Compiler Related Dependencies.

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

View File

@ -4,7 +4,7 @@ import "package:angular2/src/web-workers/shared/isolate_message_bus.dart";
import "package:angular2/src/web-workers/worker/application_common.dart"
show bootstrapWebWorkerCommon;
import "package:angular2/src/facade/async.dart" show Future;
import "package:angular2/src/core/application.dart" show ApplicationRef;
import "package:angular2/src/core/application_ref.dart" show ApplicationRef;
import "package:angular2/src/facade/lang.dart" show Type, BaseException;
import "dart:isolate";
import "dart:async";

View File

@ -8,7 +8,7 @@ import {Binding} from "angular2/di";
import {Map} from 'angular2/src/facade/collection';
import {Promise} from 'angular2/src/facade/async';
import {bootstrapWebWorkerCommon} from "angular2/src/web-workers/worker/application_common";
import {ApplicationRef} from "angular2/src/core/application";
import {ApplicationRef} from "angular2/src/core/application_ref";
import {Injectable} from "angular2/di";
// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492)

View File

@ -55,8 +55,7 @@ import {internalView} from 'angular2/src/core/compiler/view_ref';
import {MessageBrokerFactory} from 'angular2/src/web-workers/worker/broker';
import {MessageBus, MessageBusInterface} from 'angular2/src/web-workers/shared/message_bus';
import {APP_COMPONENT_REF_PROMISE, APP_COMPONENT} from 'angular2/src/core/application_tokens';
import {ApplicationRef} from 'angular2/src/core/application';
import {createNgZone} from 'angular2/src/core/application_common';
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {Serializer} from "angular2/src/web-workers/shared/serializer";
import {ON_WEB_WORKER} from "angular2/src/web-workers/shared/api";
import {RenderProtoViewRefStore} from 'angular2/src/web-workers/shared/render_proto_view_ref_store';
@ -147,7 +146,7 @@ export function bootstrapWebWorkerCommon(
componentInjectableBindings: List<Type | Binding | List<any>> = null): Promise<ApplicationRef> {
var bootstrapProcess: PromiseCompleter<any> = PromiseWrapper.completer();
var zone = createNgZone();
var zone = new NgZone({enableLongStackTrace: assertionsEnabled()});
zone.run(() => {
// TODO(rado): prepopulate template cache, so applications with only
// index.html and main.js are possible.