Skip to content

Commit

Permalink
fixup! perf(ivy): apply static styles/classes directly to an element'…
Browse files Browse the repository at this point in the history
…s style/className properties
  • Loading branch information
matsko committed Oct 25, 2019
1 parent 1204c2b commit 7527437
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/element.ts
Expand Up @@ -65,7 +65,7 @@ export function ɵɵelementStart(
}

if ((tNode.flags & TNodeFlags.hasInitialStyling) === TNodeFlags.hasInitialStyling) {
renderInitialStyling(renderer, native, tNode);
renderInitialStyling(renderer, native, tNode, false);
}

appendChild(native, tNode, lView);
Expand Down Expand Up @@ -222,7 +222,7 @@ export function ɵɵelementHostAttrs(attrs: TAttributes) {
// attribute values to the element.
if (stylingNeedsToBeRendered) {
const renderer = lView[RENDERER];
renderInitialStyling(renderer, native, tNode);
renderInitialStyling(renderer, native, tNode, true);
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions packages/core/src/render3/instructions/shared.ts
Expand Up @@ -31,7 +31,7 @@ import {BINDING_INDEX, CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_VIE
import {assertNodeOfPossibleTypes} from '../node_assert';
import {isNodeMatchingSelectorList} from '../node_selector_matcher';
import {ActiveElementFlags, enterView, executeElementExitFn, getBindingsEnabled, getCheckNoChangesMode, getIsParent, getPreviousOrParentTNode, getSelectedIndex, hasActiveElementFlag, incrementActiveDirectiveId, leaveView, leaveViewProcessExit, setActiveHostElement, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setCurrentQueryIndex, setPreviousOrParentTNode, setSelectedIndex} from '../state';
import {writeStylingValueDirectly} from '../styling/bindings';
import {writeStylingValueDirectly, renderStylingMap} from '../styling/bindings';
import {NO_CHANGE} from '../tokens';
import {isAnimationProp} from '../util/attrs_utils';
import {INTERPOLATION_DELIMITER, renderStringify, stringifyForError} from '../util/misc_utils';
Expand Down Expand Up @@ -1833,13 +1833,21 @@ export function textBindingInternal(lView: LView, index: number, value: string):
* applied once the element is instantiated. This function applies each of the static
* style and class entries to the element.
*/
export function renderInitialStyling(renderer: Renderer3, native: RElement, tNode: TNode) {
if (tNode.classes) {
const classes = getInitialStylingValue(tNode.classes);
writeStylingValueDirectly(renderer, native, classes, true, null);
export function renderInitialStyling(renderer: Renderer3, native: RElement, tNode: TNode, append: boolean) {
if (tNode.classes !== null) {
if (append) {
renderStylingMap(renderer, native, tNode.classes, true);
} else {
const classes = getInitialStylingValue(tNode.classes);
writeStylingValueDirectly(renderer, native, classes, true, null);
}
}
if (tNode.styles) {
const styles = getInitialStylingValue(tNode.styles);
writeStylingValueDirectly(renderer, native, styles, false, null);
if (tNode.styles !== null) {
if (append) {
renderStylingMap(renderer, native, tNode.styles, false);
} else {
const styles = getInitialStylingValue(tNode.styles);
writeStylingValueDirectly(renderer, native, styles, false, null);
}
}
}

0 comments on commit 7527437

Please sign in to comment.