refactor(core): view engine - remove `ViewData.parentDiIndex` (#14225)
Instead, calculate it on the fly Part of #14013
This commit is contained in:
parent
45e1e36477
commit
ae7f5f37d2
|
@ -220,7 +220,7 @@ export function resolveDep(
|
||||||
if (elDef.parent != null) {
|
if (elDef.parent != null) {
|
||||||
elIndex = elDef.parent;
|
elIndex = elDef.parent;
|
||||||
} else {
|
} else {
|
||||||
elIndex = view.parentDiIndex;
|
elIndex = parentDiIndex(view);
|
||||||
view = view.parent;
|
view = view.parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,12 +246,26 @@ export function resolveDep(
|
||||||
return asProviderData(view, providerIndex).instance;
|
return asProviderData(view, providerIndex).instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elIndex = view.parentDiIndex;
|
elIndex = parentDiIndex(view);
|
||||||
view = view.parent;
|
view = view.parent;
|
||||||
}
|
}
|
||||||
return Injector.NULL.get(depDef.token, notFoundValue);
|
return Injector.NULL.get(depDef.token, notFoundValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for component views, this is the same as parentIndex.
|
||||||
|
* for embedded views, this is the index of the parent node
|
||||||
|
* that contains the view container.
|
||||||
|
*/
|
||||||
|
function parentDiIndex(view: ViewData): number {
|
||||||
|
if (view.parent) {
|
||||||
|
const parentNodeDef = view.def.nodes[view.parentIndex];
|
||||||
|
return parentNodeDef.element && parentNodeDef.element.template ? parentNodeDef.parent :
|
||||||
|
parentNodeDef.index;
|
||||||
|
}
|
||||||
|
return view.parentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
export function createInjector(view: ViewData, elIndex: number): Injector {
|
export function createInjector(view: ViewData, elIndex: number): Injector {
|
||||||
return new Injector_(view, elIndex);
|
return new Injector_(view, elIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,10 +259,6 @@ export interface ViewData {
|
||||||
// index of parent element / anchor. Not the index
|
// index of parent element / anchor. Not the index
|
||||||
// of the provider with the component view.
|
// of the provider with the component view.
|
||||||
parentIndex: number;
|
parentIndex: number;
|
||||||
// for component views, this is the same as parentIndex.
|
|
||||||
// for embedded views, this is the index of the parent node
|
|
||||||
// that contains the view container.
|
|
||||||
parentDiIndex: number;
|
|
||||||
parent: ViewData;
|
parent: ViewData;
|
||||||
component: any;
|
component: any;
|
||||||
context: any;
|
context: any;
|
||||||
|
|
|
@ -223,8 +223,7 @@ function cloneAndModifyElement(
|
||||||
export function createEmbeddedView(parent: ViewData, anchorDef: NodeDef, context?: any): ViewData {
|
export function createEmbeddedView(parent: ViewData, anchorDef: NodeDef, context?: any): ViewData {
|
||||||
// embedded views are seen as siblings to the anchor, so we need
|
// embedded views are seen as siblings to the anchor, so we need
|
||||||
// to get the parent of the anchor and use it as parentIndex.
|
// to get the parent of the anchor and use it as parentIndex.
|
||||||
const view = createView(
|
const view = createView(parent.services, parent, anchorDef.index, anchorDef.element.template);
|
||||||
parent.services, parent, anchorDef.index, anchorDef.parent, anchorDef.element.template);
|
|
||||||
initView(view, parent.component, context);
|
initView(view, parent.component, context);
|
||||||
createViewNodes(view);
|
createViewNodes(view);
|
||||||
return view;
|
return view;
|
||||||
|
@ -236,15 +235,14 @@ export function createEmbeddedView(parent: ViewData, anchorDef: NodeDef, context
|
||||||
*/
|
*/
|
||||||
export function createRootView(
|
export function createRootView(
|
||||||
services: Services, defFactory: ViewDefinitionFactory, context?: any): ViewData {
|
services: Services, defFactory: ViewDefinitionFactory, context?: any): ViewData {
|
||||||
const view = createView(services, null, null, null, resolveViewDefinition(defFactory));
|
const view = createView(services, null, null, resolveViewDefinition(defFactory));
|
||||||
initView(view, context, context);
|
initView(view, context, context);
|
||||||
createViewNodes(view);
|
createViewNodes(view);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createView(
|
function createView(
|
||||||
services: Services, parent: ViewData, parentIndex: number, parentDiIndex: number,
|
services: Services, parent: ViewData, parentIndex: number, def: ViewDefinition): ViewData {
|
||||||
def: ViewDefinition): ViewData {
|
|
||||||
const nodes: NodeData[] = new Array(def.nodes.length);
|
const nodes: NodeData[] = new Array(def.nodes.length);
|
||||||
let renderer: Renderer;
|
let renderer: Renderer;
|
||||||
if (def.flags != null && (def.flags & ViewFlags.DirectDom)) {
|
if (def.flags != null && (def.flags & ViewFlags.DirectDom)) {
|
||||||
|
@ -257,7 +255,6 @@ function createView(
|
||||||
def,
|
def,
|
||||||
parent,
|
parent,
|
||||||
parentIndex,
|
parentIndex,
|
||||||
parentDiIndex,
|
|
||||||
context: undefined,
|
context: undefined,
|
||||||
component: undefined, nodes,
|
component: undefined, nodes,
|
||||||
state: ViewState.FirstCheck, renderer, services,
|
state: ViewState.FirstCheck, renderer, services,
|
||||||
|
@ -303,8 +300,7 @@ function _createViewNodes(view: ViewData) {
|
||||||
if (nodeDef.provider.component) {
|
if (nodeDef.provider.component) {
|
||||||
const hostElIndex = nodeDef.parent;
|
const hostElIndex = nodeDef.parent;
|
||||||
componentView = createView(
|
componentView = createView(
|
||||||
view.services, view, hostElIndex, hostElIndex,
|
view.services, view, hostElIndex, resolveViewDefinition(nodeDef.provider.component));
|
||||||
resolveViewDefinition(nodeDef.provider.component));
|
|
||||||
}
|
}
|
||||||
const providerData = nodeData = createProvider(view, nodeDef, componentView);
|
const providerData = nodeData = createProvider(view, nodeDef, componentView);
|
||||||
if (componentView) {
|
if (componentView) {
|
||||||
|
|
Loading…
Reference in New Issue