refactor(core): introduce ComponentFactory.

Each compile template now exposes a `<CompName>NgFactory` variable
with an instance of a `ComponentFactory`.
Calling `ComponentFactory.create` returns a `ComponentRef` that can
be used directly.

BREAKING CHANGE:
- `Compiler` is renamed to `ComponentResolver`,
  `Compiler.compileInHost` has been renamed to `ComponentResolver.resolveComponent`.
- `ComponentRef.dispose` is renamed to `ComponentRef.destroy`
- `ViewContainerRef.createHostView` is renamed to `ViewContainerRef.createComponent`
- `ComponentFixture_` has been removed, the class `ComponentFixture`
  can now be created directly as it is no more using private APIs.
This commit is contained in:
Tobias Bosch 2016-04-13 17:05:17 -07:00
parent 41404057cf
commit 0c600cf6e3
66 changed files with 611 additions and 849 deletions

View File

@ -4,6 +4,7 @@ export {TEMPLATE_TRANSFORMS} from 'angular2/src/compiler/template_parser';
export {CompilerConfig, RenderTypes} from './config';
export * from './compile_metadata';
export * from './offline_compiler';
export {RuntimeCompiler} from './runtime_compiler';
export * from 'angular2/src/compiler/url_resolver';
export * from 'angular2/src/compiler/xhr';
@ -20,7 +21,7 @@ import {RuntimeMetadataResolver} from 'angular2/src/compiler/runtime_metadata';
import {StyleCompiler} from 'angular2/src/compiler/style_compiler';
import {ViewCompiler} from 'angular2/src/compiler/view_compiler/view_compiler';
import {CompilerConfig} from './config';
import {Compiler} from 'angular2/src/core/linker/compiler';
import {ComponentResolver} from 'angular2/src/core/linker/component_resolver';
import {RuntimeCompiler} from 'angular2/src/compiler/runtime_compiler';
import {ElementSchemaRegistry} from 'angular2/src/compiler/schema/element_schema_registry';
import {DomElementSchemaRegistry} from 'angular2/src/compiler/schema/dom_element_schema_registry';
@ -51,7 +52,7 @@ export const COMPILER_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR([
ViewCompiler,
new Provider(CompilerConfig, {useFactory: _createCompilerConfig, deps: []}),
RuntimeCompiler,
new Provider(Compiler, {useExisting: RuntimeCompiler}),
new Provider(ComponentResolver, {useExisting: RuntimeCompiler}),
DomElementSchemaRegistry,
new Provider(ElementSchemaRegistry, {useExisting: DomElementSchemaRegistry}),
UrlResolver,

View File

@ -13,16 +13,16 @@ import {TemplateParser} from './template_parser';
import {DirectiveNormalizer} from './directive_normalizer';
import {OutputEmitter} from './output/abstract_emitter';
import * as o from './output/output_ast';
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
import {
MODULE_SUFFIX,
} from './util';
var _HOST_VIEW_FACTORY_IDENTIFIER = new CompileIdentifierMetadata({
name: 'HostViewFactory',
runtime: HostViewFactory,
moduleUrl: `asset:angular2/lib/src/core/linker/view${MODULE_SUFFIX}`
var _COMPONENT_FACTORY_IDENTIFIER = new CompileIdentifierMetadata({
name: 'ComponentFactory',
runtime: ComponentFactory,
moduleUrl: `asset:angular2/lib/src/core/linker/component_factory${MODULE_SUFFIX}`
});
export class SourceModule {
@ -59,17 +59,20 @@ export class OfflineCompiler {
exportedVars.push(compViewFactoryVar);
var hostMeta = createHostComponentMeta(compMeta.type, compMeta.selector);
var compHostViewFactoryVar = this._compileComponent(hostMeta, [compMeta], [], statements);
var hostViewFactoryVar = `hostViewFactory_${compMeta.type.name}`;
statements.push(
o.variable(hostViewFactoryVar)
.set(o.importExpr(_HOST_VIEW_FACTORY_IDENTIFIER)
.instantiate(
[o.literal(compMeta.selector), o.variable(compHostViewFactoryVar)],
o.importType(_HOST_VIEW_FACTORY_IDENTIFIER, null,
[o.TypeModifier.Const])))
.toDeclStmt(null, [o.StmtModifier.Final]));
exportedVars.push(hostViewFactoryVar);
var hostViewFactoryVar = this._compileComponent(hostMeta, [compMeta], [], statements);
var compFactoryVar = `${compMeta.type.name}NgFactory`;
statements.push(o.variable(compFactoryVar)
.set(o.importExpr(_COMPONENT_FACTORY_IDENTIFIER)
.instantiate(
[
o.literal(compMeta.selector),
o.variable(hostViewFactoryVar),
o.importExpr(compMeta.type)
],
o.importType(_COMPONENT_FACTORY_IDENTIFIER, null,
[o.TypeModifier.Const])))
.toDeclStmt(null, [o.StmtModifier.Final]));
exportedVars.push(compFactoryVar);
});
return this._codegenSourceModule(moduleUrl, statements, exportedVars);
}

View File

@ -1,5 +1,6 @@
import {isPresent} from 'angular2/src/facade/lang';
import {AppView} from 'angular2/src/core/linker/view';
import {AppElement} from 'angular2/src/core/linker/element';
import {BaseException} from 'angular2/src/facade/exceptions';
import {InstanceFactory, DynamicInstance} from './output_interpreter';
@ -19,12 +20,12 @@ class _InterpretiveAppView extends AppView<any> implements DynamicInstance {
super(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
args[10]);
}
createInternal(rootSelector: string): void {
createInternal(rootSelector: string | any): AppElement {
var m = this.methods.get('createInternal');
if (isPresent(m)) {
m(rootSelector);
return m(rootSelector);
} else {
super.createInternal(rootSelector);
return super.createInternal(rootSelector);
}
}
injectorGetInternal(token: any, nodeIndex: number, notFoundResult: any): any {

View File

@ -46,9 +46,11 @@ import {ViewCompiler} from './view_compiler/view_compiler';
import {TemplateParser} from './template_parser';
import {DirectiveNormalizer} from './directive_normalizer';
import {RuntimeMetadataResolver} from './runtime_metadata';
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {HostViewFactoryRef, HostViewFactoryRef_} from 'angular2/src/core/linker/view_ref';
import {Compiler, Compiler_} from 'angular2/src/core/linker/compiler';
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
import {
ComponentResolver,
ReflectorComponentResolver
} from 'angular2/src/core/linker/component_resolver';
import {CompilerConfig} from './config';
import * as ir from './output/output_ast';
@ -64,7 +66,7 @@ import {XHR} from 'angular2/src/compiler/xhr';
* ready for linking into an application.
*/
@Injectable()
export class RuntimeCompiler extends Compiler_ {
export class RuntimeCompiler implements ComponentResolver {
private _styleCache: Map<string, Promise<string>> = new Map<string, Promise<string>>();
private _hostCacheKeys = new Map<Type, any>();
private _compiledTemplateCache = new Map<any, CompiledTemplate>();
@ -74,11 +76,9 @@ export class RuntimeCompiler extends Compiler_ {
private _templateNormalizer: DirectiveNormalizer,
private _templateParser: TemplateParser, private _styleCompiler: StyleCompiler,
private _viewCompiler: ViewCompiler, private _xhr: XHR,
private _genConfig: CompilerConfig) {
super();
}
private _genConfig: CompilerConfig) {}
compileInHost(componentType: Type): Promise<HostViewFactoryRef_> {
resolveComponent(componentType: Type): Promise<ComponentFactory> {
var compMeta: CompileDirectiveMetadata =
this._runtimeMetadataResolver.getDirectiveMetadata(componentType);
var hostCacheKey = this._hostCacheKeys.get(componentType);
@ -92,8 +92,8 @@ export class RuntimeCompiler extends Compiler_ {
this._loadAndCompileComponent(hostCacheKey, hostMeta, [compMeta], [], []);
}
return this._compiledTemplateDone.get(hostCacheKey)
.then((compiledTemplate: CompiledTemplate) => new HostViewFactoryRef_(
new HostViewFactory(compMeta.selector, compiledTemplate.viewFactory)));
.then((compiledTemplate: CompiledTemplate) => new ComponentFactory(
compMeta.selector, compiledTemplate.viewFactory, componentType));
}
clearCache() {

View File

@ -1,77 +0,0 @@
var nodeDebugInfos_MyComp1 = [
new jit_StaticNodeDebugInfo0([],null,{}),
new jit_StaticNodeDebugInfo0([],null,{})
]
;
function _View_MyComp1(viewManager,renderer,parentInjector,declarationEl,projectableNodes) {
var self = this;
jit_AppView1.call(this, './MyComp',_View_MyComp1,jit_ViewType_EMBEDDED2,{'some-tmpl': null},renderer,viewManager,parentInjector,projectableNodes,declarationEl,jit_ChangeDetectionStrategy_Default3,nodeDebugInfos_MyComp1);
}
_View_MyComp1.prototype = Object.create(jit_AppView1.prototype);
_View_MyComp1.prototype.createInternal = function(rootSelector) {
var self = this;
self._el_0 = self.renderer.createElement(null,'copy-me',self.debug(0,0,49));
self._text_1 = self.renderer.createText(self._el_0,'',self.debug(1,0,58));
self._expr_0 = jit_uninitialized4;
self.init([].concat([self._el_0]),[
self._el_0,
self._text_1
]
,{},[],[]);
};
_View_MyComp1.prototype.detectChangesInternal = function(throwOnChange) {
var self = this;
var currVal = null;
self.debug(1,0,58);
currVal = jit_interpolate5(1,'',self.locals['some-tmpl'],'');
if (jit_checkBinding6(throwOnChange,self._expr_0,currVal)) {
self.renderer.setText(self._text_1,currVal);
self._expr_0 = currVal;
}
self.detectContentChildrenChanges(throwOnChange); }
self.detectViewChildrenChanges(throwOnChange); }
};
function viewFactory_MyComp1(viewManager,parentInjector,declarationEl,projectableNodes,rootSelector) {
projectableNodes = jit_ensureSlotCount7(projectableNodes,0);
var renderer = declarationEl.parentView.renderer;
var view = new _View_MyComp1(viewManager,renderer,parentInjector,declarationEl,projectableNodes);
view.create(rootSelector);
return view;
}
var nodeDebugInfos_MyComp0 = [new jit_StaticNodeDebugInfo0([
jit_TemplateRef8,
jit_SomeViewport9
]
,null,{})];
var renderType_MyComp = null;
function _View_MyComp0(viewManager,renderer,parentInjector,declarationEl,projectableNodes) {
var self = this;
jit_AppView1.call(this, './MyComp',_View_MyComp0,jit_ViewType_COMPONENT10,{},renderer,viewManager,parentInjector,projectableNodes,declarationEl,jit_ChangeDetectionStrategy_Default3,nodeDebugInfos_MyComp0);
}
_View_MyComp0.prototype = Object.create(jit_AppView1.prototype);
_View_MyComp0.prototype.createInternal = function(rootSelector) {
var self = this;
var parentRenderNode = self.renderer.createViewRoot(self.declarationAppElement.nativeElement);
self._anchor_0 = self.renderer.createTemplateAnchor(parentRenderNode,self.debug(0,0,0));
self.debug(null,null,null);
self._appEl_0 = new jit_AppElement11(0,null,self,self._anchor_0);
self._TemplateRef_0_0 = new jit_TemplateRef_12(self._appEl_0,viewFactory_MyComp1);
self._SomeViewport_0_1 = new jit_SomeViewport9(self._appEl_0.vcRef,self._TemplateRef_0_0);
self.init([],[self._anchor_0],{},[],[]);
};
_View_MyComp0.prototype.injectorGetInternal = function(token,requestNodeIndex,notFoundResult) {
var self = this;
if (((token === jit_TemplateRef8) && (0 === requestNodeIndex))) { return self._TemplateRef_0_0; }
if (((token === jit_SomeViewport9) && (0 === requestNodeIndex))) { return self._SomeViewport_0_1; }
return notFoundResult;
};
function viewFactory_MyComp0(viewManager,parentInjector,declarationEl,projectableNodes,rootSelector) {
if ((renderType_MyComp === null)) { (renderType_MyComp = viewManager.createRenderComponentType(jit_ViewType_EMBEDDED2,jit_undefined13)); }
projectableNodes = jit_ensureSlotCount7(projectableNodes,0);
var renderer = viewManager.renderComponent(renderType_MyComp);
var view = new _View_MyComp0(viewManager,renderer,parentInjector,declarationEl,projectableNodes);
view.create(rootSelector);
return view;
}
return viewFactory_MyComp0
//# sourceURL=MyComp.template.js

View File

@ -43,7 +43,6 @@ import {getViewFactoryName, createFlatArray, createDiTokenExpression} from './ut
import {ViewType} from 'angular2/src/core/linker/view_type';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {HOST_VIEW_ELEMENT_NAME} from 'angular2/src/core/linker/view';
import {
CompileIdentifierMetadata,
@ -185,17 +184,13 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
var nodeIndex = this.view.nodes.length;
var createRenderNodeExpr;
var debugContextExpr = this.view.createMethod.resetDebugInfoExpr(nodeIndex, ast);
var createElementExpr = ViewProperties.renderer.callMethod(
'createElement',
[this._getParentRenderNode(parent), o.literal(ast.name), debugContextExpr]);
if (nodeIndex === 0 && this.view.viewType === ViewType.HOST) {
createRenderNodeExpr =
rootSelectorVar.identical(o.NULL_EXPR)
.conditional(createElementExpr,
ViewProperties.renderer.callMethod('selectRootElement',
[rootSelectorVar, debugContextExpr]));
createRenderNodeExpr = o.THIS_EXPR.callMethod(
'selectOrCreateHostElement', [o.literal(ast.name), rootSelectorVar, debugContextExpr]);
} else {
createRenderNodeExpr = createElementExpr;
createRenderNodeExpr = ViewProperties.renderer.callMethod(
'createElement',
[this._getParentRenderNode(parent), o.literal(ast.name), debugContextExpr]);
}
var fieldName = `_el_${nodeIndex}`;
this.view.fields.push(
@ -342,9 +337,6 @@ function _readHtmlAndDirectiveVariables(elementExportAsVars: VariableAst[],
elementExportAsVars.forEach((varAst) => {
variables[varAst.name] = isPresent(component) ? identifierToken(component.type) : null;
});
if (viewType === ViewType.HOST) {
variables[HOST_VIEW_ELEMENT_NAME] = null;
}
return variables;
}
@ -444,7 +436,7 @@ function createViewClass(view: CompileView, renderCompTypeVar: o.ReadVarExpr,
var viewMethods = [
new o.ClassMethod('createInternal', [new o.FnParam(rootSelectorVar.name, o.STRING_TYPE)],
generateCreateMethod(view)),
generateCreateMethod(view), o.importType(Identifiers.AppElement)),
new o.ClassMethod(
'injectorGetInternal',
[
@ -519,6 +511,12 @@ function generateCreateMethod(view: CompileView): o.Statement[] {
.toDeclStmt(o.importType(view.genConfig.renderTypes.renderNode), [o.StmtModifier.Final])
];
}
var resultExpr: o.Expression;
if (view.viewType === ViewType.HOST) {
resultExpr = (<CompileElement>view.nodes[0]).getOrCreateAppElement();
} else {
resultExpr = o.NULL_EXPR;
}
return parentRenderNodeStmts.concat(view.createMethod.finish())
.concat([
o.THIS_EXPR.callMethod('init',
@ -529,7 +527,8 @@ function generateCreateMethod(view: CompileView): o.Statement[] {
o.literalArr(view.disposables),
o.literalArr(view.subscriptions)
])
.toStmt()
.toStmt(),
new o.ReturnStatement(resultExpr)
]);
}

View File

@ -13,8 +13,8 @@ import {
} from './change_detection/change_detection';
import {AppViewManager} from './linker/view_manager';
import {AppViewManager_} from "./linker/view_manager";
import {Compiler} from './linker/compiler';
import {Compiler_} from "./linker/compiler";
import {ComponentResolver} from './linker/component_resolver';
import {ReflectorComponentResolver} from "./linker/component_resolver";
import {DynamicComponentLoader} from './linker/dynamic_component_loader';
import {DynamicComponentLoader_} from "./linker/dynamic_component_loader";
@ -25,7 +25,7 @@ var __unused: Type; // avoid unused import when Type union types are erased
* application, regardless of the platform it runs onto.
*/
export const APPLICATION_COMMON_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR([
new Provider(Compiler, {useClass: Compiler_}),
new Provider(ComponentResolver, {useClass: ReflectorComponentResolver}),
APP_ID_RANDOM_PROVIDER,
new Provider(AppViewManager, {useClass: AppViewManager_}),
new Provider(IterableDiffers, {useValue: defaultIterableDiffers}),

View File

@ -18,10 +18,8 @@ import {
import {PromiseWrapper, PromiseCompleter, ObservableWrapper} from 'angular2/src/facade/async';
import {ListWrapper} from 'angular2/src/facade/collection';
import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability';
import {
ComponentRef,
DynamicComponentLoader
} from 'angular2/src/core/linker/dynamic_component_loader';
import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component_loader';
import {ComponentRef} from 'angular2/src/core/linker/component_factory';
import {
BaseException,
WrappedException,
@ -32,7 +30,6 @@ import {Console} from 'angular2/src/core/console';
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref';
import {lockMode} from 'angular2/src/facade/lang';
import {ElementRef_} from 'angular2/src/core/linker/element_ref';
/**
* Construct providers specific to an individual root component.
@ -457,8 +454,7 @@ export class ApplicationRef_ extends ApplicationRef {
/** @internal */
_loadComponent(componentRef: ComponentRef): void {
var appChangeDetector = (<ElementRef_>componentRef.location).internalElement.parentView;
this._changeDetectorRefs.push(appChangeDetector.ref);
this._changeDetectorRefs.push(componentRef.changeDetectorRef);
this.tick();
this._rootComponents.push(componentRef);
this._bootstrapListeners.forEach((listener) => listener(componentRef));
@ -469,8 +465,7 @@ export class ApplicationRef_ extends ApplicationRef {
if (!ListWrapper.contains(this._rootComponents, componentRef)) {
return;
}
this.unregisterChangeDetector(
(<ElementRef_>componentRef.location).internalElement.parentView.ref);
this.unregisterChangeDetector(componentRef.changeDetectorRef);
ListWrapper.remove(this._rootComponents, componentRef);
}
@ -498,7 +493,7 @@ export class ApplicationRef_ extends ApplicationRef {
dispose(): void {
// TODO(alxhub): Dispose of the NgZone.
ListWrapper.clone(this._rootComponents).forEach((ref) => ref.dispose());
ListWrapper.clone(this._rootComponents).forEach((ref) => ref.destroy());
this._disposeListeners.forEach((dispose) => dispose());
this._platform._applicationDisposed(this);
}

View File

@ -25,8 +25,8 @@ export class DebugDomRootRenderer implements RootRenderer {
export class DebugDomRenderer implements Renderer {
constructor(private _delegate: Renderer) {}
selectRootElement(selector: string, debugInfo: RenderDebugInfo): any {
var nativeEl = this._delegate.selectRootElement(selector, debugInfo);
selectRootElement(selectorOrNode: string | any, debugInfo: RenderDebugInfo): any {
var nativeEl = this._delegate.selectRootElement(selectorOrNode, debugInfo);
var debugEl = new DebugElement(nativeEl, null, debugInfo);
indexDebugNode(debugEl);
return nativeEl;

View File

@ -11,7 +11,7 @@ import {makeDecorator, makeParamDecorator} from '../util/decorators';
/**
* Factory for creating {@link InjectMetadata}.
*/
export interface InjectFactory {
export interface InjectMetadataFactory {
(token: any): any;
new (token: any): InjectMetadata;
}
@ -19,7 +19,7 @@ export interface InjectFactory {
/**
* Factory for creating {@link OptionalMetadata}.
*/
export interface OptionalFactory {
export interface OptionalMetadataFactory {
(): any;
new (): OptionalMetadata;
}
@ -27,7 +27,7 @@ export interface OptionalFactory {
/**
* Factory for creating {@link InjectableMetadata}.
*/
export interface InjectableFactory {
export interface InjectableMetadataFactory {
(): any;
new (): InjectableMetadata;
}
@ -35,7 +35,7 @@ export interface InjectableFactory {
/**
* Factory for creating {@link SelfMetadata}.
*/
export interface SelfFactory {
export interface SelfMetadataFactory {
(): any;
new (): SelfMetadata;
}
@ -43,7 +43,7 @@ export interface SelfFactory {
/**
* Factory for creating {@link HostMetadata}.
*/
export interface HostFactory {
export interface HostMetadataFactory {
(): any;
new (): HostMetadata;
}
@ -51,7 +51,7 @@ export interface HostFactory {
/**
* Factory for creating {@link SkipSelfMetadata}.
*/
export interface SkipSelfFactory {
export interface SkipSelfMetadataFactory {
(): any;
new (): SkipSelfMetadata;
}
@ -59,29 +59,30 @@ export interface SkipSelfFactory {
/**
* Factory for creating {@link InjectMetadata}.
*/
export var Inject: InjectFactory = makeParamDecorator(InjectMetadata);
export var Inject: InjectMetadataFactory = makeParamDecorator(InjectMetadata);
/**
* Factory for creating {@link OptionalMetadata}.
*/
export var Optional: OptionalFactory = makeParamDecorator(OptionalMetadata);
export var Optional: OptionalMetadataFactory = makeParamDecorator(OptionalMetadata);
/**
* Factory for creating {@link InjectableMetadata}.
*/
export var Injectable: InjectableFactory = <InjectableFactory>makeDecorator(InjectableMetadata);
export var Injectable: InjectableMetadataFactory =
<InjectableMetadataFactory>makeDecorator(InjectableMetadata);
/**
* Factory for creating {@link SelfMetadata}.
*/
export var Self: SelfFactory = makeParamDecorator(SelfMetadata);
export var Self: SelfMetadataFactory = makeParamDecorator(SelfMetadata);
/**
* Factory for creating {@link HostMetadata}.
*/
export var Host: HostFactory = makeParamDecorator(HostMetadata);
export var Host: HostMetadataFactory = makeParamDecorator(HostMetadata);
/**
* Factory for creating {@link SkipSelfMetadata}.
*/
export var SkipSelf: SkipSelfFactory = makeParamDecorator(SkipSelfMetadata);
export var SkipSelf: SkipSelfMetadataFactory = makeParamDecorator(SkipSelfMetadata);

View File

@ -1,11 +1,11 @@
// Public API for compiler
export {Compiler} from './linker/compiler';
export {ComponentResolver} from './linker/component_resolver';
export {AppViewManager} from './linker/view_manager';
export {QueryList} from './linker/query_list';
export {DynamicComponentLoader} from './linker/dynamic_component_loader';
export {ElementRef} from './linker/element_ref';
export {TemplateRef} from './linker/template_ref';
export {EmbeddedViewRef, HostViewRef, ViewRef, HostViewFactoryRef} from './linker/view_ref';
export {EmbeddedViewRef, ViewRef} from './linker/view_ref';
export {ViewContainerRef} from './linker/view_container_ref';
export {ComponentRef} from './linker/dynamic_component_loader';
export {ComponentRef, ComponentFactory} from './linker/component_factory';
export {ExpressionChangedAfterItHasBeenCheckedException} from './linker/exceptions';

View File

@ -1,40 +0,0 @@
import {HostViewFactoryRef} from 'angular2/src/core/linker/view_ref';
import {Injectable} from 'angular2/src/core/di';
import {Type, isBlank, stringify} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {reflector} from 'angular2/src/core/reflection/reflection';
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {HostViewFactoryRef_} from 'angular2/src/core/linker/view_ref';
/**
* Low-level service for compiling {@link Component}s into {@link ProtoViewRef ProtoViews}s, which
* can later be used to create and render a Component instance.
*
* Most applications should instead use higher-level {@link DynamicComponentLoader} service, which
* both compiles and instantiates a Component.
*/
export abstract class Compiler {
abstract compileInHost(componentType: Type): Promise<HostViewFactoryRef>;
abstract clearCache();
}
function isHostViewFactory(type: any): boolean {
return type instanceof HostViewFactory;
}
@Injectable()
export class Compiler_ extends Compiler {
compileInHost(componentType: Type): Promise<HostViewFactoryRef_> {
var metadatas = reflector.annotations(componentType);
var hostViewFactory = metadatas.find(isHostViewFactory);
if (isBlank(hostViewFactory)) {
throw new BaseException(`No precompiled component ${stringify(componentType)} found`);
}
return PromiseWrapper.resolve(new HostViewFactoryRef_(hostViewFactory));
}
clearCache() {}
}

View File

@ -0,0 +1,93 @@
import {Injector} from 'angular2/src/core/di';
import {Type, CONST, isPresent, isBlank} from 'angular2/src/facade/lang';
import {unimplemented} from 'angular2/src/facade/exceptions';
import {ElementRef, ElementRef_} from './element_ref';
import {ViewRef, ViewRef_} from './view_ref';
import {AppElement} from './element';
import {AppViewManager} from './view_manager';
import {ChangeDetectorRef} from '../change_detection/change_detection';
/**
* Represents an instance of a Component created via a {@link ComponentFactory}.
*
* `ComponentRef` provides access to the Component Instance as well other objects related to this
* Component Instance and allows you to destroy the Component Instance via the {@link #destroy}
* method.
*/
export abstract class ComponentRef {
/**
* Location of the Host Element of this Component Instance.
*/
get location(): ElementRef { return unimplemented(); }
/**
* The injector on which the component instance exists.
*/
get injector(): Injector { return unimplemented(); }
/**
* The instance of the Component.
*/
get instance(): any { return unimplemented(); };
/**
* The {@link ViewRef} of the Host View of this Component instance.
*/
get hostView(): ViewRef { return unimplemented(); };
/**
* The {@link ChangeDetectorRef} of the Component instance.
*/
get changeDetectorRef(): ChangeDetectorRef { return unimplemented(); };
/**
* The component type.
*/
get componentType(): Type { return unimplemented(); }
/**
* Destroys the component instance and all of the data structures associated with it.
*/
abstract destroy(): void;
/**
* Allows to register a callback that will be called when the component is destroyed.
*/
abstract onDestroy(callback: Function): void;
}
export class ComponentRef_ extends ComponentRef {
constructor(private _location: AppElement, private _componentType: Type) { super(); }
get location(): ElementRef { return this._location.ref; }
get injector(): Injector { return this._location.injector; }
get instance(): any { return this._location.component; };
get hostView(): ViewRef { return this._location.parentView.ref; };
get changeDetectorRef(): ChangeDetectorRef { return this.hostView; };
get componentType(): Type { return this._componentType; }
destroy(): void { this._location.parentView.destroy(); }
onDestroy(callback: Function): void { this.hostView.onDestroy(callback); }
}
@CONST()
export class ComponentFactory {
constructor(public selector: string, private _viewFactory: Function,
private _componentType: Type) {}
get componentType(): Type { return this._componentType; }
/**
* Creates a new component.
*/
create(injector: Injector, projectableNodes: any[][] = null,
rootSelectorOrNode: string | any = null): ComponentRef {
var vm: AppViewManager = injector.get(AppViewManager);
if (isBlank(projectableNodes)) {
projectableNodes = [];
}
// Note: Host views don't need a declarationAppElement!
var hostView = this._viewFactory(vm, injector, null);
var hostElement = hostView.create(projectableNodes, rootSelectorOrNode);
return new ComponentRef_(hostElement, this._componentType);
}
}

View File

@ -0,0 +1,33 @@
import {Injectable} from 'angular2/src/core/di';
import {Type, isBlank, stringify} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {reflector} from 'angular2/src/core/reflection/reflection';
import {ComponentFactory} from './component_factory';
/**
* Low-level service for loading {@link ComponentFactory}s, which
* can later be used to create and render a Component instance.
*/
export abstract class ComponentResolver {
abstract resolveComponent(componentType: Type): Promise<ComponentFactory>;
abstract clearCache();
}
function _isComponentFactory(type: any): boolean {
return type instanceof ComponentFactory;
}
@Injectable()
export class ReflectorComponentResolver extends ComponentResolver {
resolveComponent(componentType: Type): Promise<ComponentFactory> {
var metadatas = reflector.annotations(componentType);
var componentFactory = metadatas.find(_isComponentFactory);
if (isBlank(componentFactory)) {
throw new BaseException(`No precompiled component ${stringify(componentType)} found`);
}
return PromiseWrapper.resolve(componentFactory);
}
clearCache() {}
}

View File

@ -1,91 +1,9 @@
import {Key, Injector, ResolvedProvider, Provider, provide, Injectable} from 'angular2/src/core/di';
import {Compiler} from './compiler';
import {ComponentResolver} from './component_resolver';
import {isType, Type, stringify, isPresent} from 'angular2/src/facade/lang';
import {AppViewManager} from 'angular2/src/core/linker/view_manager';
import {ElementRef, ElementRef_} from './element_ref';
import {HostViewRef} from './view_ref';
/**
* Represents an instance of a Component created via {@link DynamicComponentLoader}.
*
* `ComponentRef` provides access to the Component Instance as well other objects related to this
* Component Instance and allows you to destroy the Component Instance via the {@link #dispose}
* method.
*/
export abstract class ComponentRef {
/**
* The injector provided {@link DynamicComponentLoader#loadAsRoot}.
*
* TODO(i): this api is useless and should be replaced by an injector retrieved from
* the HostElementRef, which is currently not possible.
*/
injector: Injector;
/**
* Location of the Host Element of this Component Instance.
*/
location: ElementRef;
/**
* The instance of the Component.
*/
instance: any;
/**
* The user defined component type, represented via the constructor function.
*
* <!-- TODO: customize wording for Dart docs -->
*/
componentType: Type;
/**
* The {@link ViewRef} of the Host View of this Component instance.
*/
get hostView(): HostViewRef {
return (<ElementRef_>this.location).internalElement.parentView.ref;
}
/**
* @internal
*
* The instance of the component.
*
* TODO(i): this api should be removed
*/
get hostComponent(): any { return this.instance; }
/**
* Destroys the component instance and all of the data structures associated with it.
*
* TODO(i): rename to destroy to be consistent with AppViewManager and ViewContainerRef
*/
abstract dispose(): void;
}
export class ComponentRef_ extends ComponentRef {
/**
* TODO(i): refactor into public/private fields
*/
constructor(location: ElementRef, instance: any, componentType: Type, injector: Injector,
private _dispose: () => void) {
super();
this.location = location;
this.instance = instance;
this.componentType = componentType;
this.injector = injector;
}
/**
* @internal
*
* Returns the type of this Component instance.
*
* TODO(i): this api should be removed
*/
get hostComponentType(): Type { return this.componentType; }
dispose(): void { this._dispose(); }
}
import {ComponentRef} from './component_factory';
/**
* Service for instantiating a Component and attaching it to a View at a specified location.
@ -140,7 +58,7 @@ export abstract class DynamicComponentLoader {
* </my-app>
* ```
*/
abstract loadAsRoot(type: Type, overrideSelector: string, injector: Injector,
abstract loadAsRoot(type: Type, overrideSelectorOrNode: string | any, injector: Injector,
onDispose?: () => void, projectableNodes?: any[][]): Promise<ComponentRef>;
/**
@ -240,23 +158,20 @@ export abstract class DynamicComponentLoader {
@Injectable()
export class DynamicComponentLoader_ extends DynamicComponentLoader {
constructor(private _compiler: Compiler, private _viewManager: AppViewManager) { super(); }
constructor(private _compiler: ComponentResolver, private _viewManager: AppViewManager) {
super();
}
loadAsRoot(type: Type, overrideSelector: string, injector: Injector, onDispose?: () => void,
projectableNodes?: any[][]): Promise<ComponentRef> {
return this._compiler.compileInHost(type).then(hostProtoViewRef => {
var hostViewRef = this._viewManager.createRootHostView(hostProtoViewRef, overrideSelector,
injector, projectableNodes);
var newLocation = this._viewManager.getHostElement(hostViewRef);
var component = this._viewManager.getComponent(newLocation);
var dispose = () => {
if (isPresent(onDispose)) {
onDispose();
}
this._viewManager.destroyRootHostView(hostViewRef);
};
return new ComponentRef_(newLocation, component, type, injector, dispose);
loadAsRoot(type: Type, overrideSelectorOrNode: string | any, injector: Injector,
onDispose?: () => void, projectableNodes?: any[][]): Promise<ComponentRef> {
return this._compiler.resolveComponent(type).then(componentFactory => {
var componentRef = componentFactory.create(
injector, projectableNodes,
isPresent(overrideSelectorOrNode) ? overrideSelectorOrNode : componentFactory.selector);
if (isPresent(onDispose)) {
componentRef.onDestroy(onDispose);
}
return componentRef;
});
}
@ -270,20 +185,10 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
loadNextToLocation(type: Type, location: ElementRef, providers: ResolvedProvider[] = null,
projectableNodes: any[][] = null): Promise<ComponentRef> {
return this._compiler.compileInHost(type).then(hostProtoViewRef => {
return this._compiler.resolveComponent(type).then(componentFactory => {
var viewContainer = this._viewManager.getViewContainer(location);
var hostViewRef = viewContainer.createHostView(hostProtoViewRef, viewContainer.length,
providers, projectableNodes);
var newLocation = this._viewManager.getHostElement(hostViewRef);
var component = this._viewManager.getComponent(newLocation);
var dispose = () => {
var index = viewContainer.indexOf(hostViewRef);
if (!hostViewRef.destroyed && index !== -1) {
viewContainer.remove(index);
}
};
return new ComponentRef_(newLocation, component, type, null, dispose);
return viewContainer.createComponent(componentFactory, viewContainer.length, providers,
projectableNodes);
});
}
}

View File

@ -81,7 +81,7 @@ export class AppElement {
if (isPresent(refRenderNode)) {
view.renderer.attachViewAfter(refRenderNode, view.flatRootNodes);
}
this.parentView.addRenderContentChild(view);
view.addToContentChildren(this);
}
detachView(viewIndex: number): AppView<any> {
@ -92,7 +92,7 @@ export class AppElement {
view.renderer.detachView(view.flatRootNodes);
view.renderParent.removeContentChild(view);
view.removeFromContentChildren(this);
return view;
}
}

View File

@ -2,15 +2,14 @@ import {unimplemented} from 'angular2/src/facade/exceptions';
import {AppElement} from './element';
/**
* Represents a location in a View that has an injection, change-detection and render context
* associated with it.
*
* An `ElementRef` is created for each element in the Template that contains a Directive, Component
* or data-binding.
* A wrapper around a native element inside of a View.
*
* An `ElementRef` is backed by a render-specific element. In the browser, this is usually a DOM
* element.
*/
// Note: We don't expose things like `Injector`, `ViewContainer`, ... here,
// i.e. users have to ask for what they need. With that, we can build better analysis tools
// and could do better codegen in the future.
export abstract class ElementRef {
/**
* The underlying native element or `null` if direct access to native elements is not supported

View File

@ -1,6 +1,7 @@
import {ElementRef, ElementRef_} from './element_ref';
import {AppElement} from './element';
import {AppView} from './view';
import {EmbeddedViewRef} from './view_ref';
/**
* Represents an Embedded Template that can be used to instantiate Embedded Views.
@ -28,16 +29,18 @@ export abstract class TemplateRef {
*/
// TODO(i): rename to anchor or location
get elementRef(): ElementRef { return null; }
abstract createEmbeddedView(): EmbeddedViewRef;
}
export class TemplateRef_ extends TemplateRef {
constructor(private _appElement: AppElement, private _viewFactory: Function) { super(); }
createEmbeddedView(): AppView<any> {
createEmbeddedView(): EmbeddedViewRef {
var view: AppView<any> = this._viewFactory(this._appElement.parentView.viewManager,
this._appElement.parentInjector, this._appElement);
view.create(null, null);
return view;
return view.ref;
}
get elementRef(): ElementRef { return this._appElement.ref; }

View File

@ -19,12 +19,13 @@ import {
CONST,
CONST_EXPR,
stringify,
isPrimitive
isPrimitive,
isString
} from 'angular2/src/facade/lang';
import {ObservableWrapper} from 'angular2/src/facade/async';
import {Renderer, RootRenderer, RenderComponentType} from 'angular2/src/core/render/api';
import {ViewRef_, HostViewFactoryRef} from './view_ref';
import {ViewRef_} from './view_ref';
import {AppViewManager_, AppViewManager} from './view_manager';
import {ViewType} from './view_type';
@ -50,8 +51,6 @@ import {
import {StaticNodeDebugInfo, DebugContext} from './debug_context';
import {ElementInjector} from './element_injector';
export const HOST_VIEW_ELEMENT_NAME = '$hostViewEl';
const EMPTY_CONTEXT = CONST_EXPR(new Object());
var _scope_check: WtfScopeFn = wtfCreateScope(`AppView#check(ascii id)`);
@ -70,6 +69,7 @@ export abstract class AppView<T> {
contentChildren: AppView<any>[] = [];
viewChildren: AppView<any>[] = [];
renderParent: AppView<any>;
viewContainerElement: AppElement = null;
private _literalArrayCache: any[][];
private _literalMapCache: Array<{[key: string]: any}>;
@ -92,6 +92,8 @@ export abstract class AppView<T> {
private _currentDebugContext: DebugContext = null;
private _hasExternalHostElement: boolean;
constructor(public clazz: any, public componentType: RenderComponentType, public type: ViewType,
public locals: {[key: string]: any}, public viewManager: AppViewManager_,
public parentInjector: Injector, public declarationAppElement: AppElement,
@ -107,7 +109,7 @@ export abstract class AppView<T> {
this._literalMapCache = ListWrapper.createFixedSize(literalMapCacheSize);
}
create(givenProjectableNodes: Array<any | any[]>, rootSelector: string) {
create(givenProjectableNodes: Array<any | any[]>, rootSelectorOrNode: string | any): AppElement {
var context;
var projectableNodes;
switch (this.type) {
@ -126,25 +128,26 @@ export abstract class AppView<T> {
projectableNodes = givenProjectableNodes;
break;
}
this._hasExternalHostElement = isPresent(rootSelectorOrNode);
this.context = context;
this.projectableNodes = projectableNodes;
if (this.debugMode) {
this._resetDebug();
try {
this.createInternal(rootSelector);
return this.createInternal(rootSelectorOrNode);
} catch (e) {
this._rethrowWithContext(e, e.stack);
throw e;
}
} else {
this.createInternal(rootSelector);
return this.createInternal(rootSelectorOrNode);
}
}
/**
* Overwritten by implementations
*/
createInternal(rootSelector: string): void {}
createInternal(rootSelectorOrNode: string | any): AppElement { return null; }
init(rootNodesOrAppElements: any[], allNodes: any[], appElements: {[key: string]: AppElement},
disposables: Function[], subscriptions: any[]) {
@ -162,7 +165,16 @@ export abstract class AppView<T> {
}
}
getHostViewElement(): AppElement { return this.namedAppElements[HOST_VIEW_ELEMENT_NAME]; }
selectOrCreateHostElement(elementName: string, rootSelectorOrNode: string | any,
debugCtx: DebugContext): any {
var hostElement;
if (isPresent(rootSelectorOrNode)) {
hostElement = this.renderer.selectRootElement(rootSelectorOrNode, debugCtx);
} else {
hostElement = this.renderer.createElement(null, elementName, debugCtx);
}
return hostElement;
}
injectorGet(token: any, nodeIndex: number, notFoundResult: any): any {
if (this.debugMode) {
@ -194,16 +206,25 @@ export abstract class AppView<T> {
}
destroy() {
if (this._hasExternalHostElement) {
this.renderer.detachView(this.flatRootNodes);
} else if (isPresent(this.viewContainerElement)) {
this.viewContainerElement.detachView(this.viewContainerElement.nestedViews.indexOf(this));
}
this._destroyRecurse();
}
private _destroyRecurse() {
if (this.destroyed) {
return;
}
var children = this.contentChildren;
for (var i = 0; i < children.length; i++) {
children[i].destroy();
children[i]._destroyRecurse();
}
children = this.viewChildren;
for (var i = 0; i < children.length; i++) {
children[i].destroy();
children[i]._destroyRecurse();
}
if (this.debugMode) {
this._resetDebug();
@ -223,7 +244,6 @@ export abstract class AppView<T> {
private _destroyLocal() {
var hostElement =
this.type === ViewType.COMPONENT ? this.declarationAppElement.nativeElement : null;
this.renderer.destroyView(hostElement, this.allNodes);
for (var i = 0; i < this.disposables.length; i++) {
this.disposables[i]();
}
@ -231,8 +251,14 @@ export abstract class AppView<T> {
ObservableWrapper.dispose(this.subscriptions[i]);
}
this.destroyInternal();
this.dirtyParentQueriesInternal();
if (this._hasExternalHostElement) {
this.renderer.detachView(this.flatRootNodes);
} else if (isPresent(this.viewContainerElement)) {
this.viewContainerElement.detachView(this.viewContainerElement.nestedViews.indexOf(this));
} else {
this.dirtyParentQueriesInternal();
}
this.renderer.destroyView(hostElement, this.allNodes);
}
/**
@ -323,6 +349,18 @@ export abstract class AppView<T> {
}
}
addToContentChildren(renderAppElement: AppElement): void {
renderAppElement.parentView.contentChildren.push(this);
this.viewContainerElement = renderAppElement;
this.dirtyParentQueriesInternal();
}
removeFromContentChildren(renderAppElement: AppElement): void {
ListWrapper.remove(renderAppElement.parentView.contentChildren, this);
this.dirtyParentQueriesInternal();
this.viewContainerElement = null;
}
literalArray(id: number, value: any[]): any[] {
var prevValue = this._literalArrayCache[id];
if (isBlank(value)) {
@ -393,11 +431,6 @@ export abstract class AppView<T> {
throwDestroyedError(details: string): void { throw new ViewDestroyedException(details); }
}
@CONST()
export class HostViewFactory {
constructor(public selector: string, public viewFactory: Function) {}
}
function _findLastRenderNode(node: any): any {
var lastNode;
if (node instanceof AppElement) {

View File

@ -9,21 +9,14 @@ import {AppElement} from './element';
import {ElementRef, ElementRef_} from './element_ref';
import {TemplateRef, TemplateRef_} from './template_ref';
import {
EmbeddedViewRef,
HostViewRef,
HostViewFactoryRef,
HostViewFactoryRef_,
ViewRef,
ViewRef_
} from './view_ref';
import {AppView} from './view';
import {EmbeddedViewRef, ViewRef, ViewRef_} from './view_ref';
import {ComponentFactory, ComponentRef} from './component_factory';
/**
* Represents a container where one or more Views can be attached.
*
* The container can contain two kinds of Views. Host Views, created by instantiating a
* {@link Component} via {@link #createHostView}, and Embedded Views, created by instantiating an
* {@link Component} via {@link #createComponent}, and Embedded Views, created by instantiating an
* {@link TemplateRef Embedded Template} via {@link #createEmbeddedView}.
*
* The location of the View Container within the containing View is specified by the Anchor
@ -83,11 +76,11 @@ export abstract class ViewContainerRef {
* You can optionally specify `dynamicallyCreatedProviders`, which configure the {@link Injector}
* that will be created for the Host View.
*
* Returns the {@link HostViewRef} of the Host View created for the newly instantiated Component.
* Returns the {@link ComponentRef} of the Host View created for the newly instantiated Component.
*/
abstract createHostView(hostViewFactoryRef: HostViewFactoryRef, index?: number,
dynamicallyCreatedProviders?: ResolvedProvider[],
projectableNodes?: any[][]): HostViewRef;
abstract createComponent(componentFactory: ComponentFactory, index?: number,
dynamicallyCreatedProviders?: ResolvedProvider[],
projectableNodes?: any[][]): ComponentRef;
/**
* Inserts a View identified by a {@link ViewRef} into the container at the specified `index`.
@ -130,45 +123,32 @@ export class ViewContainerRef_ implements ViewContainerRef {
get element(): ElementRef { return this._element.ref; }
/** @internal */
_createEmbeddedViewInContainerScope: WtfScopeFn =
wtfCreateScope('ViewContainerRef#createEmbeddedView()');
// TODO(rado): profile and decide whether bounds checks should be added
// to the methods below.
createEmbeddedView(templateRef: TemplateRef, index: number = -1): EmbeddedViewRef {
var s = this._createEmbeddedViewInContainerScope();
if (index == -1) index = this.length;
var templateRef_ = (<TemplateRef_>templateRef);
var view: AppView<any> = templateRef_.createEmbeddedView();
this._element.attachView(view, index);
return wtfLeave(s, view.ref);
var viewRef: EmbeddedViewRef = templateRef.createEmbeddedView();
this.insert(viewRef, index);
return viewRef;
}
/** @internal */
_createHostViewInContainerScope: WtfScopeFn = wtfCreateScope('ViewContainerRef#createHostView()');
_createComponentInContainerScope: WtfScopeFn =
wtfCreateScope('ViewContainerRef#createComponent()');
createHostView(hostViewFactoryRef: HostViewFactoryRef, index: number = -1,
dynamicallyCreatedProviders: ResolvedProvider[] = null,
projectableNodes: any[][] = null): HostViewRef {
var s = this._createHostViewInContainerScope();
if (index == -1) index = this.length;
var contextEl = this._element;
createComponent(componentFactory: ComponentFactory, index: number = -1,
dynamicallyCreatedProviders: ResolvedProvider[] = null,
projectableNodes: any[][] = null): ComponentRef {
var s = this._createComponentInContainerScope();
var contextInjector = this._element.parentInjector;
var hostViewFactory = (<HostViewFactoryRef_>hostViewFactoryRef).internalHostViewFactory;
var childInjector =
isPresent(dynamicallyCreatedProviders) && dynamicallyCreatedProviders.length > 0 ?
new Injector_(ProtoInjector.fromResolvedProviders(dynamicallyCreatedProviders),
contextInjector) :
contextInjector;
var view =
hostViewFactory.viewFactory(contextEl.parentView.viewManager, childInjector, contextEl);
view.create(projectableNodes, null);
this._element.attachView(view, index);
return wtfLeave(s, view.ref);
var componentRef = componentFactory.create(childInjector, projectableNodes);
this.insert(componentRef.hostView, index);
return wtfLeave(s, componentRef);
}
/** @internal */

View File

@ -9,20 +9,10 @@ import {
import {isPresent, isBlank, isArray, Type} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {ElementRef, ElementRef_} from './element_ref';
import {
HostViewFactoryRef,
HostViewFactoryRef_,
EmbeddedViewRef,
HostViewRef,
ViewRef,
ViewRef_
} from './view_ref';
import {ViewContainerRef, ViewContainerRef_} from './view_container_ref';
import {RootRenderer, RenderComponentType, Renderer} from 'angular2/src/core/render/api';
import {wtfCreateScope, wtfLeave, WtfScopeFn} from '../profile/profile';
import {APP_ID} from 'angular2/src/core/application_tokens';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {ViewType} from './view_type';
/**
* Service exposing low level API for creating, moving and destroying Views.
@ -36,11 +26,6 @@ export abstract class AppViewManager {
*/
abstract getViewContainer(location: ElementRef): ViewContainerRef;
/**
* Returns the {@link ElementRef} that makes up the specified Host View.
*/
abstract getHostElement(hostViewRef: HostViewRef): ElementRef;
/**
* Searches the Component View of the Component specified via `hostLocation` and returns the
* {@link ElementRef} for the Element identified via a Variable Name `variableName`.
@ -50,75 +35,6 @@ export abstract class AppViewManager {
*/
abstract getNamedElementInComponentView(hostLocation: ElementRef,
variableName: string): ElementRef;
/**
* Returns the component instance for the provided Host Element.
*/
abstract getComponent(hostLocation: ElementRef): any;
/**
* Creates an instance of a Component and attaches it to the first element in the global View
* (usually DOM Document) that matches the component's selector or `overrideSelector`.
*
* This as a low-level way to bootstrap an application and upgrade an existing Element to a
* Host Element. Most applications should use {@link DynamicComponentLoader#loadAsRoot} instead.
*
* The Component and its View are created based on the `hostProtoComponentRef` which can be
* obtained
* by compiling the component with {@link Compiler#compileInHost}.
*
* Use {@link AppViewManager#destroyRootHostView} to destroy the created Component and it's Host
* View.
*
* ### Example
*
* ```
* @ng.Component({
* selector: 'child-component'
* })
* @ng.View({
* template: 'Child'
* })
* class ChildComponent {
*
* }
*
* @ng.Component({
* selector: 'my-app'
* })
* @ng.View({
* template: `
* Parent (<some-component></some-component>)
* `
* })
* class MyApp implements OnDestroy {
* viewRef: ng.ViewRef;
*
* constructor(public appViewManager: ng.AppViewManager, compiler: ng.Compiler) {
* compiler.compileInHost(ChildComponent).then((protoView: ng.ProtoComponentRef) => {
* this.viewRef = appViewManager.createRootHostView(protoView, 'some-component', null);
* })
* }
*
* ngOnDestroy() {
* this.appViewManager.destroyRootHostView(this.viewRef);
* this.viewRef = null;
* }
* }
*
* ng.bootstrap(MyApp);
* ```
*/
abstract createRootHostView(hostViewFactoryRef: HostViewFactoryRef, overrideSelector: string,
injector: Injector, projectableNodes?: any[][]): HostViewRef;
/**
* Destroys the Host View created via {@link AppViewManager#createRootHostView}.
*
* Along with the Host View, the Component Instance as well as all nested View and Components are
* destroyed as well.
*/
abstract destroyRootHostView(hostViewRef: HostViewRef);
}
@Injectable()
@ -131,14 +47,6 @@ export class AppViewManager_ extends AppViewManager {
return (<ElementRef_>location).internalElement.vcRef;
}
getHostElement(hostViewRef: ViewRef): ElementRef {
var hostView = (<ViewRef_>hostViewRef).internalView;
if (hostView.type !== ViewType.HOST) {
throw new BaseException('This operation is only allowed on host views');
}
return hostView.getHostViewElement().ref;
}
getNamedElementInComponentView(hostLocation: ElementRef, variableName: string): ElementRef {
var appEl = (<ElementRef_>hostLocation).internalElement;
var componentView = appEl.componentView;
@ -152,34 +60,6 @@ export class AppViewManager_ extends AppViewManager {
throw new BaseException(`Could not find variable ${variableName}`);
}
getComponent(hostLocation: ElementRef): any {
return (<ElementRef_>hostLocation).internalElement.component;
}
/** @internal */
_createRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#createRootHostView()');
createRootHostView(hostViewFactoryRef: HostViewFactoryRef, overrideSelector: string,
injector: Injector, projectableNodes: any[][] = null): HostViewRef {
var s = this._createRootHostViewScope();
var hostViewFactory = (<HostViewFactoryRef_>hostViewFactoryRef).internalHostViewFactory;
var selector = isPresent(overrideSelector) ? overrideSelector : hostViewFactory.selector;
var view = hostViewFactory.viewFactory(this, injector, null);
view.create(projectableNodes, selector);
return wtfLeave(s, view.ref);
}
/** @internal */
_destroyRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#destroyRootHostView()');
destroyRootHostView(hostViewRef: ViewRef) {
var s = this._destroyRootHostViewScope();
var hostView = (<ViewRef_>hostViewRef).internalView;
hostView.renderer.detachView(hostView.flatRootNodes);
hostView.destroy();
wtfLeave(s);
}
/**
* Used by the generated code
*/

View File

@ -1,6 +1,7 @@
import {unimplemented} from 'angular2/src/facade/exceptions';
import {isPresent} from 'angular2/src/facade/lang';
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
import {AppView, HostViewFactory} from './view';
import {AppView} from './view';
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection/constants';
export abstract class ViewRef extends ChangeDetectorRef {
@ -10,19 +11,8 @@ export abstract class ViewRef extends ChangeDetectorRef {
get changeDetectorRef(): ChangeDetectorRef { return <ChangeDetectorRef>unimplemented(); };
get destroyed(): boolean { return <boolean>unimplemented(); }
}
/**
* Represents a View containing a single Element that is the Host Element of a {@link Component}
* instance.
*
* A Host View is created for every dynamically created Component that was compiled on its own (as
* opposed to as a part of another Component's Template) via {@link Compiler#compileInHost} or one
* of the higher-level APIs: {@link AppViewManager#createRootHostView},
* {@link AppViewManager#createHostViewInContainer}, {@link ViewContainerRef#createHostView}.
*/
export abstract class HostViewRef extends ViewRef {
get rootNodes(): any[] { return <any[]>unimplemented(); };
abstract onDestroy(callback: Function);
}
/**
@ -90,9 +80,14 @@ export abstract class EmbeddedViewRef extends ViewRef {
abstract hasLocal(variableName: string): boolean;
get rootNodes(): any[] { return <any[]>unimplemented(); };
/**
* Destroys the view and all of the data structures associated with it.
*/
abstract destroy();
}
export class ViewRef_ implements EmbeddedViewRef, HostViewRef {
export class ViewRef_ implements EmbeddedViewRef {
constructor(private _view: AppView<any>) { this._view = _view; }
get internalView(): AppView<any> { return this._view; }
@ -118,12 +113,8 @@ export class ViewRef_ implements EmbeddedViewRef, HostViewRef {
this._view.cdMode = ChangeDetectionStrategy.CheckAlways;
this.markForCheck();
}
}
export abstract class HostViewFactoryRef {}
export class HostViewFactoryRef_ implements HostViewFactoryRef {
constructor(private _hostViewFactory: HostViewFactory) {}
get internalHostViewFactory(): HostViewFactory { return this._hostViewFactory; }
onDestroy(callback: Function) { this._view.disposables.push(callback); }
destroy() { this._view.destroy(); }
}

View File

@ -146,7 +146,7 @@ export interface ViewDecorator extends TypeDecorator {
* ]
* ```
*/
export interface DirectiveFactory {
export interface DirectiveMetadataFactory {
(obj: {
selector?: string,
inputs?: string[],
@ -204,7 +204,7 @@ export interface DirectiveFactory {
* ]
* ```
*/
export interface ComponentFactory {
export interface ComponentMetadataFactory {
(obj: {
selector?: string,
inputs?: string[],
@ -298,7 +298,7 @@ export interface ComponentFactory {
* ]
* ```
*/
export interface ViewFactory {
export interface ViewMetadataFactory {
(obj: {
templateUrl?: string,
template?: string,
@ -353,7 +353,7 @@ export interface ViewFactory {
* ]
* ```
*/
export interface AttributeFactory {
export interface AttributeMetadataFactory {
(name: string): TypeDecorator;
new (name: string): AttributeMetadata;
}
@ -401,7 +401,7 @@ export interface AttributeFactory {
* ]
* ```
*/
export interface QueryFactory {
export interface QueryMetadataFactory {
(selector: Type | string, {descendants}?: {descendants?: boolean}): ParameterDecorator;
new (selector: Type | string, {descendants}?: {descendants?: boolean}): QueryMetadata;
}
@ -409,7 +409,7 @@ export interface QueryFactory {
/**
* Factory for {@link ContentChildren}.
*/
export interface ContentChildrenFactory {
export interface ContentChildrenMetadataFactory {
(selector: Type | string, {descendants}?: {descendants?: boolean}): any;
new (selector: Type | string, {descendants}?: {descendants?: boolean}): ContentChildrenMetadata;
}
@ -417,15 +417,15 @@ export interface ContentChildrenFactory {
/**
* Factory for {@link ContentChild}.
*/
export interface ContentChildFactory {
export interface ContentChildMetadataFactory {
(selector: Type | string): any;
new (selector: Type | string): ContentChildFactory;
new (selector: Type | string): ContentChildMetadataFactory;
}
/**
* Factory for {@link ViewChildren}.
*/
export interface ViewChildrenFactory {
export interface ViewChildrenMetadataFactory {
(selector: Type | string): any;
new (selector: Type | string): ViewChildrenMetadata;
}
@ -433,9 +433,9 @@ export interface ViewChildrenFactory {
/**
* Factory for {@link ViewChild}.
*/
export interface ViewChildFactory {
export interface ViewChildMetadataFactory {
(selector: Type | string): any;
new (selector: Type | string): ViewChildFactory;
new (selector: Type | string): ViewChildMetadataFactory;
}
@ -446,7 +446,7 @@ export interface ViewChildFactory {
*
* {@example core/ts/metadata/metadata.ts region='pipe'}
*/
export interface PipeFactory {
export interface PipeMetadataFactory {
(obj: {name: string, pure?: boolean}): any;
new (obj: {name: string, pure?: boolean}): any;
}
@ -456,7 +456,7 @@ export interface PipeFactory {
*
* See {@link InputMetadata}.
*/
export interface InputFactory {
export interface InputMetadataFactory {
(bindingPropertyName?: string): any;
new (bindingPropertyName?: string): any;
}
@ -466,7 +466,7 @@ export interface InputFactory {
*
* See {@link OutputMetadata}.
*/
export interface OutputFactory {
export interface OutputMetadataFactory {
(bindingPropertyName?: string): any;
new (bindingPropertyName?: string): any;
}
@ -474,7 +474,7 @@ export interface OutputFactory {
/**
* {@link HostBindingMetadata} factory function.
*/
export interface HostBindingFactory {
export interface HostBindingMetadataFactory {
(hostPropertyName?: string): any;
new (hostPropertyName?: string): any;
}
@ -482,7 +482,7 @@ export interface HostBindingFactory {
/**
* {@link HostListenerMetadata} factory function.
*/
export interface HostListenerFactory {
export interface HostListenerMetadataFactory {
(eventName: string, args?: string[]): any;
new (eventName: string, args?: string[]): any;
}
@ -511,8 +511,8 @@ export interface HostListenerFactory {
*
* {@example core/ts/metadata/metadata.ts region='component'}
*/
export var Component: ComponentFactory =
<ComponentFactory>makeDecorator(ComponentMetadata, (fn: any) => fn.View = View);
export var Component: ComponentMetadataFactory =
<ComponentMetadataFactory>makeDecorator(ComponentMetadata, (fn: any) => fn.View = View);
// TODO(alexeagle): remove the duplication of this doc. It is copied from DirectiveMetadata.
/**
@ -893,7 +893,8 @@ export var Component: ComponentFactory =
* the instantiated
* view occurs on the second `<li></li>` which is a sibling to the `<template>` element.
*/
export var Directive: DirectiveFactory = <DirectiveFactory>makeDecorator(DirectiveMetadata);
export var Directive: DirectiveMetadataFactory =
<DirectiveMetadataFactory>makeDecorator(DirectiveMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from ViewMetadata.
/**
@ -925,7 +926,8 @@ export var Directive: DirectiveFactory = <DirectiveFactory>makeDecorator(Directi
* }
* ```
*/
var View: ViewFactory = <ViewFactory>makeDecorator(ViewMetadata, (fn: any) => fn.View = View);
var View: ViewMetadataFactory =
<ViewMetadataFactory>makeDecorator(ViewMetadata, (fn: any) => fn.View = View);
/**
* Specifies that a constant attribute value should be injected.
@ -944,7 +946,7 @@ var View: ViewFactory = <ViewFactory>makeDecorator(ViewMetadata, (fn: any) => fn
*
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
*/
export var Attribute: AttributeFactory = makeParamDecorator(AttributeMetadata);
export var Attribute: AttributeMetadataFactory = makeParamDecorator(AttributeMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from QueryMetadata.
/**
@ -1054,7 +1056,7 @@ export var Attribute: AttributeFactory = makeParamDecorator(AttributeMetadata);
* The injected object is an unmodifiable live list.
* See {@link QueryList} for more details.
*/
export var Query: QueryFactory = makeParamDecorator(QueryMetadata);
export var Query: QueryMetadataFactory = makeParamDecorator(QueryMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from ContentChildrenMetadata.
/**
@ -1077,7 +1079,8 @@ export var Query: QueryFactory = makeParamDecorator(QueryMetadata);
* }
* ```
*/
export var ContentChildren: ContentChildrenFactory = makePropDecorator(ContentChildrenMetadata);
export var ContentChildren: ContentChildrenMetadataFactory =
makePropDecorator(ContentChildrenMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from ContentChildMetadata.
/**
@ -1100,7 +1103,7 @@ export var ContentChildren: ContentChildrenFactory = makePropDecorator(ContentCh
* }
* ```
*/
export var ContentChild: ContentChildFactory = makePropDecorator(ContentChildMetadata);
export var ContentChild: ContentChildMetadataFactory = makePropDecorator(ContentChildMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from ViewChildrenMetadata.
/**
@ -1182,7 +1185,7 @@ export var ContentChild: ContentChildFactory = makePropDecorator(ContentChildMet
*
* See also: [ViewChildrenMetadata]
*/
export var ViewChildren: ViewChildrenFactory = makePropDecorator(ViewChildrenMetadata);
export var ViewChildren: ViewChildrenMetadataFactory = makePropDecorator(ViewChildrenMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from ViewChildMetadata.
/**
@ -1255,7 +1258,7 @@ export var ViewChildren: ViewChildrenFactory = makePropDecorator(ViewChildrenMet
* ```
* See also: [ViewChildMetadata]
*/
export var ViewChild: ViewChildFactory = makePropDecorator(ViewChildMetadata);
export var ViewChild: ViewChildMetadataFactory = makePropDecorator(ViewChildMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from ViewQueryMetadata.
/**
@ -1293,7 +1296,7 @@ export var ViewChild: ViewChildFactory = makePropDecorator(ViewChildMetadata);
* The injected object is an iterable and observable live list.
* See {@link QueryList} for more details.
*/
export var ViewQuery: QueryFactory = makeParamDecorator(ViewQueryMetadata);
export var ViewQuery: QueryMetadataFactory = makeParamDecorator(ViewQueryMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from PipeMetadata.
/**
@ -1303,7 +1306,7 @@ export var ViewQuery: QueryFactory = makeParamDecorator(ViewQueryMetadata);
*
* {@example core/ts/metadata/metadata.ts region='pipe'}
*/
export var Pipe: PipeFactory = <PipeFactory>makeDecorator(PipeMetadata);
export var Pipe: PipeMetadataFactory = <PipeMetadataFactory>makeDecorator(PipeMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from InputMetadata.
/**
@ -1347,7 +1350,7 @@ export var Pipe: PipeFactory = <PipeFactory>makeDecorator(PipeMetadata);
* bootstrap(App);
* ```
*/
export var Input: InputFactory = makePropDecorator(InputMetadata);
export var Input: InputMetadataFactory = makePropDecorator(InputMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from OutputMetadata.
/**
@ -1391,7 +1394,7 @@ export var Input: InputFactory = makePropDecorator(InputMetadata);
* bootstrap(App);
* ```
*/
export var Output: OutputFactory = makePropDecorator(OutputMetadata);
export var Output: OutputMetadataFactory = makePropDecorator(OutputMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from HostBindingMetadata.
/**
@ -1429,7 +1432,7 @@ export var Output: OutputFactory = makePropDecorator(OutputMetadata);
* bootstrap(App);
* ```
*/
export var HostBinding: HostBindingFactory = makePropDecorator(HostBindingMetadata);
export var HostBinding: HostBindingMetadataFactory = makePropDecorator(HostBindingMetadata);
// TODO(alexeagle): remove the duplication of this doc. It is copied from HostListenerMetadata.
/**
@ -1466,4 +1469,4 @@ export var HostBinding: HostBindingFactory = makePropDecorator(HostBindingMetada
* bootstrap(App);
* ```
*/
export var HostListener: HostListenerFactory = makePropDecorator(HostListenerMetadata);
export var HostListener: HostListenerMetadataFactory = makePropDecorator(HostListenerMetadata);

View File

@ -16,7 +16,7 @@ export abstract class RenderDebugInfo {
}
export abstract class Renderer {
abstract selectRootElement(selector: string, debugInfo: RenderDebugInfo): any;
abstract selectRootElement(selectorOrNode: string | any, debugInfo: RenderDebugInfo): any;
abstract createElement(parentElement: any, name: string, debugInfo: RenderDebugInfo): any;

View File

@ -1,7 +1,7 @@
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {Injectable} from 'angular2/src/core/di';
import {Type} from 'angular2/src/facade/lang';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {ComponentRef} from 'angular2/src/core/linker/component_factory';
import {Provider, Injector} from 'angular2/src/core/di';
import {NgZone} from 'angular2/src/core/zone/ng_zone';

View File

@ -1,5 +1,5 @@
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {ComponentRef, ComponentRef_} from 'angular2/src/core/linker/dynamic_component_loader';
import {ComponentRef} from 'angular2/src/core/linker/component_factory';
import {isPresent, NumberWrapper} from 'angular2/src/facade/lang';
import {window} from 'angular2/src/facade/browser';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
@ -25,9 +25,7 @@ export class AngularTools {
export class AngularProfiler {
appRef: ApplicationRef;
constructor(ref: ComponentRef) {
this.appRef = (<ComponentRef_>ref).injector.get(ApplicationRef);
}
constructor(ref: ComponentRef) { this.appRef = ref.injector.get(ApplicationRef); }
/**
* Exercises change detection in a loop and then prints the average amount of

View File

@ -1,7 +1,7 @@
library angular2.src.tools.tools;
import 'dart:js';
import 'package:angular2/src/core/linker/dynamic_component_loader.dart'
import 'package:angular2/src/core/linker/component_factory.dart'
show ComponentRef;
import 'common_tools.dart' show AngularTools;

View File

@ -1,5 +1,5 @@
import {global} from 'angular2/src/facade/lang';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {ComponentRef} from 'angular2/src/core/linker/component_factory';
import {AngularTools} from './common_tools';
var context = <any>global;

View File

@ -8,7 +8,8 @@ import {
CONST_EXPR,
stringify,
StringWrapper,
isArray
isArray,
isString
} from 'angular2/src/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
@ -76,10 +77,15 @@ export class DomRenderer implements Renderer {
}
}
selectRootElement(selector: string, debugInfo: RenderDebugInfo): Element {
var el = DOM.querySelector(this._rootRenderer.document, selector);
if (isBlank(el)) {
throw new BaseException(`The selector "${selector}" did not match any elements`);
selectRootElement(selectorOrNode: string | any, debugInfo: RenderDebugInfo): Element {
var el;
if (isString(selectorOrNode)) {
el = DOM.querySelector(this._rootRenderer.document, selectorOrNode);
if (isBlank(el)) {
throw new BaseException(`The selector "${selectorOrNode}" did not match any elements`);
}
} else {
el = selectorOrNode;
}
DOM.clearNodes(el);
return el;

View File

@ -118,7 +118,7 @@ export class RouterOutlet implements OnDestroy {
}
return next.then((_) => {
if (isPresent(this._componentRef)) {
var onDispose = this._componentRef.then((ref: ComponentRef) => ref.dispose());
var onDispose = this._componentRef.then((ref: ComponentRef) => ref.destroy());
this._componentRef = null;
return onDispose;
}

View File

@ -6,6 +6,7 @@ import {
ViewMetadata,
ElementRef,
EmbeddedViewRef,
ChangeDetectorRef,
provide
} from 'angular2/core';
import {DirectiveResolver, ViewResolver} from 'angular2/compiler';
@ -14,9 +15,6 @@ import {Type, isPresent, isBlank} from 'angular2/src/facade/lang';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
import {ViewRef_} from 'angular2/src/core/linker/view_ref';
import {AppView} from 'angular2/src/core/linker/view';
import {el} from './utils';
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
@ -29,7 +27,7 @@ import {tick} from './fake_async';
/**
* Fixture for debugging and testing a component.
*/
export abstract class ComponentFixture {
export class ComponentFixture {
/**
* The DebugElement associated with the root element of this component.
*/
@ -51,46 +49,40 @@ export abstract class ComponentFixture {
elementRef: ElementRef;
/**
* Trigger a change detection cycle for the component.
* The ComponentRef for the component
*/
abstract detectChanges(checkNoChanges?: boolean): void;
abstract checkNoChanges(): void;
componentRef: ComponentRef;
/**
* Trigger component destruction.
* The ChangeDetectorRef for the component
*/
abstract destroy(): void;
}
export class ComponentFixture_ extends ComponentFixture {
/** @internal */
_componentRef: ComponentRef;
/** @internal */
_componentParentView: AppView<any>;
changeDetectorRef: ChangeDetectorRef;
constructor(componentRef: ComponentRef) {
super();
this._componentParentView = (<ViewRef_>componentRef.hostView).internalView;
var hostAppElement = this._componentParentView.getHostViewElement();
this.elementRef = hostAppElement.ref;
this.debugElement = <DebugElement>getDebugNode(hostAppElement.nativeElement);
this.componentInstance = hostAppElement.component;
this.nativeElement = hostAppElement.nativeElement;
this._componentRef = componentRef;
this.changeDetectorRef = componentRef.changeDetectorRef;
this.elementRef = componentRef.location;
this.debugElement = <DebugElement>getDebugNode(this.elementRef.nativeElement);
this.componentInstance = componentRef.instance;
this.nativeElement = this.elementRef.nativeElement;
this.componentRef = componentRef;
}
/**
* Trigger a change detection cycle for the component.
*/
detectChanges(checkNoChanges: boolean = true): void {
this._componentParentView.detectChanges(false);
this.changeDetectorRef.detectChanges();
if (checkNoChanges) {
this.checkNoChanges();
}
}
checkNoChanges(): void { this._componentParentView.detectChanges(true); }
checkNoChanges(): void { this.changeDetectorRef.checkNoChanges(); }
destroy(): void { this._componentRef.dispose(); }
/**
* Trigger component destruction.
*/
destroy(): void { this.componentRef.destroy(); }
}
var _nextRootElementId = 0;
@ -261,11 +253,10 @@ export class TestComponentBuilder {
}
DOM.appendChild(doc.body, rootEl);
var promise: Promise<ComponentRef> =
this._injector.get(DynamicComponentLoader)
.loadAsRoot(rootComponentType, `#${rootElId}`, this._injector);
return promise.then((componentRef) => { return new ComponentFixture_(componentRef); });
return promise.then((componentRef) => { return new ComponentFixture(componentRef); });
}
createFakeAsync(rootComponentType: Type): ComponentFixture {

View File

@ -1,7 +1,7 @@
export const NG2_APP_VIEW_MANAGER = 'ng2.AppViewManager';
export const NG2_COMPILER = 'ng2.Compiler';
export const NG2_INJECTOR = 'ng2.Injector';
export const NG2_HOST_VIEW_FACTORY_REF_MAP = 'ng2.HostViewFactoryRefMap';
export const NG2_COMPONENT_FACTORY_REF_MAP = 'ng2.ComponentFactoryRefMap';
export const NG2_ZONE = 'ng2.NgZone';
export const NG1_CONTROLLER = '$controller';

View File

@ -2,10 +2,10 @@ import {
provide,
AppViewManager,
ChangeDetectorRef,
HostViewRef,
Injector,
OnChanges,
HostViewFactoryRef,
ComponentFactory,
ComponentRef,
SimpleChange
} from 'angular2/core';
import {NG1_SCOPE} from './constants';
@ -21,7 +21,7 @@ export class DowngradeNg2ComponentAdapter {
component: any = null;
inputChangeCount: number = 0;
inputChanges: {[key: string]: SimpleChange} = null;
hostViewRef: HostViewRef = null;
componentRef: ComponentRef = null;
changeDetector: ChangeDetectorRef = null;
componentScope: angular.IScope;
childNodes: Node[];
@ -31,7 +31,7 @@ export class DowngradeNg2ComponentAdapter {
private element: angular.IAugmentedJQuery, private attrs: angular.IAttributes,
private scope: angular.IScope, private parentInjector: Injector,
private parse: angular.IParseService, private viewManager: AppViewManager,
private hostViewFactory: HostViewFactoryRef) {
private componentFactory: ComponentFactory) {
(<any>this.element[0]).id = id;
this.componentScope = scope.$new();
this.childNodes = <Node[]><any>element.contents();
@ -42,11 +42,10 @@ export class DowngradeNg2ComponentAdapter {
[provide(NG1_SCOPE, {useValue: this.componentScope})]);
this.contentInsertionPoint = document.createComment('ng1 insertion point');
this.hostViewRef = this.viewManager.createRootHostView(
this.hostViewFactory, '#' + this.id, childInjector, [[this.contentInsertionPoint]]);
var hostElement = this.viewManager.getHostElement(this.hostViewRef);
this.changeDetector = this.hostViewRef.changeDetectorRef;
this.component = this.viewManager.getComponent(hostElement);
this.componentRef =
this.componentFactory.create(childInjector, [[this.contentInsertionPoint]], '#' + this.id);
this.changeDetector = this.componentRef.changeDetectorRef;
this.component = this.componentRef.instance;
}
setupInputs(): void {
@ -162,7 +161,7 @@ export class DowngradeNg2ComponentAdapter {
registerCleanup() {
this.element.bind('$destroy', () => {
this.componentScope.$destroy();
this.viewManager.destroyRootHostView(this.hostViewRef);
this.componentRef.destroy();
});
}
}

View File

@ -3,11 +3,11 @@ import {
platform,
ApplicationRef,
AppViewManager,
Compiler,
ComponentResolver,
Injector,
NgZone,
PlatformRef,
HostViewFactoryRef,
ComponentFactory,
Provider,
Type,
Testability,
@ -29,7 +29,7 @@ import {
NG2_APP_VIEW_MANAGER,
NG2_COMPILER,
NG2_INJECTOR,
NG2_HOST_VIEW_FACTORY_REF_MAP,
NG2_COMPONENT_FACTORY_REF_MAP,
NG2_ZONE,
REQUIRE_INJECTOR
} from './constants';
@ -305,19 +305,19 @@ export class UpgradeAdapter {
]);
var injector: Injector = applicationRef.injector;
var ngZone: NgZone = injector.get(NgZone);
var compiler: Compiler = injector.get(Compiler);
var compiler: ComponentResolver = injector.get(ComponentResolver);
var delayApplyExps: Function[] = [];
var original$applyFn: Function;
var rootScopePrototype: any;
var rootScope: angular.IRootScopeService;
var hostViewFactoryRefMap: HostViewFactoryRefMap = {};
var componentFactoryRefMap: ComponentFactoryRefMap = {};
var ng1Module = angular.module(this.idPrefix, modules);
var ng1BootstrapPromise: Promise<any> = null;
var ng1compilePromise: Promise<any> = null;
ng1Module.value(NG2_INJECTOR, injector)
.value(NG2_ZONE, ngZone)
.value(NG2_COMPILER, compiler)
.value(NG2_HOST_VIEW_FACTORY_REF_MAP, hostViewFactoryRefMap)
.value(NG2_COMPONENT_FACTORY_REF_MAP, componentFactoryRefMap)
.value(NG2_APP_VIEW_MANAGER, injector.get(AppViewManager))
.config([
'$provide',
@ -393,7 +393,7 @@ export class UpgradeAdapter {
});
Promise.all([
this.compileNg2Components(compiler, hostViewFactoryRefMap),
this.compileNg2Components(compiler, componentFactoryRefMap),
ng1BootstrapPromise,
ng1compilePromise
])
@ -519,35 +519,36 @@ export class UpgradeAdapter {
}
/* @internal */
private compileNg2Components(compiler: Compiler, hostViewFactoryRefMap: HostViewFactoryRefMap):
Promise<HostViewFactoryRefMap> {
var promises: Array<Promise<HostViewFactoryRef>> = [];
private compileNg2Components(compiler: ComponentResolver,
componentFactoryRefMap: ComponentFactoryRefMap):
Promise<ComponentFactoryRefMap> {
var promises: Array<Promise<ComponentFactory>> = [];
var types = this.upgradedComponents;
for (var i = 0; i < types.length; i++) {
promises.push(compiler.compileInHost(types[i]));
promises.push(compiler.resolveComponent(types[i]));
}
return Promise.all(promises).then((hostViewFactories: Array<HostViewFactoryRef>) => {
return Promise.all(promises).then((componentFactories: Array<ComponentFactory>) => {
var types = this.upgradedComponents;
for (var i = 0; i < hostViewFactories.length; i++) {
hostViewFactoryRefMap[getComponentInfo(types[i]).selector] = hostViewFactories[i];
for (var i = 0; i < componentFactories.length; i++) {
componentFactoryRefMap[getComponentInfo(types[i]).selector] = componentFactories[i];
}
return hostViewFactoryRefMap;
return componentFactoryRefMap;
}, onError);
}
}
interface HostViewFactoryRefMap {
[selector: string]: HostViewFactoryRef;
interface ComponentFactoryRefMap {
[selector: string]: ComponentFactory;
}
function ng1ComponentDirective(info: ComponentInfo, idPrefix: string): Function {
(<any>directiveFactory).$inject =
[NG2_HOST_VIEW_FACTORY_REF_MAP, NG2_APP_VIEW_MANAGER, NG1_PARSE];
function directiveFactory(hostViewFactoryRefMap: HostViewFactoryRefMap,
[NG2_COMPONENT_FACTORY_REF_MAP, NG2_APP_VIEW_MANAGER, NG1_PARSE];
function directiveFactory(componentFactoryRefMap: ComponentFactoryRefMap,
viewManager: AppViewManager,
parse: angular.IParseService): angular.IDirective {
var hostViewFactory: HostViewFactoryRef = hostViewFactoryRefMap[info.selector];
if (!hostViewFactory) throw new Error('Expecting HostViewFactoryRef for: ' + info.selector);
var componentFactory: ComponentFactory = componentFactoryRefMap[info.selector];
if (!componentFactory) throw new Error('Expecting ComponentFactory for: ' + info.selector);
var idCount = 0;
return {
restrict: 'E',
@ -558,7 +559,7 @@ function ng1ComponentDirective(info: ComponentInfo, idPrefix: string): Function
var domElement = <any>element[0];
var facade = new DowngradeNg2ComponentAdapter(idPrefix + (idCount++), info, element,
attrs, scope, <Injector>parentInjector,
parse, viewManager, hostViewFactory);
parse, viewManager, componentFactory);
facade.setupInputs();
facade.bootstrapNg2();
facade.projectContent();

View File

@ -95,10 +95,10 @@ export class WebWorkerRenderer implements Renderer, RenderStoreObject {
this._rootRenderer.runOnService(fnName, fnArgsWithRenderer);
}
selectRootElement(selector: string, debugInfo: RenderDebugInfo): any {
selectRootElement(selectorOrNode: string, debugInfo: RenderDebugInfo): any {
var node = this._rootRenderer.allocateNode();
this._runOnService('selectRootElement',
[new FnArg(selector, null), new FnArg(node, RenderStoreObject)]);
[new FnArg(selectorOrNode, null), new FnArg(node, RenderStoreObject)]);
return node;
}

View File

@ -4,9 +4,9 @@ import {TypeScriptEmitter} from 'angular2/src/compiler/output/ts_emitter';
import {DartEmitter} from 'angular2/src/compiler/output/dart_emitter';
import * as o from 'angular2/src/compiler/output/output_ast';
import {compileComp, compAMetadata} from './offline_compiler_util';
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
export const hostViewFactory_CompA: HostViewFactory = null;
export const CompANgFactory: ComponentFactory = null;
// Generator
export function main(args: string[]) {

View File

@ -2,9 +2,9 @@
import {print} from 'angular2/src/facade/lang';
import {JavaScriptEmitter} from 'angular2/src/compiler/output/js_emitter';
import {compileComp, compAMetadata} from './offline_compiler_util';
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
export const hostViewFactory_CompA: HostViewFactory = null;
export const CompANgFactory: ComponentFactory = null;
// Generator
export function main(args: string[]) {

View File

@ -18,65 +18,48 @@ import {IS_DART} from 'angular2/src/facade/lang';
import {Injector} from 'angular2/core';
import {DebugNode, DebugElement, getDebugNode} from 'angular2/src/core/debug/debug_node';
import {HostViewFactoryRef_} from 'angular2/src/core/linker/view_ref';
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
import * as typed from './offline_compiler_codegen_typed';
import * as untyped from './offline_compiler_codegen_untyped';
import {AppViewManager} from 'angular2/src/core/linker/view_manager';
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {SharedStylesHost} from "angular2/src/platform/dom/shared_styles_host";
import {CompA} from './offline_compiler_util';
var _nextRootElementId = 0;
export function main() {
var outputDefs = [];
var typedHostViewFactory = typed.hostViewFactory_CompA;
var untypedHostViewFactory = untyped.hostViewFactory_CompA;
var typedComponentFactory = typed.CompANgFactory;
var untypedComponentFactory = untyped.CompANgFactory;
if (IS_DART || !DOM.supportsDOMEvents()) {
// Our generator only works on node.js and Dart...
outputDefs.push({'compAHostViewFactory': typedHostViewFactory, 'name': 'typed'});
outputDefs.push({'compAHostComponentFactory': typedComponentFactory, 'name': 'typed'});
}
if (!IS_DART) {
// Our generator only works on node.js and Dart...
if (!DOM.supportsDOMEvents()) {
outputDefs.push({'compAHostViewFactory': untypedHostViewFactory, 'name': 'untyped'});
outputDefs.push({'compAHostComponentFactory': untypedComponentFactory, 'name': 'untyped'});
}
}
describe('OfflineCompiler', () => {
var viewManager: AppViewManager;
var injector: Injector;
var sharedStylesHost: SharedStylesHost;
var rootEl;
beforeEach(inject([AppViewManager, Injector, SharedStylesHost],
(_viewManager, _injector, _sharedStylesHost) => {
viewManager = _viewManager;
injector = _injector;
sharedStylesHost = _sharedStylesHost;
}));
beforeEach(inject([Injector, SharedStylesHost], (_injector, _sharedStylesHost) => {
injector = _injector;
sharedStylesHost = _sharedStylesHost;
}));
function createHostComp(hvf: HostViewFactory): DebugElement {
var doc = injector.get(DOCUMENT);
var oldRoots = DOM.querySelectorAll(doc, hvf.selector);
for (var i = 0; i < oldRoots.length; i++) {
DOM.remove(oldRoots[i]);
}
rootEl = el(`<${hvf.selector}></${hvf.selector}>`);
DOM.appendChild(doc.body, rootEl);
viewManager.createRootHostView(new HostViewFactoryRef_(hvf), hvf.selector, injector, []);
return <DebugElement>getDebugNode(rootEl);
function createHostComp(cf: ComponentFactory): DebugElement {
var compRef = cf.create(injector);
return <DebugElement>getDebugNode(compRef.location.nativeElement);
}
outputDefs.forEach((outputDef) => {
describe(`${outputDef['name']}`, () => {
it('should compile components', () => {
var hostEl = createHostComp(outputDef['compAHostViewFactory']);
var hostEl = createHostComp(outputDef['compAHostComponentFactory']);
expect(hostEl.componentInstance).toBeAnInstanceOf(CompA);
var styles = sharedStylesHost.getAllStyles();
expect(styles[0]).toContain('.redStyle[_ngcontent');

View File

@ -1,51 +0,0 @@
import {
ddescribe,
describe,
xdescribe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
AsyncTestCompleter,
inject,
beforeEachProviders
} from 'angular2/testing_internal';
import {provide} from 'angular2/core';
import {Compiler} from 'angular2/src/core/linker/compiler';
import {reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
import {Compiler_} from "angular2/src/core/linker/compiler";
import {HostViewFactory} from 'angular2/src/core/linker/view';
import {HostViewFactoryRef_} from 'angular2/src/core/linker/view_ref';
export function main() {
describe('Compiler', () => {
var someHostViewFactory;
beforeEachProviders(() => [provide(Compiler, {useClass: Compiler_})]);
beforeEach(inject([Compiler], (_compiler) => {
someHostViewFactory = new HostViewFactory(null, null);
reflector.registerType(SomeComponent, new ReflectionInfo([someHostViewFactory]));
}));
it('should read the template from an annotation',
inject([AsyncTestCompleter, Compiler], (async, compiler: Compiler) => {
compiler.compileInHost(SomeComponent)
.then((hostViewFactoryRef: HostViewFactoryRef_) => {
expect(hostViewFactoryRef.internalHostViewFactory).toBe(someHostViewFactory);
async.done();
return null;
});
}));
it('should clear the cache', inject([Compiler], (compiler) => {
// Nothing to assert for now...
compiler.clearCache();
}));
});
}
class SomeComponent {}

View File

@ -24,7 +24,6 @@ import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component
import {ElementRef, ElementRef_} from 'angular2/src/core/linker/element_ref';
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {ComponentFixture_} from "angular2/src/testing/test_component_builder";
import {BaseException} from 'angular2/src/facade/exceptions';
import {PromiseWrapper} from 'angular2/src/facade/promise';
@ -61,14 +60,14 @@ export function main() {
loader.loadIntoLocation(DynamicallyLoaded, tc.elementRef, 'loc')
.then(ref => {
ref.dispose();
ref.destroy();
expect(tc.debugElement.nativeElement).toHaveText("Location;");
async.done();
});
});
}));
it('should allow to dispose even if the location has been removed',
it('should allow to destroy even if the location has been removed',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({
@ -95,7 +94,7 @@ export function main() {
tc.detectChanges();
expect(tc.debugElement.nativeElement).toHaveText("");
ref.dispose();
ref.destroy();
expect(tc.debugElement.nativeElement).toHaveText("");
async.done();
});
@ -236,7 +235,7 @@ export function main() {
expect(firstSibling).toHaveText("DynamicallyLoaded;");
expect(secondSibling).toHaveText("DynamicallyLoaded2;");
ref2.dispose();
ref2.destroy();
firstSibling = DOM.nextSibling(tc.debugElement.nativeElement);
secondSibling = DOM.nextSibling(firstSibling);
@ -302,7 +301,7 @@ export function main() {
DOM.appendChild(doc.body, rootEl);
loader.loadAsRoot(ChildComp, null, injector)
.then((componentRef) => {
var el = new ComponentFixture_(componentRef);
var el = new ComponentFixture(componentRef);
expect(rootEl.parentNode).toBe(doc.body);
@ -316,7 +315,7 @@ export function main() {
expect(rootEl).toHaveText('new');
componentRef.dispose();
componentRef.destroy();
expect(rootEl.parentNode).toBeFalsy();

View File

@ -87,7 +87,7 @@ import {QueryList} from 'angular2/src/core/linker/query_list';
import {ViewContainerRef} from 'angular2/src/core/linker/view_container_ref';
import {EmbeddedViewRef} from 'angular2/src/core/linker/view_ref';
import {Compiler} from 'angular2/src/core/linker/compiler';
import {ComponentResolver} from 'angular2/src/core/linker/component_resolver';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
import {TemplateRef} from 'angular2/src/core/linker/template_ref';
@ -1167,7 +1167,7 @@ function declareTests(isJit: boolean) {
describe('dynamic ViewContainers', () => {
it('should allow to create a ViewContainerRef at any bound location',
inject([TestComponentBuilder, AsyncTestCompleter, Compiler],
inject([TestComponentBuilder, AsyncTestCompleter, ComponentResolver],
(tcb: TestComponentBuilder, async, compiler) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<div><dynamic-vp #dynamic></dynamic-vp></div>',
@ -1946,13 +1946,13 @@ class SimpleImperativeViewComponent {
@Injectable()
class DynamicViewport {
done: Promise<any>;
constructor(vc: ViewContainerRef, compiler: Compiler) {
constructor(vc: ViewContainerRef, compiler: ComponentResolver) {
var myService = new MyService();
myService.greeting = 'dynamic greet';
var bindings = Injector.resolve([provide(MyService, {useValue: myService})]);
this.done = compiler.compileInHost(ChildCompUsingService)
.then((hostPv) => {vc.createHostView(hostPv, 0, bindings)});
this.done = compiler.resolveComponent(ChildCompUsingService)
.then((compFactory) => {vc.createComponent(compFactory, 0, bindings)});
}
}

View File

@ -0,0 +1,47 @@
import {
ddescribe,
describe,
xdescribe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
AsyncTestCompleter,
inject,
beforeEachProviders
} from 'angular2/testing_internal';
import {provide} from 'angular2/core';
import {
ComponentResolver,
ReflectorComponentResolver
} from 'angular2/src/core/linker/component_resolver';
import {reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
import {ComponentFactory} from 'angular2/src/core/linker/component_factory';
export function main() {
describe('Compiler', () => {
var someCompFactory;
beforeEachProviders(() => [provide(ComponentResolver, {useClass: ReflectorComponentResolver})]);
beforeEach(inject([ComponentResolver], (_compiler) => {
someCompFactory = new ComponentFactory(null, null, null);
reflector.registerType(SomeComponent, new ReflectionInfo([someCompFactory]));
}));
it('should read the template from an annotation',
inject([AsyncTestCompleter, ComponentResolver], (async, compiler: ComponentResolver) => {
compiler.resolveComponent(SomeComponent)
.then((compFactory: ComponentFactory) => {
expect(compFactory).toBe(someCompFactory);
async.done();
return null;
});
}));
});
}
class SomeComponent {}

View File

@ -24,7 +24,7 @@ import {provide, Inject, Injector, PLATFORM_INITIALIZER, APP_INITIALIZER} from '
import {disposePlatform} from 'angular2/src/core/application_ref';
import {ExceptionHandler, BaseException} from 'angular2/src/facade/exceptions';
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
import {ComponentRef_, ComponentRef} from "angular2/src/core/linker/dynamic_component_loader";
import {ComponentRef} from "angular2/src/core/linker/component_factory";
@Component({selector: 'hello-app', template: '{{greeting}} world!'})
class HelloRootCmp {
@ -194,7 +194,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
bootstrap(HelloOnDestroyTickCmp, testProviders)
.then((ref) => {
expect(() => ref.dispose()).not.toThrow();
expect(() => ref.destroy()).not.toThrow();
async.done();
});
}));
@ -204,7 +204,7 @@ export function main() {
var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, testProviders]);
app.bootstrap(HelloRootCmp)
.then((ref) => {
ref.dispose();
ref.destroy();
expect(() => app.tick()).not.toThrow();
async.done();
});
@ -216,7 +216,7 @@ export function main() {
HelloRootCmp3, [testProviders, provide("appBinding", {useValue: "BoundValue"})]);
refPromise.then((ref) => {
expect(ref.hostComponent.appBinding).toEqual("BoundValue");
expect(ref.instance.appBinding).toEqual("BoundValue");
async.done();
});
}));
@ -226,7 +226,7 @@ export function main() {
var refPromise = bootstrap(HelloRootCmp4, testProviders);
refPromise.then((ref) => {
expect(ref.hostComponent.appRef).toBe((<ComponentRef_>ref).injector.get(ApplicationRef));
expect(ref.instance.appRef).toBe(ref.injector.get(ApplicationRef));
async.done();
});
}));

View File

@ -1,8 +1,8 @@
import 'package:angular2/testing_internal.dart' show SpyObject;
import 'package:angular2/core.dart' show Injector, bind;
import 'package:angular2/src/core/application_ref.dart' show ApplicationRef;
import 'package:angular2/src/core/linker/dynamic_component_loader.dart'
show ComponentRef_;
import 'package:angular2/src/core/linker/component_factory.dart'
show ComponentRef;
import 'dart:js';
@proxy
@ -11,7 +11,7 @@ class SpyApplicationRef extends SpyObject implements ApplicationRef {
}
@proxy
class SpyComponentRef extends SpyObject implements ComponentRef_ {
class SpyComponentRef extends SpyObject implements ComponentRef {
Injector injector;
SpyComponentRef() {

View File

@ -1,6 +1,5 @@
import {SpyObject} from 'angular2/testing_internal';
import {Injector, provide} from 'angular2/core';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {global} from 'angular2/src/facade/lang';
import {ApplicationRef, ApplicationRef_} from 'angular2/src/core/application_ref';

View File

@ -158,7 +158,7 @@ var NG_CORE = [
'ChangeDetectionStrategy',
'ChangeDetectorRef',
'Class:js',
'Compiler',
'ComponentResolver',
'Component',
'ComponentMetadata',
'ComponentRef',
@ -189,7 +189,7 @@ var NG_CORE = [
'HostListener',
'HostListenerMetadata',
'HostMetadata',
'HostViewFactoryRef',
'ComponentFactory',
'Inject',
'InjectMetadata',
'Injectable',
@ -270,7 +270,6 @@ var NG_CORE = [
'AfterViewChecked:dart',
'AfterViewInit:dart',
'DoCheck:dart',
'HostViewRef',
'IterableDifferFactory:dart',
'IterableDiffer:dart',
'KeyValueDifferFactory:dart',

View File

@ -69,10 +69,10 @@ export function main() {
provide(Console, {useClass: DummyConsole})
])
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('outer { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('');
expect(applicationRef.instance.location.path()).toEqual('');
async.done();
});
});

View File

@ -1,4 +1,4 @@
import {Component} from 'angular2/core';
import {Component, ComponentRef} from 'angular2/core';
import {
AsyncRoute,
Route,
@ -10,10 +10,7 @@ import {
} from 'angular2/router';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {isPresent} from 'angular2/src/facade/lang';
import {
DynamicComponentLoader,
ComponentRef
} from 'angular2/src/core/linker/dynamic_component_loader';
import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component_loader';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
@Component({selector: 'goodbye-cmp', template: `{{farewell}}`})
@ -152,7 +149,7 @@ export class DynamicLoaderCmp {
onSomeAction(): Promise<any> {
if (isPresent(this._componentRef)) {
this._componentRef.dispose();
this._componentRef.destroy();
this._componentRef = null;
}
return this._dynamicComponentLoader.loadIntoLocation(DynamicallyLoadedComponent,

View File

@ -58,10 +58,10 @@ export function main() {
it('should bootstrap an app with a hierarchy', inject([AsyncTestCompleter], (async) => {
bootstrap(HierarchyAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('root { parent { hello } }');
expect(applicationRef.hostComponent.location.path()).toEqual('/parent/child');
expect(applicationRef.instance.location.path()).toEqual('/parent/child');
async.done();
});
router.navigateByUrl('/parent/child');
@ -72,10 +72,10 @@ export function main() {
it('should work in an app with redirects', inject([AsyncTestCompleter], (async) => {
bootstrap(RedirectAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/after');
expect(applicationRef.instance.location.path()).toEqual('/after');
async.done();
});
router.navigateByUrl('/before');
@ -86,10 +86,10 @@ export function main() {
it('should work in an app with async components', inject([AsyncTestCompleter], (async) => {
bootstrap(AsyncAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
expect(applicationRef.instance.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
@ -100,10 +100,10 @@ export function main() {
it('should work in an app with aux routes', inject([AsyncTestCompleter], (async) => {
bootstrap(AuxAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello } aside { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello(aside)');
expect(applicationRef.instance.location.path()).toEqual('/hello(aside)');
async.done();
});
router.navigateByUrl('/hello(aside)');
@ -115,10 +115,10 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
bootstrap(ConciseAsyncAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
expect(applicationRef.instance.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');
@ -130,10 +130,10 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
bootstrap(ExplicitConstructorAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
var router = applicationRef.instance.router;
router.subscribe((_) => {
expect(el).toHaveText('root { hello }');
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
expect(applicationRef.instance.location.path()).toEqual('/hello');
async.done();
});
router.navigateByUrl('/hello');

View File

@ -6,7 +6,7 @@ import {ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
import {DateWrapper, Type, print, isPresent} from 'angular2/src/facade/lang';
import {
Compiler,
ComponentResolver,
Component,
Directive,
ViewContainerRef,
@ -40,7 +40,7 @@ export function main() {
BrowserDomAdapter.makeCurrent();
bootstrap(CompilerAppComponent, _createBindings())
.then((ref) => {
var app = ref.hostComponent;
var app = ref.instance;
bindAction('#compileNoBindings',
measureWrapper(() => app.compileNoBindings(), 'No Bindings'));
bindAction('#compileWithBindings',
@ -91,15 +91,15 @@ class MultiplyViewResolver extends ViewResolver {
@Component({selector: 'app', directives: [], template: ``})
class CompilerAppComponent {
constructor(private _compiler: Compiler) {}
constructor(private _compiler: ComponentResolver) {}
compileNoBindings() {
this._compiler.clearCache();
return this._compiler.compileInHost(BenchmarkComponentNoBindings);
return this._compiler.resolveComponent(BenchmarkComponentNoBindings);
}
compileWithBindings() {
this._compiler.clearCache();
return this._compiler.compileInHost(BenchmarkComponentWithBindings);
return this._compiler.resolveComponent(BenchmarkComponentWithBindings);
}
}

View File

@ -14,7 +14,7 @@ export function main() {
bootstrap(AppComponent)
.then((ref) => {
var injector = ref.injector;
var app: AppComponent = ref.hostComponent;
var app: AppComponent = ref.instance;
var appRef = injector.get(ApplicationRef);
bindAction('#reset', function() {

View File

@ -113,7 +113,7 @@ export function main() {
bootstrap(AppComponent, _createBindings())
.then((ref) => {
var injector = ref.injector;
app = ref.hostComponent;
app = ref.instance;
appRef = injector.get(ApplicationRef);
bindAction('#ng2DestroyDom', ng2DestroyDom);
bindAction('#ng2CreateDom', ng2CreateDom);

View File

@ -1,15 +1,6 @@
import {bootstrap} from 'angular2/platform/browser';
import {NgIf} from 'angular2/common';
import {
Compiler,
Component,
Directive,
ViewContainerRef,
bind,
provide,
Provider
} from 'angular2/core';
import {ComponentRef_} from 'angular2/src/core/linker/dynamic_component_loader';
import {Component, Directive, ViewContainerRef, bind, provide, Provider} from 'angular2/core';
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {reflector} from 'angular2/src/core/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
@ -94,10 +85,10 @@ export function main() {
function initNg2() {
bootstrap(AppComponentWithStaticTree, createBindings())
.then((ref) => {
var injector = (<ComponentRef_>ref).injector;
var injector = ref.injector;
appRef = injector.get(ApplicationRef);
app = (<ComponentRef_>ref).hostComponent;
app = ref.instance;
bindAction('#ng2DestroyDom', ng2DestroyDom);
bindAction('#ng2CreateDom', ng2CreateDom);
bindAction('#ng2UpdateDomProfile', profile(ng2CreateDom, noop, 'ng2-update'));

View File

@ -1,6 +1,5 @@
import {bootstrap} from 'angular2/platform/browser';
import {
Compiler,
Component,
Directive,
ViewContainerRef,
@ -96,7 +95,7 @@ export function main() {
var injector = ref.injector;
appRef = injector.get(ApplicationRef);
app = ref.hostComponent;
app = ref.instance;
bindAction('#ng2DestroyDom', ng2DestroyDom);
bindAction('#ng2CreateDom', ng2CreateDom);
bindAction('#ng2UpdateDomProfile', profile(ng2CreateDom, noop, 'ng2-update'));

View File

@ -66,7 +66,7 @@ Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
for (var reflectable in viewDefResults.viewDefinitions.keys) {
// TODO(kegluneq): Avoid duplicating naming logic for generated classes.
reflectable.annotations.add(new AnnotationModel()
..name = 'hostViewFactory_${reflectable.name}'
..name = '${reflectable.name}NgFactory'
..isConstObject = true);
}
}

View File

@ -13,7 +13,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
}

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -15,7 +15,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [
const [MyContext]
], (MyContext c) => new MyComponent(c)));
i0.initReflector();

View File

@ -13,7 +13,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
}

View File

@ -13,7 +13,7 @@ void initReflector() {
_ngRef.reflector
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(const [hostViewFactory_MyComponent], const [],
new _ngRef.ReflectionInfo(const [MyComponentNgFactory], const [],
() => new MyComponent()));
i0.initReflector();
}

View File

@ -16,7 +16,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Annotation1(prop1: 'value1'),
const Annotation2(prop2: 'value2'),
hostViewFactory_MyComponent
MyComponentNgFactory
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -16,7 +16,7 @@ void initReflector() {
..registerType(
MyComponent,
new _ngRef.ReflectionInfo(
const [hostViewFactory_MyComponent],
const [MyComponentNgFactory],
const [
const [prefix.MyContext],
const [prefix.MyDep]

View File

@ -114,7 +114,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))
..toContain('$CONTEXT_ACCESSOR.greeting')
@ -132,7 +132,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))..toContain('$CONTEXT_ACCESSOR.action()');
});
@ -158,7 +158,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))
@ -188,7 +188,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))
@ -216,7 +216,7 @@ void allTests() {
expect(ngDeps).toBeNotNull();
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = 'hostViewFactory_FooComponent'
..name = 'FooComponentNgFactory'
..isConstObject = true);
expect(_generatedCode(outputs))

View File

@ -29,10 +29,6 @@ const CORE = [
'AfterViewInit',
'AfterViewInit.ngAfterViewInit():any',
'AppViewManager',
'AppViewManager.createRootHostView(hostViewFactoryRef:HostViewFactoryRef, overrideSelector:string, injector:Injector, projectableNodes:any[][]):HostViewRef',
'AppViewManager.destroyRootHostView(hostViewRef:HostViewRef):any',
'AppViewManager.getComponent(hostLocation:ElementRef):any',
'AppViewManager.getHostElement(hostViewRef:HostViewRef):ElementRef',
'AppViewManager.getNamedElementInComponentView(hostLocation:ElementRef, variableName:string):ElementRef',
'AppViewManager.getViewContainer(location:ElementRef):ViewContainerRef',
'ApplicationRef',
@ -44,7 +40,7 @@ const CORE = [
'ApplicationRef.registerDisposeListener(dispose:() => void):void',
'ApplicationRef.tick():void',
'ApplicationRef.zone:NgZone',
'AttributeFactory',
'AttributeMetadataFactory',
'AttributeMetadata',
'AttributeMetadata.constructor(attributeName:string)',
'AttributeMetadata.toString():string',
@ -77,12 +73,12 @@ const CORE = [
'CollectionChangeRecord.currentIndex:number',
'CollectionChangeRecord.previousIndex:number',
'CollectionChangeRecord.toString():string',
'Compiler',
'Compiler.clearCache():any',
'Compiler.compileInHost(componentType:Type):Promise<HostViewFactoryRef>',
'ComponentResolver',
'ComponentResolver.clearCache():any',
'ComponentResolver.resolveComponent(componentType:Type):Promise<ComponentFactory>',
'ComponentDecorator',
'ComponentDecorator.View(obj:{templateUrl?:string, template?:string, directives?:Array<Type|any[]>, pipes?:Array<Type|any[]>, renderer?:string, styles?:string[], styleUrls?:string[]}):ViewDecorator',
'ComponentFactory',
'ComponentMetadataFactory',
'ComponentMetadata',
'ComponentMetadata.changeDetection:ChangeDetectionStrategy',
'ComponentMetadata.constructor({selector,inputs,outputs,properties,events,host,exportAs,moduleId,bindings,providers,viewBindings,viewProviders,changeDetection=ChangeDetectionStrategy.Default,queries,templateUrl,template,styleUrls,styles,directives,pipes,encapsulation}:{selector?:string, inputs?:string[], outputs?:string[], properties?:string[], events?:string[], host?:{[key:string]:string}, bindings?:any[], providers?:any[], exportAs?:string, moduleId?:string, viewBindings?:any[], viewProviders?:any[], queries?:{[key:string]:any}, changeDetection?:ChangeDetectionStrategy, templateUrl?:string, template?:string, styleUrls?:string[], styles?:string[], directives?:Array<Type|any[]>, pipes?:Array<Type|any[]>, encapsulation?:ViewEncapsulation})',
@ -98,17 +94,18 @@ const CORE = [
'ComponentMetadata.viewProviders:any[]',
'ComponentRef',
'ComponentRef.componentType:Type',
'ComponentRef.dispose():void',
'ComponentRef.hostComponent:any',
'ComponentRef.hostView:HostViewRef',
'ComponentRef.injector:Injector',
'ComponentRef.instance:any',
'ComponentRef.location:ElementRef',
'ComponentRef.destroy():void',
'ComponentRef.hostView:ViewRef',
'ComponentRef.onDestroy(callback:Function):void',
'ComponentRef.changeDetectorRef:ChangeDetectorRef',
'ConcreteType',
'ContentChildFactory',
'ContentChildMetadataFactory',
'ContentChildMetadata',
'ContentChildMetadata.constructor(_selector:Type|string)',
'ContentChildrenFactory',
'ContentChildrenMetadataFactory',
'ContentChildrenMetadata',
'ContentChildrenMetadata.constructor(_selector:Type|string, {descendants=false}:{descendants?:boolean})',
'CyclicDependencyError',
@ -147,7 +144,7 @@ const CORE = [
'DependencyMetadata',
'DependencyMetadata.token:any',
'DirectiveDecorator',
'DirectiveFactory',
'DirectiveMetadataFactory',
'DirectiveMetadata',
'DirectiveMetadata.bindings:any[]',
'DirectiveMetadata.constructor({selector,inputs,outputs,properties,events,host,bindings,providers,exportAs,queries}:{selector?:string, inputs?:string[], outputs?:string[], properties?:string[], events?:string[], host?:{[key:string]:string}, providers?:any[], bindings?:any[], exportAs?:string, queries?:{[key:string]:any}})',
@ -163,7 +160,7 @@ const CORE = [
'DoCheck',
'DoCheck.ngDoCheck():any',
'DynamicComponentLoader',
'DynamicComponentLoader.loadAsRoot(type:Type, overrideSelector:string, injector:Injector, onDispose:() => void, projectableNodes:any[][]):Promise<ComponentRef>',
'DynamicComponentLoader.loadAsRoot(type:Type, overrideSelectorOrNode:string, injector:Injector, onDispose:() => void, projectableNodes:any[][]):Promise<ComponentRef>',
'DynamicComponentLoader.loadIntoLocation(type:Type, hostLocation:ElementRef, anchorName:string, providers:ResolvedProvider[], projectableNodes:any[][]):Promise<ComponentRef>',
'DynamicComponentLoader.loadNextToLocation(type:Type, location:ElementRef, providers:ResolvedProvider[], projectableNodes:any[][]):Promise<ComponentRef>',
'ElementRef',
@ -172,6 +169,7 @@ const CORE = [
'EmbeddedViewRef.hasLocal(variableName:string):boolean',
'EmbeddedViewRef.rootNodes:any[]',
'EmbeddedViewRef.setLocal(variableName:string, value:any):void',
'EmbeddedViewRef.destroy():any',
'EventEmitter.constructor(isAsync:boolean)',
'EventEmitter.emit(value:T):any',
'EventEmitter.next(value:any):any',
@ -187,23 +185,24 @@ const CORE = [
'GetTestability',
'GetTestability.addToWindow(registry:TestabilityRegistry):void',
'GetTestability.findTestabilityInTree(registry:TestabilityRegistry, elem:any, findInAncestors:boolean):Testability',
'HostBindingFactory',
'HostBindingMetadataFactory',
'HostBindingMetadata',
'HostBindingMetadata.constructor(hostPropertyName:string)',
'HostFactory',
'HostListenerFactory',
'HostMetadataFactory',
'HostListenerMetadataFactory',
'HostListenerMetadata',
'HostListenerMetadata.constructor(eventName:string, args:string[])',
'HostMetadata',
'HostMetadata.toString():string',
'HostViewFactoryRef',
'HostViewRef',
'HostViewRef.rootNodes:any[]',
'InjectFactory',
'ComponentFactory',
'ComponentFactory.componentType:Type',
'ComponentFactory.constructor(selector:string, _viewFactory:Function, _componentType:Type)',
'ComponentFactory.create(injector:Injector, projectableNodes:any[][], rootSelectorOrNode:string|any):ComponentRef',
'InjectMetadataFactory',
'InjectMetadata',
'InjectMetadata.constructor(token:any)',
'InjectMetadata.toString():string',
'InjectableFactory',
'InjectableMetadataFactory',
'InjectableMetadata',
'InjectableMetadata.constructor()',
'Injector',
@ -219,7 +218,7 @@ const CORE = [
'Injector.resolveAndCreate(providers:Array<Type|Provider|any[]>):Injector',
'Injector.resolveAndCreateChild(providers:Array<Type|Provider|any[]>):Injector',
'Injector.resolveAndInstantiate(provider:Type|Provider):any',
'InputFactory',
'InputMetadataFactory',
'InputMetadata',
'InputMetadata.constructor(bindingPropertyName:string)',
'InstantiationError',
@ -292,15 +291,15 @@ const CORE = [
'OpaqueToken',
'OpaqueToken.constructor(_desc:string)',
'OpaqueToken.toString():string',
'OptionalFactory',
'OptionalMetadataFactory',
'OptionalMetadata',
'OptionalMetadata.toString():string',
'OutOfBoundsError',
'OutOfBoundsError.constructor(index:any)',
'OutputFactory',
'OutputMetadataFactory',
'OutputMetadata',
'OutputMetadata.constructor(bindingPropertyName:string)',
'PipeFactory',
'PipeMetadataFactory',
'PipeMetadata',
'PipeMetadata.constructor({name,pure}:{name:string, pure?:boolean})',
'PipeMetadata.name:string',
@ -328,7 +327,7 @@ const CORE = [
'ProviderBuilder.toClass(type:Type):Provider',
'ProviderBuilder.toFactory(factory:Function, dependencies:any[]):Provider',
'ProviderBuilder.toValue(value:any):Provider',
'QueryFactory',
'QueryMetadataFactory',
'QueryList.changes:Observable<any>',
'QueryList.dirty:any',
'QueryList.filter(fn:(item: T) => boolean):T[]',
@ -389,7 +388,7 @@ const CORE = [
'Renderer.listen(renderElement:any, name:string, callback:Function):Function',
'Renderer.listenGlobal(target:string, name:string, callback:Function):Function',
'Renderer.projectNodes(parentElement:any, nodes:any[]):void',
'Renderer.selectRootElement(selector:string, debugInfo:RenderDebugInfo):any',
'Renderer.selectRootElement(selectorOrNode:string|any, debugInfo:RenderDebugInfo):any',
'Renderer.setBindingDebugInfo(renderElement:any, propertyName:string, propertyValue:string):void',
'Renderer.setElementAttribute(renderElement:any, attributeName:string, attributeValue:string):void',
'Renderer.setElementClass(renderElement:any, className:string, isAdd:boolean):any',
@ -405,17 +404,18 @@ const CORE = [
'ResolvedProvider.resolvedFactories:ResolvedFactory[]',
'RootRenderer',
'RootRenderer.renderComponent(componentType:RenderComponentType):Renderer',
'SelfFactory',
'SelfMetadataFactory',
'SelfMetadata',
'SelfMetadata.toString():string',
'SimpleChange',
'SimpleChange.constructor(previousValue:any, currentValue:any)',
'SimpleChange.isFirstChange():boolean',
'SkipSelfFactory',
'SkipSelfMetadataFactory',
'SkipSelfMetadata',
'SkipSelfMetadata.toString():string',
'TemplateRef',
'TemplateRef.elementRef:ElementRef',
'TemplateRef.createEmbeddedView():EmbeddedViewRef',
'Testability',
'Testability.constructor(_ngZone:NgZone)',
'Testability.decreasePendingRequestCount():number',
@ -436,16 +436,16 @@ const CORE = [
'TypeDecorator',
'TypeDecorator.Class(obj:ClassDefinition):ConcreteType',
'TypeDecorator.annotations:any[]',
'ViewChildFactory',
'ViewChildMetadataFactory',
'ViewChildMetadata',
'ViewChildMetadata.constructor(_selector:Type|string)',
'ViewChildrenFactory',
'ViewChildrenMetadataFactory',
'ViewChildrenMetadata',
'ViewChildrenMetadata.constructor(_selector:Type|string)',
'ViewContainerRef',
'ViewContainerRef.clear():void',
'ViewContainerRef.createEmbeddedView(templateRef:TemplateRef, index:number):EmbeddedViewRef',
'ViewContainerRef.createHostView(hostViewFactoryRef:HostViewFactoryRef, index:number, dynamicallyCreatedProviders:ResolvedProvider[], projectableNodes:any[][]):HostViewRef',
'ViewContainerRef.createComponent(componentFactory:ComponentFactory, index:number, dynamicallyCreatedProviders:ResolvedProvider[], projectableNodes:any[][]):ComponentRef',
'ViewContainerRef.detach(index:number):ViewRef',
'ViewContainerRef.element:ElementRef',
'ViewContainerRef.get(index:number):ViewRef',
@ -459,7 +459,7 @@ const CORE = [
'ViewEncapsulation.Emulated',
'ViewEncapsulation.Native',
'ViewEncapsulation.None',
'ViewFactory',
'ViewMetadataFactory',
'ViewMetadata',
'ViewMetadata.constructor({templateUrl,template,directives,pipes,encapsulation,styles,styleUrls}:{templateUrl?:string, template?:string, directives?:Array<Type|any[]>, pipes?:Array<Type|any[]>, encapsulation?:ViewEncapsulation, styles?:string[], styleUrls?:string[]})',
'ViewMetadata.directives:Array<Type|any[]>',
@ -476,6 +476,7 @@ const CORE = [
'ViewRef',
'ViewRef.changeDetectorRef:ChangeDetectorRef',
'ViewRef.destroyed:boolean',
'ViewRef.onDestroy(callback:Function):any',
'WrappedException',
'WrappedException.constructor(_wrapperMessage:string, _originalException:any, _originalStack:any, _context:any)',
'WrappedException.context:any',
@ -505,27 +506,27 @@ const CORE = [
'provide(token:any, {useClass,useValue,useExisting,useFactory,deps,multi}:{useClass?:Type, useValue?:any, useExisting?:any, useFactory?:Function, deps?:Object[], multi?:boolean}):Provider',
'resolveForwardRef(type:any):any',
'setTestabilityGetter(getter:GetTestability):void',
'var Attribute:AttributeFactory',
'var Component:ComponentFactory',
'var ContentChild:ContentChildFactory',
'var ContentChildren:ContentChildrenFactory',
'var Directive:DirectiveFactory',
'var Host:HostFactory',
'var HostBinding:HostBindingFactory',
'var HostListener:HostListenerFactory',
'var Inject:InjectFactory',
'var Injectable:InjectableFactory',
'var Input:InputFactory',
'var Optional:OptionalFactory',
'var Output:OutputFactory',
'var Pipe:PipeFactory',
'var Query:QueryFactory',
'var Self:SelfFactory',
'var SkipSelf:SkipSelfFactory',
'var Attribute:AttributeMetadataFactory',
'var Component:ComponentMetadataFactory',
'var ContentChild:ContentChildMetadataFactory',
'var ContentChildren:ContentChildrenMetadataFactory',
'var Directive:DirectiveMetadataFactory',
'var Host:HostMetadataFactory',
'var HostBinding:HostBindingMetadataFactory',
'var HostListener:HostListenerMetadataFactory',
'var Inject:InjectMetadataFactory',
'var Injectable:InjectableMetadataFactory',
'var Input:InputMetadataFactory',
'var Optional:OptionalMetadataFactory',
'var Output:OutputMetadataFactory',
'var Pipe:PipeMetadataFactory',
'var Query:QueryMetadataFactory',
'var Self:SelfMetadataFactory',
'var SkipSelf:SkipSelfMetadataFactory',
'var Type:any',
'var ViewChild:ViewChildFactory',
'var ViewChildren:ViewChildrenFactory',
'var ViewQuery:QueryFactory',
'var ViewChild:ViewChildMetadataFactory',
'var ViewChildren:ViewChildrenMetadataFactory',
'var ViewQuery:QueryMetadataFactory',
'var reflector:any'
];