refactor(ivy): remove global state access in elementCreate (#31959)
PR Close #31959
This commit is contained in:
parent
9d1f43f3ba
commit
48a3741d5a
|
@ -138,7 +138,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
||||||
namespaceHTMLInternal();
|
namespaceHTMLInternal();
|
||||||
const hostRNode = rootSelectorOrNode ?
|
const hostRNode = rootSelectorOrNode ?
|
||||||
locateHostElement(rendererFactory, rootSelectorOrNode) :
|
locateHostElement(rendererFactory, rootSelectorOrNode) :
|
||||||
elementCreate(this.selector, rendererFactory.createRenderer(null, this.componentDef));
|
elementCreate(this.selector, rendererFactory.createRenderer(null, this.componentDef), null);
|
||||||
|
|
||||||
const rootFlags = this.componentDef.onPush ? LViewFlags.Dirty | LViewFlags.IsRoot :
|
const rootFlags = this.componentDef.onPush ? LViewFlags.Dirty | LViewFlags.IsRoot :
|
||||||
LViewFlags.CheckAlways | LViewFlags.IsRoot;
|
LViewFlags.CheckAlways | LViewFlags.IsRoot;
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {isContentQueryHost} from '../interfaces/type_checks';
|
||||||
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
|
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
|
||||||
import {assertNodeType} from '../node_assert';
|
import {assertNodeType} from '../node_assert';
|
||||||
import {appendChild} from '../node_manipulation';
|
import {appendChild} from '../node_manipulation';
|
||||||
import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state';
|
import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getNamespace, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state';
|
||||||
import {registerInitialStylingOnTNode} from '../styling_next/instructions';
|
import {registerInitialStylingOnTNode} from '../styling_next/instructions';
|
||||||
import {StylingMapArray, TStylingContext} from '../styling_next/interfaces';
|
import {StylingMapArray, TStylingContext} from '../styling_next/interfaces';
|
||||||
import {getInitialStylingValue, hasClassInput, hasStyleInput} from '../styling_next/util';
|
import {getInitialStylingValue, hasClassInput, hasStyleInput} from '../styling_next/util';
|
||||||
|
@ -52,8 +52,8 @@ export function ɵɵelementStart(
|
||||||
|
|
||||||
ngDevMode && ngDevMode.rendererCreateElement++;
|
ngDevMode && ngDevMode.rendererCreateElement++;
|
||||||
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
|
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
|
||||||
const native = lView[index + HEADER_OFFSET] = elementCreate(name);
|
|
||||||
const renderer = lView[RENDERER];
|
const renderer = lView[RENDERER];
|
||||||
|
const native = lView[index + HEADER_OFFSET] = elementCreate(name, renderer, getNamespace());
|
||||||
const tNode =
|
const tNode =
|
||||||
getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.Element, name, attrs || null);
|
getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.Element, name, attrs || null);
|
||||||
|
|
||||||
|
|
|
@ -197,26 +197,19 @@ function refreshChildComponents(hostLView: LView, components: number[]): void {
|
||||||
/**
|
/**
|
||||||
* Creates a native element from a tag name, using a renderer.
|
* Creates a native element from a tag name, using a renderer.
|
||||||
* @param name the tag name
|
* @param name the tag name
|
||||||
* @param overriddenRenderer Optional A renderer to override the default one
|
* @param renderer A renderer to use
|
||||||
* @returns the element created
|
* @returns the element created
|
||||||
*/
|
*/
|
||||||
export function elementCreate(name: string, overriddenRenderer?: Renderer3): RElement {
|
export function elementCreate(
|
||||||
let native: RElement;
|
name: string, renderer: Renderer3, namespace: string | null): RElement {
|
||||||
const rendererToUse = overriddenRenderer || getLView()[RENDERER];
|
if (isProceduralRenderer(renderer)) {
|
||||||
|
return renderer.createElement(name, namespace);
|
||||||
const namespace = getNamespace();
|
|
||||||
|
|
||||||
if (isProceduralRenderer(rendererToUse)) {
|
|
||||||
native = rendererToUse.createElement(name, namespace);
|
|
||||||
} else {
|
} else {
|
||||||
if (namespace === null) {
|
return namespace === null ? renderer.createElement(name) :
|
||||||
native = rendererToUse.createElement(name);
|
renderer.createElementNS(namespace, name);
|
||||||
} else {
|
|
||||||
native = rendererToUse.createElementNS(namespace, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return native;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createLView<T>(
|
export function createLView<T>(
|
||||||
parentLView: LView | null, tView: TView, context: T | null, flags: LViewFlags,
|
parentLView: LView | null, tView: TView, context: T | null, flags: LViewFlags,
|
||||||
host: RElement | null, tHostNode: TViewNode | TElementNode | null,
|
host: RElement | null, tHostNode: TViewNode | TElementNode | null,
|
||||||
|
|
Loading…
Reference in New Issue