(
tNode: TElementNode | TElementContainerNode,
lView: LView,
index: number,
name: string,
locateOrCreateNativeNode: (
tView: TView,
lView: LView,
tNode: TNode,
name: string,
index: number,
) => RNode,
)
| 594 | |
| 595 | /** Shared code between instructions that indicate the start of an element. */ |
| 596 | export function elementLikeStartShared( |
| 597 | tNode: TElementNode | TElementContainerNode, |
| 598 | lView: LView, |
| 599 | index: number, |
| 600 | name: string, |
| 601 | locateOrCreateNativeNode: ( |
| 602 | tView: TView, |
| 603 | lView: LView, |
| 604 | tNode: TNode, |
| 605 | name: string, |
| 606 | index: number, |
| 607 | ) => RNode, |
| 608 | ) { |
| 609 | const adjustedIndex = HEADER_OFFSET + index; |
| 610 | const tView = lView[TVIEW]; |
| 611 | const native = locateOrCreateNativeNode(tView, lView, tNode, name, index); |
| 612 | lView[adjustedIndex] = native; |
| 613 | setCurrentTNode(tNode, true); |
| 614 | |
| 615 | // It's important that this runs before we've instantiated the directives. |
| 616 | const isElement = tNode.type === TNodeType.Element; |
| 617 | if (isElement) { |
| 618 | setupStaticAttributes(lView[RENDERER], native as RElement, tNode); |
| 619 | |
| 620 | // any immediate children of a component or template container must be pre-emptively |
| 621 | // monkey-patched with the component view data so that the element can be inspected |
| 622 | // later on using any element discovery utility methods (see `element_discovery.ts`) |
| 623 | if (getElementDepthCount() === 0 || isDirectiveHost(tNode)) { |
| 624 | attachPatchData(native, lView); |
| 625 | } |
| 626 | increaseElementDepthCount(); |
| 627 | } else { |
| 628 | attachPatchData(native, lView); |
| 629 | } |
| 630 | |
| 631 | if (wasLastNodeCreated() && (!isElement || !isDetachedByI18n(tNode))) { |
| 632 | // In the i18n case, the translation may have removed this element, so only add it if it is not |
| 633 | // detached. See `TNodeType.Placeholder` and `LFrame.inI18n` for more context. |
| 634 | appendChild(tView, lView, native, tNode); |
| 635 | } |
| 636 | |
| 637 | return tNode; |
| 638 | } |
| 639 | |
| 640 | /** Shared code between instructions that indicate the end of an element. */ |
| 641 | export function elementLikeEndShared(tNode: TNode): TNode { |
no test coverage detected