refactor(ivy): remove concept of RENDER_PARENT from LContainer (#28011)

PR Close #28011
This commit is contained in:
Pawel Kozlowski 2019-01-09 14:54:47 +01:00 committed by Andrew Kushnir
parent 6beeb76ac0
commit 6f9881f85f
7 changed files with 18 additions and 67 deletions

View File

@ -12,7 +12,7 @@ import {_sanitizeUrl, sanitizeSrcset} from '../sanitization/url_sanitizer';
import {assertDefined, assertEqual, assertGreaterThan} from './assert';
import {attachPatchData} from './context_discovery';
import {allocExpando, createNodeAtIndex, elementAttribute, load, textBinding} from './instructions';
import {LContainer, NATIVE, RENDER_PARENT} from './interfaces/container';
import {LContainer, NATIVE} from './interfaces/container';
import {COMMENT_MARKER, ELEMENT_MARKER, I18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, IcuType, TI18n, TIcu} from './interfaces/i18n';
import {TElementNode, TIcuContainerNode, TNode, TNodeType} from './interfaces/node';
import {RComment, RElement} from './interfaces/renderer';
@ -795,7 +795,6 @@ function removeNode(index: number, viewData: LView) {
if (removedPhTNode.type !== TNodeType.Container) {
removeChild(removedPhTNode, lContainer[NATIVE], viewData);
}
lContainer[RENDER_PARENT] = null;
}
}

View File

