@@ -6,10 +6,11 @@ import {Injector, Key, Dependency, bind, Binding, ResolvedBinding, NoBindingErro
66 AbstractBindingError , CyclicDependencyError } from 'angular2/di' ;
77import { Parent , Ancestor } from 'angular2/src/core/annotations/visibility' ;
88import { Attribute , Query } from 'angular2/src/core/annotations/di' ;
9- import * as viewModule from 'angular2/src/core/compiler /view' ;
9+ import * as viewModule from '. /view' ;
1010import * as avmModule from './view_manager' ;
11- import { ViewContainerRef } from 'angular2/src/core/compiler/view_container_ref' ;
12- import { NgElement } from 'angular2/src/core/compiler/ng_element' ;
11+ import { ViewContainerRef } from './view_container_ref' ;
12+ import { ElementRef } from './element_ref' ;
13+ import { ProtoViewRef , ViewRef } from './view_ref' ;
1314import { Directive , Component , onChange , onDestroy , onAllChangesDone } from 'angular2/src/core/annotations/annotations' ;
1415import { ChangeDetector , ChangeDetectorRef } from 'angular2/change_detection' ;
1516import { QueryList } from './query_list' ;
@@ -23,40 +24,17 @@ var _undefined = new Object();
2324
2425var _staticKeys ;
2526
26- /**
27- * @exportedAs angular2/view
28- */
29- export class ElementRef {
30- hostView :viewModule . AppView ;
31- boundElementIndex:number ;
32- injector:Injector ;
33- elementInjector:ElementInjector ;
34- viewContainer:ViewContainerRef ;
35-
36- constructor ( elementInjector , hostView , boundElementIndex , injector , viewManager , defaultProtoView ) {
37- this . elementInjector = elementInjector ;
38- this . hostView = hostView ;
39- this . boundElementIndex = boundElementIndex ;
40- this . injector = injector ;
41- this . viewContainer = new ViewContainerRef ( viewManager , this , defaultProtoView ) ;
42- }
43- }
44-
4527class StaticKeys {
4628 viewManagerId :number ;
47- viewId :number ;
48- ngElementId :number ;
49- defaultProtoViewId :number ;
29+ protoViewId :number ;
5030 viewContainerId :number ;
5131 changeDetectorRefId :number ;
5232 elementRefId :number ;
5333
5434 constructor ( ) {
5535 //TODO: vsavkin Key.annotate(Key.get(AppView), 'static')
5636 this . viewManagerId = Key . get ( avmModule . AppViewManager ) . id ;
57- this . defaultProtoViewId = Key . get ( viewModule . AppProtoView ) . id ;
58- this . viewId = Key . get ( viewModule . AppView ) . id ;
59- this . ngElementId = Key . get ( NgElement ) . id ;
37+ this . protoViewId = Key . get ( ProtoViewRef ) . id ;
6038 this . viewContainerId = Key . get ( ViewContainerRef ) . id ;
6139 this . changeDetectorRefId = Key . get ( ChangeDetectorRef ) . id ;
6240 this . elementRefId = Key . get ( ElementRef ) . id ;
@@ -294,14 +272,12 @@ export class DirectiveBinding extends ResolvedBinding {
294272// TODO(rado): benchmark and consider rolling in as ElementInjector fields.
295273export class PreBuiltObjects {
296274 viewManager :avmModule . AppViewManager ;
297- defaultProtoView :viewModule . AppProtoView ;
275+ protoView :viewModule . AppProtoView ;
298276 view:viewModule . AppView ;
299- element:NgElement ;
300- constructor ( viewManager :avmModule . AppViewManager , view :viewModule . AppView , element :NgElement , defaultProtoView :viewModule . AppProtoView ) {
277+ constructor ( viewManager :avmModule . AppViewManager , view :viewModule . AppView , protoView :viewModule . AppProtoView ) {
301278 this . viewManager = viewManager ;
302279 this . view = view ;
303- this . defaultProtoView = defaultProtoView ;
304- this . element = element ;
280+ this . protoView = protoView ;
305281 }
306282}
307283
@@ -649,11 +625,6 @@ export class ElementInjector extends TreeNode {
649625 return this . _proto . eventEmitterAccessors ;
650626 }
651627
652- /** Gets the NgElement associated with this ElementInjector */
653- getNgElement ( ) {
654- return this . _preBuiltObjects . element ;
655- }
656-
657628 getComponent ( ) {
658629 if ( this . _proto . _binding0IsComponent ) {
659630 return this . _obj0 ;
@@ -663,8 +634,11 @@ export class ElementInjector extends TreeNode {
663634 }
664635
665636 getElementRef ( ) {
666- return new ElementRef ( this , this . _preBuiltObjects . view , this . _proto . index , this . _lightDomAppInjector ,
667- this . _preBuiltObjects . viewManager , this . _preBuiltObjects . defaultProtoView ) ;
637+ return new ElementRef ( new ViewRef ( this . _preBuiltObjects . view ) , this . _proto . index ) ;
638+ }
639+
640+ getViewContainerRef ( ) {
641+ return new ViewContainerRef ( this . _preBuiltObjects . viewManager , this . getElementRef ( ) , new ProtoViewRef ( this . _preBuiltObjects . protoView ) ) ;
668642 }
669643
670644 getDynamicallyLoadedComponent ( ) {
@@ -742,7 +716,10 @@ export class ElementInjector extends TreeNode {
742716 return this . getElementRef ( ) ;
743717 }
744718 if ( dep . key . id === StaticKeys . instance ( ) . viewContainerId ) {
745- return this . getElementRef ( ) . viewContainer ;
719+ return this . getViewContainerRef ( ) ;
720+ }
721+ if ( dep . key . id === StaticKeys . instance ( ) . protoViewId ) {
722+ return new ProtoViewRef ( this . _preBuiltObjects . protoView ) ;
746723 }
747724 return this . _getByKey ( dep . key , dep . depth , dep . optional , requestor ) ;
748725 }
@@ -914,11 +891,7 @@ export class ElementInjector extends TreeNode {
914891
915892 _getPreBuiltObjectByKeyId ( keyId :int ) {
916893 var staticKeys = StaticKeys . instance ( ) ;
917- // TODO: AppView should not be injectable. Remove it.
918894 if ( keyId === staticKeys . viewManagerId ) return this . _preBuiltObjects . viewManagerId ;
919- if ( keyId === staticKeys . viewId ) return this . _preBuiltObjects . view ;
920- if ( keyId === staticKeys . ngElementId ) return this . _preBuiltObjects . element ;
921- if ( keyId === staticKeys . defaultProtoViewId ) return this . _preBuiltObjects . defaultProtoView ;
922895
923896 //TODO add other objects as needed
924897 return _undefined ;
0 commit comments