|
9 | 9 | import {ViewEncapsulation} from '../metadata/view'; |
10 | 10 | import {Renderer2} from '../render/api'; |
11 | 11 | import {addToArray, removeFromArray} from '../util/array_utils'; |
12 | | -import {assertDefined, assertDomNode, assertEqual, assertSame, assertString} from '../util/assert'; |
| 12 | +import {assertDefined, assertDomNode, assertEqual, assertString} from '../util/assert'; |
13 | 13 |
|
14 | 14 | import {assertLContainer, assertLView, assertTNodeForLView} from './assert'; |
15 | 15 | import {attachPatchData} from './context_discovery'; |
16 | 16 | import {CONTAINER_HEADER_OFFSET, HAS_TRANSPLANTED_VIEWS, LContainer, MOVED_VIEWS, NATIVE, unusedValueExportToPlacateAjd as unused1} from './interfaces/container'; |
17 | 17 | import {ComponentDef} from './interfaces/definition'; |
18 | 18 | import {NodeInjectorFactory} from './interfaces/injector'; |
19 | | -import {TElementNode, TNode, TNodeFlags, TNodeType, TProjectionNode, TViewNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node'; |
| 19 | +import {TElementNode, TNode, TNodeFlags, TNodeType, TProjectionNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node'; |
20 | 20 | import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection'; |
21 | 21 | import {isProceduralRenderer, ProceduralRenderer3, RElement, Renderer3, RNode, RText, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer'; |
22 | 22 | import {isLContainer, isLView} from './interfaces/type_checks'; |
23 | 23 | import {CHILD_HEAD, CLEANUP, DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, DestroyHookData, FLAGS, HookData, HookFn, HOST, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, T_HOST, TVIEW, TView, TViewType, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; |
24 | 24 | import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert'; |
25 | 25 | import {getLViewParent} from './util/view_traversal_utils'; |
26 | | -import {getNativeByTNode, getNonViewFirstChild, unwrapRNode, updateTransplantedViewCount} from './util/view_utils'; |
| 26 | +import {getNativeByTNode, unwrapRNode, updateTransplantedViewCount} from './util/view_utils'; |
27 | 27 |
|
28 | 28 | const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5; |
29 | 29 |
|
30 | | -export function getLContainer(tNode: TViewNode, embeddedView: LView): LContainer|null { |
31 | | - ngDevMode && assertLView(embeddedView); |
32 | | - const container = embeddedView[PARENT] as LContainer; |
33 | | - if (tNode.index === -1) { |
34 | | - // This is a dynamically created view inside a dynamic container. |
35 | | - // The parent isn't an LContainer if the embedded view hasn't been attached yet. |
36 | | - return isLContainer(container) ? container : null; |
37 | | - } else { |
38 | | - ngDevMode && assertLContainer(container); |
39 | | - // This is a inline view node (e.g. embeddedViewStart) |
40 | | - return container; |
41 | | - } |
42 | | -} |
43 | | - |
44 | | - |
45 | | -/** |
46 | | - * Retrieves render parent for a given view. |
47 | | - * Might be null if a view is not yet attached to any container. |
48 | | - */ |
49 | | -export function getContainerRenderParent(tViewNode: TViewNode, view: LView): RElement|null { |
50 | | - const container = getLContainer(tViewNode, view); |
51 | | - return container ? nativeParentNode(view[RENDERER], container[NATIVE]) : null; |
52 | | -} |
53 | | - |
54 | 30 | const enum WalkTNodeTreeAction { |
55 | 31 | /** node create in the native environment. Run on initial creation. */ |
56 | 32 | Create = 0, |
@@ -211,11 +187,15 @@ export function destroyViewTree(rootView: LView): void { |
211 | 187 | // Only clean up view when moving to the side or up, as destroy hooks |
212 | 188 | // should be called in order from the bottom up. |
213 | 189 | while (lViewOrLContainer && !lViewOrLContainer![NEXT] && lViewOrLContainer !== rootView) { |
214 | | - isLView(lViewOrLContainer) && cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer); |
215 | | - lViewOrLContainer = getParentState(lViewOrLContainer, rootView); |
| 190 | + if (isLView(lViewOrLContainer)) { |
| 191 | + cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer); |
| 192 | + } |
| 193 | + lViewOrLContainer = lViewOrLContainer[PARENT]; |
216 | 194 | } |
217 | 195 | if (lViewOrLContainer === null) lViewOrLContainer = rootView; |
218 | | - isLView(lViewOrLContainer) && cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer); |
| 196 | + if (isLView(lViewOrLContainer)) { |
| 197 | + cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer); |
| 198 | + } |
219 | 199 | next = lViewOrLContainer && lViewOrLContainer![NEXT]; |
220 | 200 | } |
221 | 201 | lViewOrLContainer = next; |
@@ -381,32 +361,6 @@ export function destroyLView(tView: TView, lView: LView) { |
381 | 361 | } |
382 | 362 | } |
383 | 363 |
|
384 | | -/** |
385 | | - * Determines which LViewOrLContainer to jump to when traversing back up the |
386 | | - * tree in destroyViewTree. |
387 | | - * |
388 | | - * Normally, the view's parent LView should be checked, but in the case of |
389 | | - * embedded views, the container (which is the view node's parent, but not the |
390 | | - * LView's parent) needs to be checked for a possible next property. |
391 | | - * |
392 | | - * @param lViewOrLContainer The LViewOrLContainer for which we need a parent state |
393 | | - * @param rootView The rootView, so we don't propagate too far up the view tree |
394 | | - * @returns The correct parent LViewOrLContainer |
395 | | - */ |
396 | | -export function getParentState(lViewOrLContainer: LView|LContainer, rootView: LView): LView| |
397 | | - LContainer|null { |
398 | | - let tNode; |
399 | | - if (isLView(lViewOrLContainer) && (tNode = lViewOrLContainer[T_HOST]) && |
400 | | - tNode.type === TNodeType.View) { |
401 | | - // if it's an embedded view, the state needs to go up to the container, in case the |
402 | | - // container has a next |
403 | | - return getLContainer(tNode as TViewNode, lViewOrLContainer); |
404 | | - } else { |
405 | | - // otherwise, use parent view for containers or component views |
406 | | - return lViewOrLContainer[PARENT] === rootView ? null : lViewOrLContainer[PARENT]; |
407 | | - } |
408 | | -} |
409 | | - |
410 | 364 | /** |
411 | 365 | * Calls onDestroys hooks for all directives and pipes in a given view and then removes all |
412 | 366 | * listeners. Listeners are removed as the last step so events delivered in the onDestroys hooks |
@@ -531,30 +485,18 @@ function getRenderParent(tView: TView, tNode: TNode, currentView: LView): REleme |
531 | 485 | // can't be used as a render parent. |
532 | 486 | let parentTNode = tNode.parent; |
533 | 487 | while (parentTNode != null && |
534 | | - (parentTNode.type === TNodeType.ElementContainer || parentTNode.type === TNodeType.View || |
| 488 | + (parentTNode.type === TNodeType.ElementContainer || |
535 | 489 | parentTNode.type === TNodeType.IcuContainer)) { |
536 | 490 | tNode = parentTNode; |
537 | 491 | parentTNode = tNode.parent; |
538 | 492 | } |
539 | 493 |
|
540 | 494 | // If the parent tNode is null, then we are inserting across views: either into an embedded view |
541 | 495 | // or a component view. |
542 | | - if (parentTNode == null) { |
543 | | - const hostTNode = currentView[T_HOST]!; |
544 | | - if (hostTNode && hostTNode.type === TNodeType.View) { |
545 | | - // We are inserting a root element of an embedded view We might delay insertion of children |
546 | | - // for a given view if it is disconnected. This might happen for 2 main reasons: |
547 | | - // - view is not inserted into any container(view was created but not inserted yet) |
548 | | - // - view is inserted into a container but the container itself is not inserted into the DOM |
549 | | - // (container might be part of projection or child of a view that is not inserted yet). |
550 | | - // In other words we can insert children of a given view if this view was inserted into a |
551 | | - // container and the container itself has its render parent determined. |
552 | | - return getContainerRenderParent(hostTNode as TViewNode, currentView); |
553 | | - } else { |
554 | | - // We are inserting a root element of the component view into the component host element and |
555 | | - // it should always be eager. |
556 | | - return currentView[HOST]; |
557 | | - } |
| 496 | + if (parentTNode === null) { |
| 497 | + // We are inserting a root element of the component view into the component host element and |
| 498 | + // it should always be eager. |
| 499 | + return currentView[HOST]; |
558 | 500 | } else { |
559 | 501 | const isIcuCase = tNode && tNode.type === TNodeType.IcuContainer; |
560 | 502 | // If the parent of this node is an ICU container, then it is represented by comment node and we |
@@ -650,13 +592,7 @@ export function nativeNextSibling(renderer: Renderer3, node: RNode): RNode|null |
650 | 592 | * @param lView |
651 | 593 | */ |
652 | 594 | function getNativeAnchorNode(parentTNode: TNode, lView: LView): RNode|null { |
653 | | - if (parentTNode.type === TNodeType.View) { |
654 | | - const lContainer = getLContainer(parentTNode as TViewNode, lView); |
655 | | - if (lContainer === null) return null; |
656 | | - const index = lContainer.indexOf(lView, CONTAINER_HEADER_OFFSET) - CONTAINER_HEADER_OFFSET; |
657 | | - return getBeforeNodeForView(index, lContainer); |
658 | | - } else if ( |
659 | | - parentTNode.type === TNodeType.ElementContainer || |
| 595 | + if (parentTNode.type === TNodeType.ElementContainer || |
660 | 596 | parentTNode.type === TNodeType.IcuContainer) { |
661 | 597 | return getNativeByTNode(parentTNode, lView); |
662 | 598 | } |
@@ -743,7 +679,7 @@ export function getBeforeNodeForView(viewIndexInContainer: number, lContainer: L |
743 | 679 | const nextViewIndex = CONTAINER_HEADER_OFFSET + viewIndexInContainer + 1; |
744 | 680 | if (nextViewIndex < lContainer.length) { |
745 | 681 | const lView = lContainer[nextViewIndex] as LView; |
746 | | - const firstTNodeOfView = getNonViewFirstChild(lView[TVIEW]); |
| 682 | + const firstTNodeOfView = lView[TVIEW].firstChild; |
747 | 683 | if (firstTNodeOfView !== null) { |
748 | 684 | return getFirstNativeNode(lView, firstTNodeOfView); |
749 | 685 | } |
|
0 commit comments