cleanup(view): changed ComponentRef to contain ElementRef instead of extending it
This commit is contained in:
parent
b5c9f9ed9b
commit
8b97cf1479
2
modules/angular2/core.js
vendored
2
modules/angular2/core.js
vendored
@ -16,7 +16,7 @@ export * from './src/core/compiler/compiler';
|
|||||||
// TODO(tbosch): remove this once render migration is complete
|
// TODO(tbosch): remove this once render migration is complete
|
||||||
export * from 'angular2/src/render/dom/compiler/template_loader';
|
export * from 'angular2/src/render/dom/compiler/template_loader';
|
||||||
export * from './src/core/compiler/dynamic_component_loader';
|
export * from './src/core/compiler/dynamic_component_loader';
|
||||||
export {ElementRef, DirectiveRef, ComponetRef} from './src/core/compiler/element_injector';
|
export {ElementRef, ComponetRef} from './src/core/compiler/element_injector';
|
||||||
export * from './src/core/compiler/view';
|
export * from './src/core/compiler/view';
|
||||||
export * from './src/core/compiler/view_container';
|
export * from './src/core/compiler/view_container';
|
||||||
|
|
||||||
|
3
modules/angular2/src/core/application.js
vendored
3
modules/angular2/src/core/application.js
vendored
@ -25,14 +25,13 @@ import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mappe
|
|||||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||||
import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver';
|
import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver';
|
||||||
import {StyleInliner} from 'angular2/src/render/dom/shadow_dom/style_inliner';
|
import {StyleInliner} from 'angular2/src/render/dom/shadow_dom/style_inliner';
|
||||||
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
import {ComponentRef, DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||||
import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability';
|
import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability';
|
||||||
import {ViewFactory, VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_factory';
|
import {ViewFactory, VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_factory';
|
||||||
import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
|
import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
|
||||||
import {Renderer} from 'angular2/src/render/api';
|
import {Renderer} from 'angular2/src/render/api';
|
||||||
import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer';
|
import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer';
|
||||||
import * as rc from 'angular2/src/render/dom/compiler/compiler';
|
import * as rc from 'angular2/src/render/dom/compiler/compiler';
|
||||||
import {ComponentRef} from 'angular2/src/core/compiler/element_injector';
|
|
||||||
import * as rvf from 'angular2/src/render/dom/view/view_factory';
|
import * as rvf from 'angular2/src/render/dom/view/view_factory';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -7,7 +7,29 @@ import {Promise} from 'angular2/src/facade/async';
|
|||||||
import {Component} from 'angular2/src/core/annotations/annotations';
|
import {Component} from 'angular2/src/core/annotations/annotations';
|
||||||
import {ViewFactory} from 'angular2/src/core/compiler/view_factory';
|
import {ViewFactory} from 'angular2/src/core/compiler/view_factory';
|
||||||
import {Renderer} from 'angular2/src/render/api';
|
import {Renderer} from 'angular2/src/render/api';
|
||||||
import {ElementRef, DirectiveRef, ComponentRef} from './element_injector';
|
import {ElementRef} from './element_injector';
|
||||||
|
import {AppView} from './view';
|
||||||
|
|
||||||
|
|
||||||
|
export class ComponentRef {
|
||||||
|
location:ElementRef;
|
||||||
|
instance:any;
|
||||||
|
componentView:AppView;
|
||||||
|
|
||||||
|
constructor(location:ElementRef, instance:any, componentView:AppView){
|
||||||
|
this.location = location;
|
||||||
|
this.instance = instance;
|
||||||
|
this.componentView = componentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
get injector() {
|
||||||
|
return this.location.injector;
|
||||||
|
}
|
||||||
|
|
||||||
|
get hostView() {
|
||||||
|
return this.location.hostView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for dynamically loading a Component into an arbitrary position in the internal Angular
|
* Service for dynamically loading a Component into an arbitrary position in the internal Angular
|
||||||
@ -43,8 +65,8 @@ export class DynamicComponentLoader {
|
|||||||
var hostView = location.hostView;
|
var hostView = location.hostView;
|
||||||
|
|
||||||
return this._compiler.compile(type).then(componentProtoView => {
|
return this._compiler.compile(type).then(componentProtoView => {
|
||||||
var context = hostEi.dynamicallyCreateComponent(type, directiveMetadata.annotation, inj);
|
var component = hostEi.dynamicallyCreateComponent(type, directiveMetadata.annotation, inj);
|
||||||
var componentView = this._instantiateAndHydrateView(componentProtoView, injector, hostEi, context);
|
var componentView = this._instantiateAndHydrateView(componentProtoView, injector, hostEi, component);
|
||||||
|
|
||||||
//TODO(vsavkin): do not use component child views as we need to clear the dynamically created views
|
//TODO(vsavkin): do not use component child views as we need to clear the dynamically created views
|
||||||
//same problem exists on the render side
|
//same problem exists on the render side
|
||||||
@ -54,7 +76,7 @@ export class DynamicComponentLoader {
|
|||||||
|
|
||||||
// TODO(vsavkin): return a component ref that dehydrates the component view and removes it
|
// TODO(vsavkin): return a component ref that dehydrates the component view and removes it
|
||||||
// from the component child views
|
// from the component child views
|
||||||
return new ComponentRef(Key.get(type), hostEi, componentView);
|
return new ComponentRef(location, component, componentView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +97,9 @@ export class DynamicComponentLoader {
|
|||||||
var hostView = this._instantiateAndHydrateView(pv, inj, null, new Object());
|
var hostView = this._instantiateAndHydrateView(pv, inj, null, new Object());
|
||||||
|
|
||||||
// TODO(vsavkin): return a component ref that dehydrates the host view
|
// TODO(vsavkin): return a component ref that dehydrates the host view
|
||||||
return new ComponentRef(Key.get(type), hostView.elementInjectors[0], hostView.componentChildViews[0]);
|
var newLocation = new ElementRef(hostView.elementInjectors[0]);
|
||||||
|
var component = hostView.elementInjectors[0].getComponent();
|
||||||
|
return new ComponentRef(newLocation, component, hostView.componentChildViews[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,34 +39,12 @@ export class ElementRef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DirectiveRef extends ElementRef {
|
|
||||||
_key:Key;
|
|
||||||
|
|
||||||
constructor(key:Key, elementInjector:ElementInjector){
|
|
||||||
super(elementInjector);
|
|
||||||
this._key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
get instance() {
|
|
||||||
return this.elementInjector.get(this._key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ComponentRef extends DirectiveRef {
|
|
||||||
componentView:viewModule.AppView;
|
|
||||||
|
|
||||||
constructor(key:Key, elementInjector:ElementInjector, componentView:viewModule.AppView){
|
|
||||||
super(key, elementInjector);
|
|
||||||
this.componentView = componentView;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class StaticKeys {
|
class StaticKeys {
|
||||||
viewId:number;
|
viewId:number;
|
||||||
ngElementId:number;
|
ngElementId:number;
|
||||||
viewContainerId:number;
|
viewContainerId:number;
|
||||||
bindingPropagationConfigId:number;
|
bindingPropagationConfigId:number;
|
||||||
directiveRefId:number;
|
elementRefId:number;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
//TODO: vsavkin Key.annotate(Key.get(AppView), 'static')
|
//TODO: vsavkin Key.annotate(Key.get(AppView), 'static')
|
||||||
@ -74,7 +52,7 @@ class StaticKeys {
|
|||||||
this.ngElementId = Key.get(NgElement).id;
|
this.ngElementId = Key.get(NgElement).id;
|
||||||
this.viewContainerId = Key.get(ViewContainer).id;
|
this.viewContainerId = Key.get(ViewContainer).id;
|
||||||
this.bindingPropagationConfigId = Key.get(BindingPropagationConfig).id;
|
this.bindingPropagationConfigId = Key.get(BindingPropagationConfig).id;
|
||||||
this.directiveRefId = Key.get(DirectiveRef).id;
|
this.elementRefId = Key.get(ElementRef).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static instance() {
|
static instance() {
|
||||||
@ -699,9 +677,8 @@ export class ElementInjector extends TreeNode {
|
|||||||
if (isPresent(dep.propSetterName)) return this._buildPropSetter(dep);
|
if (isPresent(dep.propSetterName)) return this._buildPropSetter(dep);
|
||||||
if (isPresent(dep.attributeName)) return this._buildAttribute(dep);
|
if (isPresent(dep.attributeName)) return this._buildAttribute(dep);
|
||||||
if (isPresent(dep.queryDirective)) return this._findQuery(dep.queryDirective).list;
|
if (isPresent(dep.queryDirective)) return this._findQuery(dep.queryDirective).list;
|
||||||
if (dep.key.id === StaticKeys.instance().directiveRefId) {
|
if (dep.key.id === StaticKeys.instance().elementRefId) {
|
||||||
// TODO: we need store component view here and pass it to directive ref
|
return new ElementRef(this);
|
||||||
return new DirectiveRef(requestor, this);
|
|
||||||
}
|
}
|
||||||
return this._getByKey(dep.key, dep.depth, dep.optional, requestor);
|
return this._getByKey(dep.key, dep.depth, dep.optional, requestor);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/test_lib';
|
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/test_lib';
|
||||||
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
||||||
import {DynamicComponentLoader, DirectiveRef} from 'angular2/src/core/compiler/dynamic_component_loader';
|
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||||
import {Decorator, Viewport} from 'angular2/src/core/annotations/annotations';
|
import {Decorator, Viewport} from 'angular2/src/core/annotations/annotations';
|
||||||
|
|
||||||
@Decorator({selector: 'someDecorator'})
|
@Decorator({selector: 'someDecorator'})
|
||||||
|
@ -29,7 +29,7 @@ import {View} from 'angular2/src/core/annotations/view';
|
|||||||
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
||||||
import {EventEmitter, Attribute} from 'angular2/src/core/annotations/di';
|
import {EventEmitter, Attribute} from 'angular2/src/core/annotations/di';
|
||||||
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||||
import {DirectiveRef} from 'angular2/src/core/compiler/element_injector';
|
import {ElementRef} from 'angular2/src/core/compiler/element_injector';
|
||||||
|
|
||||||
import {If} from 'angular2/src/directives/if';
|
import {If} from 'angular2/src/directives/if';
|
||||||
|
|
||||||
@ -726,8 +726,8 @@ class DynamicallyCreatedComponentService {
|
|||||||
})
|
})
|
||||||
class DynamicComp {
|
class DynamicComp {
|
||||||
done;
|
done;
|
||||||
constructor(loader:DynamicComponentLoader, self:DirectiveRef) {
|
constructor(loader:DynamicComponentLoader, location:ElementRef) {
|
||||||
this.done = loader.loadIntoExistingLocation(DynamicallyCreatedCmp, self);
|
this.done = loader.loadIntoExistingLocation(DynamicallyCreatedCmp, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user