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();
|
||||
const hostRNode = 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 :
|
||||
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 {assertNodeType} from '../node_assert';
|
||||
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 {StylingMapArray, TStylingContext} from '../styling_next/interfaces';
|
||||
import {getInitialStylingValue, hasClassInput, hasStyleInput} from '../styling_next/util';
|
||||
|
@ -52,8 +52,8 @@ export function ɵɵelementStart(
|
|||
|
||||
ngDevMode && ngDevMode.rendererCreateElement++;
|
||||
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
|
||||
const native = lView[index + HEADER_OFFSET] = elementCreate(name);
|
||||
const renderer = lView[RENDERER];
|
||||
const native = lView[index + HEADER_OFFSET] = elementCreate(name, renderer, getNamespace());
|
||||
const tNode =
|
||||
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.
|
||||
* @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
|
||||
*/
|
||||
export function elementCreate(name: string, overriddenRenderer?: Renderer3): RElement {
|
||||
let native: RElement;
|
||||
const rendererToUse = overriddenRenderer || getLView()[RENDERER];
|
||||
|
||||
const namespace = getNamespace();
|
||||
|
||||
if (isProceduralRenderer(rendererToUse)) {
|
||||
native = rendererToUse.createElement(name, namespace);
|
||||
export function elementCreate(
|
||||
name: string, renderer: Renderer3, namespace: string | null): RElement {
|
||||
if (isProceduralRenderer(renderer)) {
|
||||
return renderer.createElement(name, namespace);
|
||||
} else {
|
||||
if (namespace === null) {
|
||||
native = rendererToUse.createElement(name);
|
||||
} else {
|
||||
native = rendererToUse.createElementNS(namespace, name);
|
||||
}
|
||||
return namespace === null ? renderer.createElement(name) :
|
||||
renderer.createElementNS(namespace, name);
|
||||
}
|
||||
return native;
|
||||
}
|
||||
|
||||
export function createLView<T>(
|
||||
parentLView: LView | null, tView: TView, context: T | null, flags: LViewFlags,
|
||||
host: RElement | null, tHostNode: TViewNode | TElementNode | null,
|
||||
|
|
Loading…
Reference in New Issue