refactor(core): unify setPreviousOrParentTNode and setIsParent into single setPreviousOrParentTNode (#30453)
PR Close #30453
This commit is contained in:
parent
e122b44269
commit
2f336f15be
|
@ -26,7 +26,7 @@ import {SanitizerFn} from './interfaces/sanitization';
|
|||
import {StylingContext} from './interfaces/styling';
|
||||
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, TView, T_HOST} from './interfaces/view';
|
||||
import {appendChild, createTextNode, nativeRemoveNode} from './node_manipulation';
|
||||
import {getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from './state';
|
||||
import {getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from './state';
|
||||
import {NO_CHANGE} from './tokens';
|
||||
import {renderStringify} from './util/misc_utils';
|
||||
import {getNativeByIndex, getNativeByTNode, getTNode, isLContainer} from './util/view_utils';
|
||||
|
@ -701,7 +701,7 @@ function readCreateOpCodes(
|
|||
previousTNode = currentTNode;
|
||||
currentTNode = createDynamicNodeAtIndex(textNodeIndex, TNodeType.Element, textRNode, null);
|
||||
visitedNodes.push(textNodeIndex);
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
} else if (typeof opCode == 'number') {
|
||||
switch (opCode & I18nMutateOpCode.MASK_OPCODE) {
|
||||
case I18nMutateOpCode.AppendChild:
|
||||
|
@ -726,17 +726,13 @@ function readCreateOpCodes(
|
|||
previousTNode = currentTNode;
|
||||
currentTNode = getTNode(nodeIndex, viewData);
|
||||
if (currentTNode) {
|
||||
setPreviousOrParentTNode(currentTNode);
|
||||
if (currentTNode.type === TNodeType.Element) {
|
||||
setIsParent(true);
|
||||
}
|
||||
setPreviousOrParentTNode(currentTNode, currentTNode.type === TNodeType.Element);
|
||||
}
|
||||
break;
|
||||
case I18nMutateOpCode.ElementEnd:
|
||||
const elementIndex = opCode >>> I18nMutateOpCode.SHIFT_REF;
|
||||
previousTNode = currentTNode = getTNode(elementIndex, viewData);
|
||||
setPreviousOrParentTNode(currentTNode);
|
||||
setIsParent(false);
|
||||
setPreviousOrParentTNode(currentTNode, false);
|
||||
break;
|
||||
case I18nMutateOpCode.Attr:
|
||||
const elementNodeIndex = opCode >>> I18nMutateOpCode.SHIFT_REF;
|
||||
|
@ -764,7 +760,7 @@ function readCreateOpCodes(
|
|||
attachPatchData(commentRNode, viewData);
|
||||
(currentTNode as TIcuContainerNode).activeCaseIndex = null;
|
||||
// We will add the case nodes later, during the update phase
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
break;
|
||||
case ELEMENT_MARKER:
|
||||
const tagNameValue = createOpCodes[++i] as string;
|
||||
|
@ -785,7 +781,7 @@ function readCreateOpCodes(
|
|||
}
|
||||
}
|
||||
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
|
||||
return visitedNodes;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import {LocalRefExtractor, TAttributes, TContainerNode, TNode, TNodeType} from '
|
|||
import {BINDING_INDEX, HEADER_OFFSET, LView, QUERIES, RENDERER, TVIEW} from '../interfaces/view';
|
||||
import {assertNodeType} from '../node_assert';
|
||||
import {appendChild, removeView} from '../node_manipulation';
|
||||
import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from '../state';
|
||||
import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';
|
||||
import {getNativeByTNode, loadInternal} from '../util/view_utils';
|
||||
import {addToViewTree, createDirectivesAndLocals, createLContainer, createNodeAtIndex, createTView} from './shared';
|
||||
|
||||
|
@ -37,7 +37,7 @@ export function ɵɵcontainer(index: number): void {
|
|||
tNode.tViews = [];
|
||||
}
|
||||
addTContainerToQueries(lView, tNode);
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ export function ɵɵtemplate(
|
|||
addTContainerToQueries(lView, tContainerNode);
|
||||
attachPatchData(getNativeByTNode(tContainerNode, lView), lView);
|
||||
registerPostOrderHooks(tView, tContainerNode);
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,10 +91,8 @@ export function ɵɵcontainerRefreshStart(index: number): void {
|
|||
const lView = getLView();
|
||||
const tView = lView[TVIEW];
|
||||
let previousOrParentTNode = loadInternal(tView.data, index) as TNode;
|
||||
setPreviousOrParentTNode(previousOrParentTNode);
|
||||
|
||||
ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.Container);
|
||||
setIsParent(true);
|
||||
setPreviousOrParentTNode(previousOrParentTNode, true);
|
||||
|
||||
lView[index + HEADER_OFFSET][ACTIVE_INDEX] = 0;
|
||||
|
||||
|
@ -113,12 +111,12 @@ export function ɵɵcontainerRefreshStart(index: number): void {
|
|||
export function ɵɵcontainerRefreshEnd(): void {
|
||||
let previousOrParentTNode = getPreviousOrParentTNode();
|
||||
if (getIsParent()) {
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
} else {
|
||||
ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.View);
|
||||
ngDevMode && assertHasParent(previousOrParentTNode);
|
||||
previousOrParentTNode = previousOrParentTNode.parent !;
|
||||
setPreviousOrParentTNode(previousOrParentTNode);
|
||||
setPreviousOrParentTNode(previousOrParentTNode, false);
|
||||
}
|
||||
|
||||
ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.Container);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {validateAgainstEventAttributes} from '../../sanitization/sanitization';
|
||||
import {assertDataInRange, assertEqual} from '../../util/assert';
|
||||
import {assertDataInRange, assertDefined, assertEqual} from '../../util/assert';
|
||||
import {assertHasParent} from '../assert';
|
||||
import {attachPatchData} from '../context_discovery';
|
||||
import {registerPostOrderHooks} from '../hooks';
|
||||
|
@ -18,7 +18,7 @@ import {BINDING_INDEX, QUERIES, RENDERER, TVIEW} from '../interfaces/view';
|
|||
import {assertNodeType} from '../node_assert';
|
||||
import {appendChild} from '../node_manipulation';
|
||||
import {applyOnCreateInstructions} from '../node_util';
|
||||
import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsParent, setPreviousOrParentTNode} from '../state';
|
||||
import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state';
|
||||
import {getInitialClassNameValue, getInitialStyleStringValue, initializeStaticContext, patchContextWithStaticAttrs, renderInitialClasses, renderInitialStyles} from '../styling/class_and_style_bindings';
|
||||
import {getStylingContextFromLView, hasClassInput, hasStyleInput} from '../styling/util';
|
||||
import {registerInitialStylingIntoContext} from '../styling_next/instructions';
|
||||
|
@ -139,12 +139,13 @@ export function ɵɵelementStart(
|
|||
*/
|
||||
export function ɵɵelementEnd(): void {
|
||||
let previousOrParentTNode = getPreviousOrParentTNode();
|
||||
ngDevMode && assertDefined(previousOrParentTNode, 'No parent node to close.');
|
||||
if (getIsParent()) {
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
} else {
|
||||
ngDevMode && assertHasParent(getPreviousOrParentTNode());
|
||||
previousOrParentTNode = previousOrParentTNode.parent !;
|
||||
setPreviousOrParentTNode(previousOrParentTNode);
|
||||
setPreviousOrParentTNode(previousOrParentTNode, false);
|
||||
}
|
||||
|
||||
// this is required for all host-level styling-related instructions to run
|
||||
|
|
|
@ -14,7 +14,8 @@ import {BINDING_INDEX, QUERIES, RENDERER, TVIEW} from '../interfaces/view';
|
|||
import {assertNodeType} from '../node_assert';
|
||||
import {appendChild} from '../node_manipulation';
|
||||
import {applyOnCreateInstructions} from '../node_util';
|
||||
import {getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from '../state';
|
||||
import {getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';
|
||||
|
||||
import {createDirectivesAndLocals, createNodeAtIndex, executeContentQueries, setNodeStylingTemplate} from './shared';
|
||||
|
||||
/**
|
||||
|
@ -77,11 +78,11 @@ export function ɵɵelementContainerEnd(): void {
|
|||
const lView = getLView();
|
||||
const tView = lView[TVIEW];
|
||||
if (getIsParent()) {
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
} else {
|
||||
ngDevMode && assertHasParent(previousOrParentTNode);
|
||||
previousOrParentTNode = previousOrParentTNode.parent !;
|
||||
setPreviousOrParentTNode(previousOrParentTNode);
|
||||
setPreviousOrParentTNode(previousOrParentTNode, false);
|
||||
}
|
||||
|
||||
ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.ElementContainer);
|
||||
|
|
|
@ -40,7 +40,7 @@ export function ɵɵembeddedViewStart(
|
|||
let viewToRender = scanForView(lContainer, lContainer[ACTIVE_INDEX] !, viewBlockId);
|
||||
|
||||
if (viewToRender) {
|
||||
setIsParent(true);
|
||||
setIsParent();
|
||||
enterView(viewToRender, viewToRender[TVIEW].node);
|
||||
} else {
|
||||
// When we create a new LView, we always reset the state of the instructions.
|
||||
|
@ -141,6 +141,5 @@ export function ɵɵembeddedViewEnd(): void {
|
|||
const lContainer = lView[PARENT] as LContainer;
|
||||
ngDevMode && assertLContainerOrUndefined(lContainer);
|
||||
leaveView(lContainer[PARENT] !);
|
||||
setPreviousOrParentTNode(viewHost !);
|
||||
setIsParent(false);
|
||||
setPreviousOrParentTNode(viewHost !, false);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import {CssSelectorList} from '../interfaces/projection';
|
|||
import {T_HOST} from '../interfaces/view';
|
||||
import {appendProjectedNodes} from '../node_manipulation';
|
||||
import {matchingProjectionSelectorIndex} from '../node_selector_matcher';
|
||||
import {getLView, setIsParent} from '../state';
|
||||
import {getLView, setIsNotParent} from '../state';
|
||||
import {findComponentView} from '../util/view_traversal_utils';
|
||||
|
||||
import {createNodeAtIndex} from './shared';
|
||||
|
@ -88,7 +88,7 @@ export function ɵɵprojection(
|
|||
if (tProjectionNode.projection === null) tProjectionNode.projection = selectorIndex;
|
||||
|
||||
// `<ng-content>` has no content
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
|
||||
// re-distribution of projectable nodes is stored on a component's view level
|
||||
appendProjectedNodes(lView, tProjectionNode, selectorIndex, findComponentView(lView));
|
||||
|
|
|
@ -287,8 +287,7 @@ export function createNodeAtIndex(
|
|||
}
|
||||
}
|
||||
|
||||
setPreviousOrParentTNode(tNode);
|
||||
setIsParent(true);
|
||||
setPreviousOrParentTNode(tNode, true);
|
||||
return tNode as TElementNode & TViewNode & TContainerNode & TElementContainerNode &
|
||||
TProjectionNode & TIcuContainerNode;
|
||||
}
|
||||
|
@ -351,8 +350,7 @@ export function createEmbeddedViewAndNode<T>(
|
|||
injectorIndex: number): LView {
|
||||
const _isParent = getIsParent();
|
||||
const _previousOrParentTNode = getPreviousOrParentTNode();
|
||||
setIsParent(true);
|
||||
setPreviousOrParentTNode(null !);
|
||||
setPreviousOrParentTNode(null !, true);
|
||||
|
||||
const lView = createLView(declarationView, tView, context, LViewFlags.CheckAlways, null, null);
|
||||
lView[DECLARATION_VIEW] = declarationView;
|
||||
|
@ -366,8 +364,7 @@ export function createEmbeddedViewAndNode<T>(
|
|||
tView.node !.injectorIndex = injectorIndex;
|
||||
}
|
||||
|
||||
setIsParent(_isParent);
|
||||
setPreviousOrParentTNode(_previousOrParentTNode);
|
||||
setPreviousOrParentTNode(_previousOrParentTNode, _isParent);
|
||||
return lView;
|
||||
}
|
||||
|
||||
|
@ -390,8 +387,7 @@ export function renderEmbeddedTemplate<T>(viewToRender: LView, tView: TView, con
|
|||
tickRootContext(getRootContext(viewToRender));
|
||||
} else {
|
||||
try {
|
||||
setIsParent(true);
|
||||
setPreviousOrParentTNode(null !);
|
||||
setPreviousOrParentTNode(null !, true);
|
||||
|
||||
oldView = enterView(viewToRender, viewToRender[T_HOST]);
|
||||
resetPreOrderHookFlags(viewToRender);
|
||||
|
@ -406,8 +402,7 @@ export function renderEmbeddedTemplate<T>(viewToRender: LView, tView: TView, con
|
|||
refreshDescendantViews(viewToRender);
|
||||
} finally {
|
||||
leaveView(oldView !);
|
||||
setIsParent(_isParent);
|
||||
setPreviousOrParentTNode(_previousOrParentTNode);
|
||||
setPreviousOrParentTNode(_previousOrParentTNode, _isParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1254,7 +1249,7 @@ function addComponentLogic<T>(
|
|||
lView, createLView(
|
||||
lView, tView, null, def.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways,
|
||||
lView[previousOrParentTNode.index], previousOrParentTNode as TElementNode,
|
||||
rendererFactory, lView[RENDERER_FACTORY].createRenderer(native as RElement, def)));
|
||||
rendererFactory, rendererFactory.createRenderer(native as RElement, def)));
|
||||
|
||||
componentView[T_HOST] = previousOrParentTNode as TElementNode;
|
||||
|
||||
|
@ -1695,17 +1690,14 @@ export function storeBindingMetadata(lView: LView, prefix = '', suffix = ''): st
|
|||
|
||||
export const CLEAN_PROMISE = _CLEAN_PROMISE;
|
||||
|
||||
export function initializeTNodeInputs(tNode: TNode | null): PropertyAliases|null {
|
||||
export function initializeTNodeInputs(tNode: TNode): PropertyAliases|null {
|
||||
// If tNode.inputs is undefined, a listener has created outputs, but inputs haven't
|
||||
// yet been checked.
|
||||
if (tNode) {
|
||||
if (tNode.inputs === undefined) {
|
||||
// mark inputs as checked
|
||||
tNode.inputs = generatePropertyAliases(tNode, BindingDirection.Input);
|
||||
}
|
||||
return tNode.inputs;
|
||||
if (tNode.inputs === undefined) {
|
||||
// mark inputs as checked
|
||||
tNode.inputs = generatePropertyAliases(tNode, BindingDirection.Input);
|
||||
}
|
||||
return null;
|
||||
return tNode.inputs;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import {TNodeType} from '../interfaces/node';
|
|||
import {RText, isProceduralRenderer} from '../interfaces/renderer';
|
||||
import {BINDING_INDEX, HEADER_OFFSET, RENDERER, TVIEW} from '../interfaces/view';
|
||||
import {appendChild, createTextNode} from '../node_manipulation';
|
||||
import {getLView, setIsParent} from '../state';
|
||||
import {getLView, setIsNotParent} from '../state';
|
||||
import {NO_CHANGE} from '../tokens';
|
||||
import {renderStringify} from '../util/misc_utils';
|
||||
import {getNativeByIndex} from '../util/view_utils';
|
||||
|
@ -34,7 +34,7 @@ export function ɵɵtext(index: number, value?: any): void {
|
|||
const tNode = createNodeAtIndex(index, TNodeType.Element, textNative, null, null);
|
||||
|
||||
// Text nodes are self closing.
|
||||
setIsParent(false);
|
||||
setIsNotParent();
|
||||
appendChild(textNative, tNode, lView);
|
||||
}
|
||||
|
||||
|
|
|
@ -303,8 +303,9 @@ export function getPreviousOrParentTNode(): TNode {
|
|||
return previousOrParentTNode;
|
||||
}
|
||||
|
||||
export function setPreviousOrParentTNode(tNode: TNode) {
|
||||
export function setPreviousOrParentTNode(tNode: TNode, _isParent: boolean) {
|
||||
previousOrParentTNode = tNode;
|
||||
isParent = _isParent;
|
||||
}
|
||||
|
||||
export function setTNodeAndViewData(tNode: TNode, view: LView) {
|
||||
|
@ -325,8 +326,11 @@ export function getIsParent(): boolean {
|
|||
return isParent;
|
||||
}
|
||||
|
||||
export function setIsParent(value: boolean): void {
|
||||
isParent = value;
|
||||
export function setIsNotParent(): void {
|
||||
isParent = false;
|
||||
}
|
||||
export function setIsParent(): void {
|
||||
isParent = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -693,7 +693,7 @@
|
|||
"name": "setInputsFromAttrs"
|
||||
},
|
||||
{
|
||||
"name": "setIsParent"
|
||||
"name": "setIsNotParent"
|
||||
},
|
||||
{
|
||||
"name": "setNodeStylingTemplate"
|
||||
|
|
|
@ -468,7 +468,7 @@
|
|||
"name": "setInjectImplementation"
|
||||
},
|
||||
{
|
||||
"name": "setIsParent"
|
||||
"name": "setIsNotParent"
|
||||
},
|
||||
{
|
||||
"name": "setPreviousOrParentTNode"
|
||||
|
|
|
@ -1386,7 +1386,7 @@
|
|||
"name": "setInputsFromAttrs"
|
||||
},
|
||||
{
|
||||
"name": "setIsParent"
|
||||
"name": "setIsNotParent"
|
||||
},
|
||||
{
|
||||
"name": "setNodeStylingTemplate"
|
||||
|
|
Loading…
Reference in New Issue