Skip to content

Commit

Permalink
refactor(ivy): Remove findComponentView since we now store it in `L…
Browse files Browse the repository at this point in the history
…View[DECLARATION_COMPONENT_VIEW]` (#33810)

PR Close #33810
  • Loading branch information
mhevery authored and alxhub committed Nov 15, 2019
1 parent 4a4888b commit af2cca0
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 64 deletions.
9 changes: 3 additions & 6 deletions packages/core/src/debug/debug_node.ts
Expand Up @@ -10,17 +10,14 @@ import {Injector} from '../di';
import {getViewComponent} from '../render3/global_utils_api'; import {getViewComponent} from '../render3/global_utils_api';
import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE} from '../render3/interfaces/container'; import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE} from '../render3/interfaces/container';
import {TElementNode, TNode, TNodeFlags, TNodeType} from '../render3/interfaces/node'; import {TElementNode, TNode, TNodeFlags, TNodeType} from '../render3/interfaces/node';
import {StylingMapArray, TStylingContext} from '../render3/interfaces/styling';
import {isComponentHost, isLContainer} from '../render3/interfaces/type_checks'; import {isComponentHost, isLContainer} from '../render3/interfaces/type_checks';
import {LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view'; import {DECLARATION_COMPONENT_VIEW, LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view';
import {NodeStylingDebug} from '../render3/styling/styling_debug';
import {getComponent, getContext, getInjectionTokens, getInjector, getListeners, getLocalRefs, isBrowserEvents, loadLContext} from '../render3/util/discovery_utils'; import {getComponent, getContext, getInjectionTokens, getInjector, getListeners, getLocalRefs, isBrowserEvents, loadLContext} from '../render3/util/discovery_utils';
import {INTERPOLATION_DELIMITER, renderStringify} from '../render3/util/misc_utils'; import {INTERPOLATION_DELIMITER, renderStringify} from '../render3/util/misc_utils';
import {isStylingContext, stylingMapToStringMap} from '../render3/util/styling_utils';
import {findComponentView} from '../render3/util/view_traversal_utils';
import {getComponentLViewByIndex, getNativeByTNodeOrNull} from '../render3/util/view_utils'; import {getComponentLViewByIndex, getNativeByTNodeOrNull} from '../render3/util/view_utils';
import {assertDomNode} from '../util/assert'; import {assertDomNode} from '../util/assert';
import {DebugContext} from '../view/index'; import {DebugContext} from '../view/index';

import {createProxy} from './proxy'; import {createProxy} from './proxy';




Expand Down Expand Up @@ -533,7 +530,7 @@ function _queryNodeChildrenR3(
} else if (tNode.type === TNodeType.Projection) { } else if (tNode.type === TNodeType.Projection) {
// Case 3: the TNode is a projection insertion point (i.e. a <ng-content>). // Case 3: the TNode is a projection insertion point (i.e. a <ng-content>).
// The nodes projected at this location all need to be processed. // The nodes projected at this location all need to be processed.
const componentView = findComponentView(lView !); const componentView = lView ![DECLARATION_COMPONENT_VIEW];
const componentHost = componentView[T_HOST] as TElementNode; const componentHost = componentView[T_HOST] as TElementNode;
const head: TNode|null = const head: TNode|null =
(componentHost.projection as(TNode | null)[])[tNode.projection as number]; (componentHost.projection as(TNode | null)[])[tNode.projection as number];
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/render3/di.ts
Expand Up @@ -21,14 +21,13 @@ import {DirectiveDef, FactoryFn} from './interfaces/definition';
import {NO_PARENT_INJECTOR, NodeInjectorFactory, PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFlags, TNODE, isFactory} from './interfaces/injector'; import {NO_PARENT_INJECTOR, NodeInjectorFactory, PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFlags, TNODE, isFactory} from './interfaces/injector';
import {AttributeMarker, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeProviderIndexes, TNodeType} from './interfaces/node'; import {AttributeMarker, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeProviderIndexes, TNodeType} from './interfaces/node';
import {isComponentDef, isComponentHost} from './interfaces/type_checks'; import {isComponentDef, isComponentHost} from './interfaces/type_checks';
import {DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view'; import {DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view';
import {assertNodeOfPossibleTypes} from './node_assert'; import {assertNodeOfPossibleTypes} from './node_assert';
import {enterDI, leaveDI} from './state'; import {enterDI, leaveDI} from './state';
import {isNameOnlyAttributeMarker} from './util/attrs_utils'; import {isNameOnlyAttributeMarker} from './util/attrs_utils';
import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './util/injector_utils'; import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './util/injector_utils';
import {stringifyForError} from './util/misc_utils'; import {stringifyForError} from './util/misc_utils';
import {getInitialStylingValue} from './util/styling_utils'; import {getInitialStylingValue} from './util/styling_utils';
import {findComponentView} from './util/view_traversal_utils';






Expand Down Expand Up @@ -358,7 +357,7 @@ export function getOrCreateInjectable<T>(
let injectorIndex = getInjectorIndex(tNode, lView); let injectorIndex = getInjectorIndex(tNode, lView);
let parentLocation: RelativeInjectorLocation = NO_PARENT_INJECTOR; let parentLocation: RelativeInjectorLocation = NO_PARENT_INJECTOR;
let hostTElementNode: TNode|null = let hostTElementNode: TNode|null =
flags & InjectFlags.Host ? findComponentView(lView)[T_HOST] : null; flags & InjectFlags.Host ? lView[DECLARATION_COMPONENT_VIEW][T_HOST] : null;


// If we should skip this injector, or if there is no injector on this node, start by // If we should skip this injector, or if there is no injector on this node, start by
// searching // searching
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/render3/instructions/projection.ts
Expand Up @@ -8,12 +8,10 @@
import {newArray} from '../../util/array_utils'; import {newArray} from '../../util/array_utils';
import {TAttributes, TElementNode, TNode, TNodeType} from '../interfaces/node'; import {TAttributes, TElementNode, TNode, TNodeType} from '../interfaces/node';
import {ProjectionSlots} from '../interfaces/projection'; import {ProjectionSlots} from '../interfaces/projection';
import {TVIEW, T_HOST} from '../interfaces/view'; import {DECLARATION_COMPONENT_VIEW, TVIEW, T_HOST} from '../interfaces/view';
import {applyProjection} from '../node_manipulation'; import {applyProjection} from '../node_manipulation';
import {getProjectAsAttrValue, isNodeMatchingSelectorList, isSelectorInSelectorList} from '../node_selector_matcher'; import {getProjectAsAttrValue, isNodeMatchingSelectorList, isSelectorInSelectorList} from '../node_selector_matcher';
import {getLView, setIsNotParent} from '../state'; import {getLView, setIsNotParent} from '../state';
import {findComponentView} from '../util/view_traversal_utils';

import {getOrCreateTNode} from './shared'; import {getOrCreateTNode} from './shared';




Expand Down Expand Up @@ -75,7 +73,7 @@ export function matchingProjectionSlotIndex(tNode: TNode, projectionSlots: Proje
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵprojectionDef(projectionSlots?: ProjectionSlots): void { export function ɵɵprojectionDef(projectionSlots?: ProjectionSlots): void {
const componentNode = findComponentView(getLView())[T_HOST] as TElementNode; const componentNode = getLView()[DECLARATION_COMPONENT_VIEW][T_HOST] as TElementNode;


if (!componentNode.projection) { if (!componentNode.projection) {
// If no explicit projection slots are defined, fall back to a single // If no explicit projection slots are defined, fall back to a single
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/render3/instructions/shared.ts
Expand Up @@ -173,9 +173,11 @@ export function createLView<T>(
lView[SANITIZER] = sanitizer || parentLView && parentLView[SANITIZER] || null !; lView[SANITIZER] = sanitizer || parentLView && parentLView[SANITIZER] || null !;
lView[INJECTOR as any] = injector || parentLView && parentLView[INJECTOR] || null; lView[INJECTOR as any] = injector || parentLView && parentLView[INJECTOR] || null;
lView[T_HOST] = tHostNode; lView[T_HOST] = tHostNode;
lView[DECLARATION_COMPONENT_VIEW] = tView.type == TViewType.Embedded ? ngDevMode && assertEqual(
(parentLView === null ? null : parentLView ![DECLARATION_COMPONENT_VIEW]) : tView.type == TViewType.Embedded ? parentLView !== null : true, true,
lView; 'Embedded views must have parentLView');
lView[DECLARATION_COMPONENT_VIEW] =
tView.type == TViewType.Embedded ? parentLView ![DECLARATION_COMPONENT_VIEW] : lView;
ngDevMode && attachLViewDebug(lView); ngDevMode && attachLViewDebug(lView);
return lView; return lView;
} }
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/interfaces/view.ts
Expand Up @@ -265,7 +265,7 @@ export interface LView extends Array<any> {
* - `LView[DECLARATION_LCONTAINER]` similar problem for queries * - `LView[DECLARATION_LCONTAINER]` similar problem for queries
* - `LContainer[MOVED_VIEWS]` similar problem for queries * - `LContainer[MOVED_VIEWS]` similar problem for queries
*/ */
[DECLARATION_COMPONENT_VIEW]: LView|null; [DECLARATION_COMPONENT_VIEW]: LView;


/** /**
* A declaration point of embedded views (ones instantiated based on the content of a * A declaration point of embedded views (ones instantiated based on the content of a
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/render3/node_manipulation.ts
Expand Up @@ -20,7 +20,7 @@ import {ProceduralRenderer3, RElement, RNode, RText, Renderer3, isProceduralRend
import {isLContainer, isLView, isRootView} from './interfaces/type_checks'; import {isLContainer, isLView, isRootView} from './interfaces/type_checks';
import {CHILD_HEAD, CLEANUP, DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, FLAGS, HOST, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, T_HOST, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; import {CHILD_HEAD, CLEANUP, DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, FLAGS, HOST, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, T_HOST, unusedValueExportToPlacateAjd as unused5} from './interfaces/view';
import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert'; import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert';
import {findComponentView, getLViewParent} from './util/view_traversal_utils'; import {getLViewParent} from './util/view_traversal_utils';
import {getNativeByTNode, unwrapRNode} from './util/view_utils'; import {getNativeByTNode, unwrapRNode} from './util/view_utils';


const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5; const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5;
Expand Down Expand Up @@ -261,7 +261,7 @@ function trackMovedView(declarationContainer: LContainer, lView: LView) {
const movedViews = declarationContainer[MOVED_VIEWS]; const movedViews = declarationContainer[MOVED_VIEWS];
const insertedLContainer = lView[PARENT] as LContainer; const insertedLContainer = lView[PARENT] as LContainer;
ngDevMode && assertLContainer(insertedLContainer); ngDevMode && assertLContainer(insertedLContainer);
const insertedComponentLView = insertedLContainer[PARENT] ![DECLARATION_COMPONENT_VIEW] !; const insertedComponentLView = insertedLContainer[PARENT] ![DECLARATION_COMPONENT_VIEW];
ngDevMode && assertDefined(insertedComponentLView, 'Missing insertedComponentLView'); ngDevMode && assertDefined(insertedComponentLView, 'Missing insertedComponentLView');
const insertedComponentIsOnPush = const insertedComponentIsOnPush =
(insertedComponentLView[FLAGS] & LViewFlags.CheckAlways) !== LViewFlags.CheckAlways; (insertedComponentLView[FLAGS] & LViewFlags.CheckAlways) !== LViewFlags.CheckAlways;
Expand Down Expand Up @@ -695,7 +695,7 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null {
return getNativeByTNode(tNode, lView); return getNativeByTNode(tNode, lView);
} }
} else { } else {
const componentView = findComponentView(lView); const componentView = lView[DECLARATION_COMPONENT_VIEW];
const componentHost = componentView[T_HOST] as TElementNode; const componentHost = componentView[T_HOST] as TElementNode;
const parentView = getLViewParent(componentView); const parentView = getLViewParent(componentView);
const firstProjectedTNode: TNode|null = const firstProjectedTNode: TNode|null =
Expand Down Expand Up @@ -846,7 +846,7 @@ export function applyProjection(lView: LView, tProjectionNode: TProjectionNode)
function applyProjectionRecursive( function applyProjectionRecursive(
renderer: Renderer3, action: WalkTNodeTreeAction, lView: LView, renderer: Renderer3, action: WalkTNodeTreeAction, lView: LView,
tProjectionNode: TProjectionNode, renderParent: RElement | null, beforeNode: RNode | null) { tProjectionNode: TProjectionNode, renderParent: RElement | null, beforeNode: RNode | null) {
const componentLView = findComponentView(lView); const componentLView = lView[DECLARATION_COMPONENT_VIEW];
const componentNode = componentLView[T_HOST] as TElementNode; const componentNode = componentLView[T_HOST] as TElementNode;
ngDevMode && ngDevMode &&
assertEqual(typeof tProjectionNode.projection, 'number', 'expecting projection index'); assertEqual(typeof tProjectionNode.projection, 'number', 'expecting projection index');
Expand Down
28 changes: 1 addition & 27 deletions packages/core/src/render3/util/view_traversal_utils.ts
Expand Up @@ -8,14 +8,11 @@


import {assertDefined} from '../../util/assert'; import {assertDefined} from '../../util/assert';
import {assertLView} from '../assert'; import {assertLView} from '../assert';
import {TNodeType} from '../interfaces/node';
import {isLContainer, isLView} from '../interfaces/type_checks'; import {isLContainer, isLView} from '../interfaces/type_checks';
import {CONTEXT, DECLARATION_VIEW, FLAGS, LView, LViewFlags, PARENT, RootContext, T_HOST} from '../interfaces/view'; import {CONTEXT, FLAGS, LView, LViewFlags, PARENT, RootContext} from '../interfaces/view';

import {readPatchedLView} from './view_utils'; import {readPatchedLView} from './view_utils';





/** /**
* Gets the parent LView of the passed LView, if the PARENT is an LContainer, will get the parent of * Gets the parent LView of the passed LView, if the PARENT is an LContainer, will get the parent of
* that LContainer, which is an LView * that LContainer, which is an LView
Expand Down Expand Up @@ -43,29 +40,6 @@ export function getRootView(componentOrLView: LView | {}): LView {
return lView; return lView;
} }


/**
* Given an `LView`, find the closest declaration view which is not an embedded view.
*
* This method searches for the `LView` associated with the component which declared the `LView`.
*
* This function may return itself if the `LView` passed in is not an embedded `LView`. Otherwise
* it walks the declaration parents until it finds a component view (non-embedded-view.)
*
* @param lView LView for which we want a host element node
* @returns The host node
*/
export function findComponentView(lView: LView): LView {
let rootTNode = lView[T_HOST];
let declaredView: LView|null;
while (rootTNode !== null && rootTNode.type === TNodeType.View &&
(declaredView = lView[DECLARATION_VIEW]) !== null) {
lView = declaredView;
rootTNode = lView[T_HOST];
}
ngDevMode && assertLView(lView);
return lView;
}

/** /**
* Returns the `RootContext` instance that is associated with * Returns the `RootContext` instance that is associated with
* the application where the target is situated. It does this by walking the parent views until it * the application where the target is situated. It does this by walking the parent views until it
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/render3/view_engine_compatibility.ts
Expand Up @@ -25,13 +25,12 @@ import {ActiveIndexFlag, CONTAINER_HEADER_OFFSET, LContainer, VIEW_REFS} from '.
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node';
import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer'; import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer';
import {isComponentHost, isLContainer, isLView, isRootView} from './interfaces/type_checks'; import {isComponentHost, isLContainer, isLView, isRootView} from './interfaces/type_checks';
import {DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; import {DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view';
import {assertNodeOfPossibleTypes} from './node_assert'; import {assertNodeOfPossibleTypes} from './node_assert';
import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation'; import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation';
import {getParentInjectorTNode} from './node_util'; import {getParentInjectorTNode} from './node_util';
import {getLView, getPreviousOrParentTNode} from './state'; import {getLView, getPreviousOrParentTNode} from './state';
import {getParentInjectorView, hasParentInjector} from './util/injector_utils'; import {getParentInjectorView, hasParentInjector} from './util/injector_utils';
import {findComponentView} from './util/view_traversal_utils';
import {getComponentLViewByIndex, getNativeByTNode, setLContainerActiveIndex, unwrapRNode, viewAttachedToContainer} from './util/view_utils'; import {getComponentLViewByIndex, getNativeByTNode, setLContainerActiveIndex, unwrapRNode, viewAttachedToContainer} from './util/view_utils';
import {ViewRef} from './view_ref'; import {ViewRef} from './view_ref';


Expand Down Expand Up @@ -389,7 +388,7 @@ function createViewRef(tNode: TNode, lView: LView, isPipe: boolean): ViewEngine_
tNode.type === TNodeType.ElementContainer) { tNode.type === TNodeType.ElementContainer) {
// The LView represents the location where the injection is requested from. // The LView represents the location where the injection is requested from.
// We need to locate the containing LView (in case where the `lView` is an embedded view) // We need to locate the containing LView (in case where the `lView` is an embedded view)
const hostComponentView = findComponentView(lView); // look up const hostComponentView = lView[DECLARATION_COMPONENT_VIEW]; // look up
return new ViewRef(hostComponentView, lView); return new ViewRef(hostComponentView, lView);
} }
return null !; return null !;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/render3/view_ref.ts
Expand Up @@ -15,10 +15,10 @@ import {checkNoChangesInRootView, checkNoChangesInternal, detectChangesInRootVie
import {CONTAINER_HEADER_OFFSET} from './interfaces/container'; import {CONTAINER_HEADER_OFFSET} from './interfaces/container';
import {TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node';
import {isLContainer} from './interfaces/type_checks'; import {isLContainer} from './interfaces/type_checks';
import {CONTEXT, FLAGS, HOST, LView, LViewFlags, TVIEW, T_HOST} from './interfaces/view'; import {CONTEXT, DECLARATION_COMPONENT_VIEW, FLAGS, HOST, LView, LViewFlags, TVIEW, T_HOST} from './interfaces/view';
import {assertNodeOfPossibleTypes} from './node_assert'; import {assertNodeOfPossibleTypes} from './node_assert';
import {destroyLView, renderDetachView} from './node_manipulation'; import {destroyLView, renderDetachView} from './node_manipulation';
import {findComponentView, getLViewParent} from './util/view_traversal_utils'; import {getLViewParent} from './util/view_traversal_utils';
import {unwrapRNode} from './util/view_utils'; import {unwrapRNode} from './util/view_utils';




Expand Down Expand Up @@ -331,7 +331,7 @@ function collectNativeNodes(
if (tNodeType === TNodeType.ElementContainer || tNodeType === TNodeType.IcuContainer) { if (tNodeType === TNodeType.ElementContainer || tNodeType === TNodeType.IcuContainer) {
collectNativeNodes(lView, tNode.child, result); collectNativeNodes(lView, tNode.child, result);
} else if (tNodeType === TNodeType.Projection) { } else if (tNodeType === TNodeType.Projection) {
const componentView = findComponentView(lView); const componentView = lView[DECLARATION_COMPONENT_VIEW];
const componentHost = componentView[T_HOST] as TElementNode; const componentHost = componentView[T_HOST] as TElementNode;
const parentView = getLViewParent(componentView); const parentView = getLViewParent(componentView);
let firstProjectedNode: TNode|null = let firstProjectedNode: TNode|null =
Expand Down
Expand Up @@ -272,9 +272,6 @@
{ {
"name": "findAttrIndexInNode" "name": "findAttrIndexInNode"
}, },
{
"name": "findComponentView"
},
{ {
"name": "findDirectiveMatches" "name": "findDirectiveMatches"
}, },
Expand Down
Expand Up @@ -227,9 +227,6 @@
{ {
"name": "extractPipeDef" "name": "extractPipeDef"
}, },
{
"name": "findComponentView"
},
{ {
"name": "generateExpandoInstructionBlock" "name": "generateExpandoInstructionBlock"
}, },
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/todo/bundle.golden_symbols.json
Expand Up @@ -575,9 +575,6 @@
{ {
"name": "findAttrIndexInNode" "name": "findAttrIndexInNode"
}, },
{
"name": "findComponentView"
},
{ {
"name": "findDirectiveMatches" "name": "findDirectiveMatches"
}, },
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/render3/di_spec.ts
Expand Up @@ -223,7 +223,7 @@ describe('di', () => {
describe('getOrCreateNodeInjector', () => { describe('getOrCreateNodeInjector', () => {
it('should handle initial undefined state', () => { it('should handle initial undefined state', () => {
const contentView = createLView( const contentView = createLView(
null, createTView(TViewType.Embedded, -1, null, 1, 0, null, null, null, null, null), {}, null, createTView(TViewType.Component, -1, null, 1, 0, null, null, null, null, null), {},
LViewFlags.CheckAlways, null, null, {} as any, {} as any); LViewFlags.CheckAlways, null, null, {} as any, {} as any);
enterView(contentView, null); enterView(contentView, null);
try { try {
Expand Down

0 comments on commit af2cca0

Please sign in to comment.