perf(ivy): apply static styles/classes directly to an element's style/className properties (#33364)
PR Close #33364
This commit is contained in:

committed by
Andrew Kushnir

parent
335854f6bc
commit
5607ad8c62
@ -700,20 +700,10 @@ export function applyStylingMapDirectly(
|
||||
}
|
||||
|
||||
if (writeToAttrDirectly) {
|
||||
let valueToApply: string;
|
||||
if (isClassBased) {
|
||||
valueToApply = typeof value === 'string' ? value : objectToClassName(value);
|
||||
if (initialValue !== null) {
|
||||
valueToApply = concatString(initialValue, valueToApply, ' ');
|
||||
}
|
||||
setClassName(renderer, element, valueToApply);
|
||||
} else {
|
||||
valueToApply = forceStylesAsString(value as{[key: string]: any}, true);
|
||||
if (initialValue !== null) {
|
||||
valueToApply = initialValue + ';' + valueToApply;
|
||||
}
|
||||
setStyleAttr(renderer, element, valueToApply);
|
||||
}
|
||||
const initialValue =
|
||||
hasInitial && !bindingValueContainsInitial ? getInitialStylingValue(context) : null;
|
||||
const valueToApply =
|
||||
writeStylingValueDirectly(renderer, element, value, isClassBased, initialValue);
|
||||
setValue(data, cachedValueIndex, valueToApply || null);
|
||||
} else {
|
||||
const applyFn = isClassBased ? setClass : setStyle;
|
||||
@ -751,6 +741,26 @@ export function applyStylingMapDirectly(
|
||||
}
|
||||
}
|
||||
|
||||
export function writeStylingValueDirectly(
|
||||
renderer: any, element: RElement, value: {[key: string]: any} | string | null,
|
||||
isClassBased: boolean, initialValue: string | null): string {
|
||||
let valueToApply: string;
|
||||
if (isClassBased) {
|
||||
valueToApply = typeof value === 'string' ? value : objectToClassName(value);
|
||||
if (initialValue !== null) {
|
||||
valueToApply = concatString(initialValue, valueToApply, ' ');
|
||||
}
|
||||
setClassName(renderer, element, valueToApply);
|
||||
} else {
|
||||
valueToApply = forceStylesAsString(value, true);
|
||||
if (initialValue !== null) {
|
||||
valueToApply = initialValue + ';' + valueToApply;
|
||||
}
|
||||
setStyleAttr(renderer, element, valueToApply);
|
||||
}
|
||||
return valueToApply;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the provided styling prop/value to the element directly (without context resolution).
|
||||
*
|
||||
|
Reference in New Issue
Block a user