@@ -62,33 +62,46 @@ export class AppViewManager {
6262 return new ViewRef ( componentView ) ;
6363 }
6464
65- createInPlaceHostView ( parentComponentLocation :ElementRef ,
66- hostElementSelector :string , hostProtoViewRef :ProtoViewRef , injector :Injector ) :ViewRef {
65+ createRootHostView ( hostProtoViewRef :ProtoViewRef , overrideSelector :string , injector :Injector ) :ViewRef {
6766 var hostProtoView = internalProtoView ( hostProtoViewRef ) ;
68- var parentComponentHostView = null ;
69- var parentComponentBoundElementIndex = null ;
70- var parentRenderViewRef = null ;
71- if ( isPresent ( parentComponentLocation ) ) {
72- parentComponentHostView = internalView ( parentComponentLocation . parentView ) ;
73- parentComponentBoundElementIndex = parentComponentLocation . boundElementIndex ;
74- parentRenderViewRef = parentComponentHostView . componentChildViews [ parentComponentBoundElementIndex ] . render ;
67+ var hostElementSelector = overrideSelector ;
68+ if ( isBlank ( hostElementSelector ) ) {
69+ hostElementSelector = hostProtoView . elementBinders [ 0 ] . componentDirective . metadata . selector ;
7570 }
76- var hostRenderView = this . _renderer . createInPlaceHostView ( parentRenderViewRef , hostElementSelector , hostProtoView . render ) ;
77- var hostView = this . _utils . createView ( hostProtoView , hostRenderView , this , this . _renderer ) ;
71+ var renderView = this . _renderer . createRootHostView ( hostProtoView . render , hostElementSelector ) ;
72+ var hostView = this . _utils . createView ( hostProtoView , renderView , this , this . _renderer ) ;
7873 this . _renderer . setEventDispatcher ( hostView . render , hostView ) ;
79- this . _createViewRecurse ( hostView )
80- this . _utils . attachAndHydrateInPlaceHostView ( parentComponentHostView , parentComponentBoundElementIndex , hostView , injector ) ;
74+ this . _createViewRecurse ( hostView ) ;
75+
76+ this . _utils . hydrateRootHostView ( hostView , injector ) ;
8177 this . _viewHydrateRecurse ( hostView ) ;
8278 return new ViewRef ( hostView ) ;
8379 }
8480
85- destroyInPlaceHostView ( parentComponentLocation :ElementRef , hostViewRef :ViewRef ) {
81+ destroyRootHostView ( hostViewRef :ViewRef ) {
82+ // Note: Don't detach the hostView as we want to leave the
83+ // root element in place. Also don't put the hostView into the view pool
84+ // as it is depending on the element for which it was created.
8685 var hostView = internalView ( hostViewRef ) ;
87- var parentView = null ;
88- if ( isPresent ( parentComponentLocation ) ) {
89- parentView = internalView ( parentComponentLocation . parentView ) . componentChildViews [ parentComponentLocation . boundElementIndex ] ;
90- }
91- this . _destroyInPlaceHostView ( parentView , hostView ) ;
86+ // We do want to destroy the component view though.
87+ this . _viewDehydrateRecurse ( hostView , true ) ;
88+ this . _renderer . destroyView ( hostView . render ) ;
89+ }
90+
91+ createFreeHostView ( parentComponentLocation :ElementRef , hostProtoViewRef :ProtoViewRef , injector :Injector ) :ViewRef {
92+ var hostProtoView = internalProtoView ( hostProtoViewRef ) ;
93+ var hostView = this . _createPooledView ( hostProtoView ) ;
94+ var parentComponentHostView = internalView ( parentComponentLocation . parentView ) ;
95+ var parentComponentBoundElementIndex = parentComponentLocation . boundElementIndex ;
96+ this . _utils . attachAndHydrateFreeHostView ( parentComponentHostView , parentComponentBoundElementIndex , hostView , injector ) ;
97+ this . _viewHydrateRecurse ( hostView ) ;
98+ return new ViewRef ( hostView ) ;
99+ }
100+
101+ destroyFreeHostView ( parentComponentLocation :ElementRef , hostViewRef :ViewRef ) {
102+ var hostView = internalView ( hostViewRef ) ;
103+ var parentView = internalView ( parentComponentLocation . parentView ) . componentChildViews [ parentComponentLocation . boundElementIndex ] ;
104+ this . _destroyFreeHostView ( parentView , hostView ) ;
92105 }
93106
94107 createViewInContainer ( viewContainerLocation :ElementRef ,
@@ -186,16 +199,11 @@ export class AppViewManager {
186199 this . _destroyPooledView ( componentView ) ;
187200 }
188201
189- _destroyInPlaceHostView ( parentView , hostView ) {
190- var parentRenderViewRef = null ;
191- if ( isPresent ( parentView ) ) {
192- parentRenderViewRef = parentView . render ;
193- }
202+ _destroyFreeHostView ( parentView , hostView ) {
194203 this . _viewDehydrateRecurse ( hostView , true ) ;
195- this . _utils . detachInPlaceHostView ( parentView , hostView ) ;
196- this . _renderer . destroyInPlaceHostView ( parentRenderViewRef , hostView . render ) ;
197- // Note: Don't put the inplace host view into the view pool
198- // as it is depending on the element for which it was created.
204+ this . _renderer . detachFreeHostView ( parentView . render , hostView . render ) ;
205+ this . _utils . detachFreeHostView ( parentView , hostView ) ;
206+ this . _destroyPooledView ( hostView ) ;
199207 }
200208
201209 _viewHydrateRecurse (
@@ -234,10 +242,10 @@ export class AppViewManager {
234242 }
235243 }
236244
237- // inPlaceHostViews
238- for ( var i = view . inPlaceHostViews . length - 1 ; i >= 0 ; i -- ) {
239- var hostView = view . inPlaceHostViews [ i ] ;
240- this . _destroyInPlaceHostView ( view , hostView ) ;
245+ // freeHostViews
246+ for ( var i = view . freeHostViews . length - 1 ; i >= 0 ; i -- ) {
247+ var hostView = view . freeHostViews [ i ] ;
248+ this . _destroyFreeHostView ( view , hostView ) ;
241249 }
242250 }
243251}
0 commit comments