Skip to content

Commit

Permalink
fixup! feat(ivy): properly apply style="", [style], [style.foo] and […
Browse files Browse the repository at this point in the history
…attr.style] bindings
  • Loading branch information
matsko committed Jun 22, 2018
1 parent 49d1621 commit daef3f8
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 176 deletions.
32 changes: 10 additions & 22 deletions packages/core/src/render3/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {ComponentDefInternal, ComponentTemplate, ComponentQuery, DirectiveDefInt
import {RComment, RElement, RText, Renderer3, RendererFactory3, ProceduralRenderer3, RendererStyleFlags3, isProceduralRenderer} from './interfaces/renderer';
import {isDifferent, stringify} from './util';
import {ViewRef} from './view_ref';
import {ElementStyleRecord, updateElementStyleMap, updateElementStyleProp, renderElementStyles} from './styling';
import {StylingContext, initializeStylingContext, updateStyleMap as updateElementStyleMap, updateStyleProp as updateElementStyleProp, renderStyles as renderElementStyles} from './styling';

/**
* Directive (D) sets a property on all component instances using this constant as a key and the
Expand Down Expand Up @@ -1287,19 +1287,8 @@ export function elementClass<T>(index: number, value: T | NO_CHANGE): void {
* values that are passed in here will be applied to the element (if matched).
*/
export function elementStyling<T>(index: number, styles?: string[]): void {
const hasData = styles && styles.length;
let initialStyles: {[key: string]: any}|null = null;
if (hasData) {
initialStyles = {};
for (let i = 0; i < styles !.length; i += 2) {
const prop = styles ![i];
const value = styles ![i + 1];
initialStyles[prop] = value;
}
}
viewData[index + HEADER_OFFSET] =
{initial: initialStyles, multi: null, single: null, updated: hasData};
if (hasData) {
viewData[index + HEADER_OFFSET] = initializeStylingContext(styles);
if (styles && styles.length) {
elementStylingApply(index);
}
}
Expand All @@ -1319,11 +1308,9 @@ export function elementStyling<T>(index: number, styles?: string[]): void {
* index.)
*/
export function elementStylingApply<T>(index: number): void {
const record: ElementStyleRecord|null = viewData[index + HEADER_OFFSET];
if (record) {
const lElement: LElementNode = load(index - 1);
renderElementStyles(lElement, record, renderer);
}
const stylingContext: StylingContext = viewData[index + HEADER_OFFSET] !;
const lElement: LElementNode = load(index - 1);
renderElementStyles(lElement, stylingContext, renderer);
}

/**
Expand Down Expand Up @@ -1354,7 +1341,7 @@ export function elementStyleProp<T>(
export function elementStyleProp<T>(
index: number, styleName: string, value: T | null,
suffixOrSanitizer?: string | SanitizerFn): void {
const record: ElementStyleRecord = viewData[index + HEADER_OFFSET];
const stylingContext: StylingContext = viewData[index + HEADER_OFFSET] !;
let valueToAdd: string|null = null;
if (value) {
valueToAdd =
Expand All @@ -1363,7 +1350,7 @@ export function elementStyleProp<T>(
valueToAdd = valueToAdd + suffixOrSanitizer;
}
}
updateElementStyleProp(record !, styleName, valueToAdd);
updateElementStyleProp(stylingContext, styleName, valueToAdd);
}

/**
Expand All @@ -1385,7 +1372,8 @@ export function elementStyleProp<T>(
* are their corresponding values to set. If value is null, then the style is removed.
*/
export function elementStyle<T>(index: number, value: {[styleName: string]: any} | null): void {
updateElementStyleMap(viewData[index + HEADER_OFFSET] !, value);
const stylingContext: StylingContext = viewData[index + HEADER_OFFSET] !;
updateElementStyleMap(stylingContext, value);
}

//////////////////////////
Expand Down

0 comments on commit daef3f8

Please sign in to comment.