From 7527437a0a96aed31f6c360dcb9ad93d6fde421c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Fri, 25 Oct 2019 12:08:19 -0700 Subject: [PATCH] fixup! perf(ivy): apply static styles/classes directly to an element's style/className properties --- .../core/src/render3/instructions/element.ts | 4 ++-- .../core/src/render3/instructions/shared.ts | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/core/src/render3/instructions/element.ts b/packages/core/src/render3/instructions/element.ts index 114351d6ca4bc..18c99c35ff610 100644 --- a/packages/core/src/render3/instructions/element.ts +++ b/packages/core/src/render3/instructions/element.ts @@ -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); @@ -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); } } } diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index f8f37c5c59c3c..410fbda1de689 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -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'; @@ -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); + } } }