@ -33,7 +33,7 @@ import {GlobalTargetResolver, ProceduralRenderer3, RComment, RElement, RText, Re
import {SanitizerFn} from './interfaces/sanitization';
import {BINDING_INDEX, CLEANUP, CONTAINER_INDEX, CONTENT_QUERIES, CONTEXT, DECLARATION_VIEW, FLAGS, HEADER_OFFSET, HOST, HOST_NODE, INJECTOR, LView, LViewFlags, NEXT, OpaqueViewState, PARENT, QUERIES, RENDERER, RENDERER_FACTORY, RootContext, RootContextFlags, SANITIZER, TAIL, TVIEW, TView} from './interfaces/view';
import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert';
import {appendChild, appendProjectedNode, createTextNode, getLViewChild, getRenderParent, insertView, removeView} from './node_manipulation';
import {appendChild, appendProjectedNode, createTextNode, getLViewChild, insertView, removeView} from './node_manipulation';
import {isNodeMatchingSelectorList, matchingSelectorIndex} from './node_selector_matcher';
import {decreaseElementDepthCount, enterView, getBindingsEnabled, getCheckNoChangesMode, getContextLView, getCurrentDirectiveDef, getElementDepthCount, getFirstTemplatePass, getIsParent, getLView, getPreviousOrParentTNode, increaseElementDepthCount, isCreationMode, leaveView, nextContextImpl, resetComponentState, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setFirstTemplatePass, setIsParent, setPreviousOrParentTNode} from './state';
import {getInitialClassNameValue, initializeStaticContext as initializeStaticStylingContext, patchContextWithStaticAttrs, renderInitialStylesAndClasses, renderStyling, updateClassProp as updateElementClassProp, updateContextWithBindings, updateStyleProp as updateElementStyleProp, updateStylingMap} from './styling/class_and_style_bindings';
@ -1862,18 +1862,16 @@ function generateInitialInputs(
* @returns LContainer
*/
export function createLContainer(
hostNative: RElement | RComment,
hostTNode: TElementNode | TContainerNode | TElementContainerNode, currentView: LView,
native: RComment, isForViewContainerRef?: boolean): LContainer {
hostNative: RElement | RComment, currentView: LView, native: RComment,
isForViewContainerRef?: boolean): LContainer {
return [
isForViewContainerRef ? -1 : 0, // active index
[], // views
currentView, // parent
null, // next
null, // queries
hostNative, // host native
native, // native
getRenderParent(hostTNode, currentView) // renderParent
isForViewContainerRef ? -1 : 0, // active index
[], // views
currentView, // parent
null, // next
null, // queries
hostNative, // host native
native, // native
];
}
@ -1946,8 +1944,7 @@ function containerInternal(
const comment = lView[RENDERER].createComment(ngDevMode ? 'container' : '');
ngDevMode && ngDevMode.rendererCreateComment++;
const tNode = createNodeAtIndex(index, TNodeType.Container, comment, tagName, attrs);
const lContainer = lView[adjustedIndex] =
createLContainer(lView[adjustedIndex], tNode, lView, comment);
const lContainer = lView[adjustedIndex] = createLContainer(lView[adjustedIndex], lView, comment);
appendChild(comment, tNode, lView);

View File

@ -22,7 +22,6 @@ export const VIEWS = 1;
// PARENT, NEXT, QUERIES, and HOST are indices 2, 3, 4, and 5.
// As we already have these constants in LView, we don't need to re-create them.
export const NATIVE = 6;
export const RENDER_PARENT = 7;
// Because interfaces in TS/JS cannot be instanceof-checked this means that we
// need to rely on predictable characteristics of data-structures to check if they
// are what we expect for them to be. The `LContainer` interface code below has a
@ -30,7 +29,7 @@ export const RENDER_PARENT = 7;
// below we can predictably gaurantee that we are dealing with an `LContainer` array.
// This value MUST be kept up to date with the length of the `LContainer` array
// interface below so that runtime type checking can work.
export const LCONTAINER_LENGTH = 8;
export const LCONTAINER_LENGTH = 7;
/**
* The state associated with a container.
@ -90,28 +89,6 @@ export interface LContainer extends Array<any> {
/** The comment element that serves as an anchor for this LContainer. */
[NATIVE]: RComment;
/**
* Parent Element which will contain the location where all of the views will be
* inserted into to.
*
* If `renderParent` is `null` it is headless. This means that it is contained
* in another view which in turn is contained in another container and
* therefore it does not yet have its own parent.
*
* If `renderParent` is not `null` then it may be:
* - same as `tContainerNode.parent` in which case it is just a normal container.
* - different from `tContainerNode.parent` in which case it has been re-projected.
* In other words `tContainerNode.parent` is logical parent where as
* `tContainerNode.projectedParent` is render parent.
*
* When views are inserted into `LContainer` then `renderParent` is:
* - `null`, we are in a view, keep going up a hierarchy until actual
* `renderParent` is found.
* - not `null`, then use the `projectedParent.native` as the `RElement` to insert
* views into.
*/
[RENDER_PARENT]: RElement|null;
}
// Note: This hack is necessary so we don't erroneously get a circular dependency

View File

@ -8,7 +8,7 @@
import {attachPatchData} from './context_discovery';
import {callHooks} from './hooks';
import {LContainer, NATIVE, RENDER_PARENT, VIEWS, unusedValueExportToPlacateAjd as unused1} from './interfaces/container';
import {LContainer, NATIVE, VIEWS, unusedValueExportToPlacateAjd as unused1} from './interfaces/container';
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeType, TViewNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node';
import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection';
import {ProceduralRenderer3, RComment, RElement, RNode, RText, Renderer3, isProceduralRenderer, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer';
@ -111,8 +111,6 @@ function walkTNodeTree(
const lContainer = currentView ![tNode.index] as LContainer;
executeNodeAction(action, renderer, renderParent, lContainer[NATIVE], beforeNode);
if (renderParent) lContainer[RENDER_PARENT] = renderParent;
if (lContainer[VIEWS].length) {
currentView = lContainer[VIEWS][0];
nextTNode = currentView[TVIEW].node;
@ -487,7 +485,7 @@ function executeOnDestroys(view: LView): void {
}
}
export function getRenderParent(tNode: TNode, currentView: LView): RElement|null {
function getRenderParent(tNode: TNode, currentView: LView): RElement|null {
if (canInsertNativeNode(tNode, currentView)) {
// If we are asked for a render parent of the root component we need to do low-level DOM
// operation as LTree doesn't exist above the topmost host node. We might need to find a render
@ -527,17 +525,7 @@ function canInsertNativeChildOfElement(tNode: TElementNode): boolean {
* the container itself has its render parent determined.
*/
function canInsertNativeChildOfView(viewTNode: TViewNode, view: LView): boolean {
// Because we are inserting into a `View` the `View` may be disconnected.
const container = getLContainer(viewTNode, view) !;
if (container == null || container[RENDER_PARENT] == null) {
// The `View` is not inserted into a `Container` or the parent `Container`
// itself is disconnected. So we have to delay.
return false;
}
// The parent `Container` is in inserted state, so we can eagerly insert into
// this location.
return true;
return getContainerRenderParent(viewTNode, view) != null;
}
/**
@ -558,7 +546,7 @@ function canInsertNativeChildOfView(viewTNode: TViewNode, view: LView): boolean
* @param currentView Current LView being processed.
* @return boolean Whether the node should be inserted now (or delayed until later).
*/
export function canInsertNativeNode(tNode: TNode, currentView: LView): boolean {
function canInsertNativeNode(tNode: TNode, currentView: LView): boolean {
// Nodes of the top-most view can be inserted eagerly
if (isRootView(currentView)) {
return true;
@ -723,8 +711,6 @@ export function appendProjectedNode(
// logical container of the content projected views
attachPatchData(native, projectionView);
const renderParent = getRenderParent(tProjectionNode, currentView);
const nodeOrContainer = projectionView[projectedTNode.index];
if (projectedTNode.type === TNodeType.Container) {
// The node we are adding is a container and we are adding it to an element which
@ -732,7 +718,6 @@ export function appendProjectedNode(
// Alternatively a container is projected at the root of a component's template
// and can't be re-projected (as not content of any component).
// Assign the final projection location in those cases.
nodeOrContainer[RENDER_PARENT] = renderParent;
const views = nodeOrContainer[VIEWS];
for (let i = 0; i < views.length; i++) {
addRemoveViewFromContainer(views[i], true, nodeOrContainer[NATIVE]);
@ -747,7 +732,6 @@ export function appendProjectedNode(
}
if (isLContainer(nodeOrContainer)) {
nodeOrContainer[RENDER_PARENT] = renderParent;
appendChild(nodeOrContainer[NATIVE], tProjectionNode, currentView);
}
}

View File

@ -317,7 +317,7 @@ export function createContainerRef(
}
hostView[hostTNode.index] = lContainer =
createLContainer(slotValue, hostTNode, hostView, commentNode, true);
createLContainer(slotValue, hostView, commentNode, true);
addToViewTree(hostView, hostTNode.index as number, lContainer);
}

View File

@ -110,9 +110,6 @@
{
"name": "RENDERER_FACTORY"
},
{
"name": "RENDER_PARENT"
},
{
"name": "SANITIZER"
},

View File

@ -179,9 +179,6 @@
{
"name": "RENDERER_FACTORY"
},
{
"name": "RENDER_PARENT"
},
{
"name": "RecordViewTuple"
},