refactor(ivy): remove elementIndex param from all element-level styling instructions (#30313)

This patch is one commit of many patches that will unify all styling instructions
across both template-level bindings and host-level bindings. This patch in particular
removes the `elementIndex` param because it is already set prior to each styling
instruction via the `select(n)` instruction.

PR Close #30313
This commit is contained in:
Matias Niemelä
2019-05-07 14:02:11 -07:00
committed by Alex Rickabaugh
parent de651122a5
commit 7c8a62d64d
11 changed files with 174 additions and 167 deletions

View File

@ -154,7 +154,6 @@ function initElementStyling(
*
* Note that the styling element is updated as part of `elementStylingApply`.
*
* @param index Index of the element's with which styling is associated.
* @param styleIndex Index of style to update. This index value refers to the
* index of the style in the style bindings array that was passed into
* `elementStyling`.
@ -171,8 +170,9 @@ function initElementStyling(
* @codeGenApi
*/
export function ɵɵelementStyleProp(
index: number, styleIndex: number, value: string | number | String | PlayerFactory | null,
styleIndex: number, value: string | number | String | PlayerFactory | null,
suffix?: string | null, forceOverride?: boolean): void {
const index = getSelectedIndex();
const valueToAdd = resolveStylePropValue(value, suffix);
const stylingContext = getStylingContext(index, getLView());
updateElementStyleProp(
@ -244,7 +244,6 @@ function resolveStylePropValue(
* therefore, the class binding itself must already be allocated using
* `elementStyling` within the creation block.
*
* @param index Index of the element's with which styling is associated.
* @param classIndex Index of class to toggle. This index value refers to the
* index of the class in the class bindings array that was passed into
* `elementStyling` (which is meant to be called before this
@ -256,8 +255,8 @@ function resolveStylePropValue(
* @codeGenApi
*/
export function ɵɵelementClassProp(
index: number, classIndex: number, value: boolean | PlayerFactory,
forceOverride?: boolean): void {
classIndex: number, value: boolean | PlayerFactory, forceOverride?: boolean): void {
const index = getSelectedIndex();
const input = (value instanceof BoundPlayerFactory) ?
(value as BoundPlayerFactory<boolean|null>) :
booleanOrNull(value);
@ -316,15 +315,14 @@ function booleanOrNull(value: any): boolean|null {
*
* Note that the styling instruction will not be applied until `elementStylingApply` is called.
*
* @param index Index of the element's with which styling is associated.
* @param styles A key/value style map of the styles that will be applied to the given element.
* Any missing styles (that have already been applied to the element beforehand) will be
* removed (unset) from the element's styling.
*
* @codeGenApi
*/
export function ɵɵelementStyleMap(
index: number, styles: {[styleName: string]: any} | NO_CHANGE | null): void {
export function ɵɵelementStyleMap(styles: {[styleName: string]: any} | NO_CHANGE | null): void {
const index = getSelectedIndex();
const lView = getLView();
const stylingContext = getStylingContext(index, lView);
const tNode = getTNode(index, lView);
@ -354,15 +352,15 @@ export function ɵɵelementStyleMap(
*
* Note that the styling instruction will not be applied until `elementStylingApply` is called.
*
* @param index Index of the element's with which styling is associated.
* @param classes A key/value map or string of CSS classes that will be added to the
* given element. Any missing classes (that have already been applied to the element
* beforehand) will be removed (unset) from the element's list of CSS classes.
*
* @codeGenApi
*/
export function ɵɵelementClassMap(
index: number, classes: {[styleName: string]: any} | NO_CHANGE | string | null): void {
export function ɵɵelementClassMap(classes: {[styleName: string]: any} | NO_CHANGE | string | null):
void {
const index = getSelectedIndex();
const lView = getLView();
const stylingContext = getStylingContext(index, lView);
const tNode = getTNode(index, lView);
@ -442,11 +440,10 @@ export function ɵɵelementHostClassMap(classes: {[key: string]: any} | string |
* `elementStyleProp` or `elementClassProp` instructions have been run and will
* only apply styling to the element if any styling bindings have been updated.
*
* @param index Index of the element's with which styling is associated.
*
* @codeGenApi
*/
export function ɵɵelementStylingApply(index: number): void {
export function ɵɵelementStylingApply(): void {
const index = getSelectedIndex();
elementStylingApplyInternal(DEFAULT_TEMPLATE_DIRECTIVE_INDEX, index);
}

View File

@ -7,7 +7,7 @@
*/
import {StaticInjector} from '../../src/di/injector';
import {createInjector} from '../../src/di/r3_injector';
import {AttributeMarker, RenderFlags, getHostElement, ɵɵProvidersFeature, ɵɵdefineComponent, ɵɵdefineDirective, ɵɵelementContainerEnd, ɵɵelementContainerStart, ɵɵi18n, ɵɵi18nApply, ɵɵi18nExp} from '../../src/render3/index';
import {AttributeMarker, RenderFlags, getHostElement, ɵɵProvidersFeature, ɵɵdefineComponent, ɵɵdefineDirective, ɵɵelementContainerEnd, ɵɵelementContainerStart, ɵɵi18n, ɵɵi18nApply, ɵɵi18nExp, ɵɵselect} from '../../src/render3/index';
import {markDirty, ɵɵbind, ɵɵelement, ɵɵelementEnd, ɵɵelementProperty, ɵɵelementStart, ɵɵelementStyling, ɵɵelementStylingApply, ɵɵlistener, ɵɵtemplate, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
import {getComponent, getContext, getDirectives, getInjectionTokens, getInjector, getListeners, getLocalRefs, getRootComponents, getViewComponent, loadLContext} from '../../src/render3/util/discovery_utils';
@ -556,7 +556,8 @@ describe('discovery utils deprecated', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStylingApply();
}
}
});

View File

@ -1016,15 +1016,17 @@ describe('instructions', () => {
return createDiv(null, null, null, ['background-image'], ɵɵdefaultStyleSanitizer);
}, () => {}, 1);
t.update(() => {
ɵɵelementStyleProp(0, 0, 'url("http://server")');
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, 'url("http://server")');
ɵɵelementStylingApply();
});
// nothing is set because sanitizer suppresses it.
expect(t.html).toEqual('<div></div>');
t.update(() => {
ɵɵelementStyleProp(0, 0, bypassSanitizationTrustStyle('url("http://server2")'));
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, bypassSanitizationTrustStyle('url("http://server2")'));
ɵɵelementStylingApply();
});
expect((t.hostElement.firstChild as HTMLElement).style.getPropertyValue('background-image'))
.toEqual('url("http://server2")');
@ -1038,16 +1040,18 @@ describe('instructions', () => {
1, sanitizerInterceptor);
t.update(() => {
ɵɵelementStyleProp(0, 0, bypassSanitizationTrustStyle('apple'));
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, bypassSanitizationTrustStyle('apple'));
ɵɵelementStylingApply();
});
expect(sanitizerInterceptor.lastValue !).toEqual('apple');
sanitizerInterceptor.lastValue = null;
t.update(() => {
ɵɵelementStyleProp(0, 0, bypassSanitizationTrustStyle('apple'));
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, bypassSanitizationTrustStyle('apple'));
ɵɵelementStylingApply();
});
expect(sanitizerInterceptor.lastValue).toEqual(null);
});
@ -1063,8 +1067,9 @@ describe('instructions', () => {
it('should add style', () => {
const fixture = new TemplateFixture(createDivWithStyle, () => {}, 1);
fixture.update(() => {
ɵɵelementStyleMap(0, {'background-color': 'red'});
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleMap({'background-color': 'red'});
ɵɵelementStylingApply();
});
expect(fixture.html).toEqual('<div style="background-color: red; height: 10px;"></div>');
});
@ -1078,7 +1083,8 @@ describe('instructions', () => {
sanitizerInterceptor);
fixture.update(() => {
ɵɵelementStyleMap(0, {
ɵɵselect(0);
ɵɵelementStyleMap({
'background-image': 'background-image',
'background': 'background',
'border-image': 'border-image',
@ -1087,7 +1093,7 @@ describe('instructions', () => {
'filter': 'filter',
'width': 'width'
});
ɵɵelementStylingApply(0);
ɵɵelementStylingApply();
});
const props = detectedValues.sort();
@ -1107,8 +1113,9 @@ describe('instructions', () => {
it('should add class', () => {
const fixture = new TemplateFixture(createDivWithStyling, () => {}, 1);
fixture.update(() => {
ɵɵelementClassMap(0, 'multiple classes');
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementClassMap('multiple classes');
ɵɵelementStylingApply();
});
expect(fixture.html).toEqual('<div class="multiple classes"></div>');
});

View File

@ -11,7 +11,7 @@ import {ElementRef, TemplateRef, ViewContainerRef} from '@angular/core';
import {RendererType2} from '../../src/render/api';
import {getLContext} from '../../src/render3/context_discovery';
import {AttributeMarker, ɵɵdefineComponent, ɵɵdefineDirective, ɵɵelementClassMap, ɵɵelementHostClassMap, ɵɵelementHostStyleMap, ɵɵelementStyleMap, ɵɵtemplateRefExtractor} from '../../src/render3/index';
import {ɵɵallocHostVars, ɵɵbind, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵdirectiveInject, ɵɵelement, ɵɵelementAttribute, ɵɵelementClassProp, ɵɵelementContainerEnd, ɵɵelementContainerStart, ɵɵelementEnd, ɵɵelementHostAttrs, ɵɵelementHostClassProp, ɵɵelementHostStyleProp, ɵɵelementHostStyling, ɵɵelementHostStylingApply, ɵɵelementProperty, ɵɵelementStart, ɵɵelementStyleProp, ɵɵelementStyling, ɵɵelementStylingApply, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵinterpolation1, ɵɵinterpolation2, ɵɵinterpolation3, ɵɵinterpolation4, ɵɵinterpolation5, ɵɵinterpolation6, ɵɵinterpolation7, ɵɵinterpolation8, ɵɵinterpolationV, ɵɵprojection, ɵɵprojectionDef, ɵɵreference, ɵɵtemplate, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
import {ɵɵallocHostVars, ɵɵbind, ɵɵcontainer, ɵɵcontainerRefreshEnd, ɵɵcontainerRefreshStart, ɵɵdirectiveInject, ɵɵelement, ɵɵelementAttribute, ɵɵelementClassProp, ɵɵelementContainerEnd, ɵɵelementContainerStart, ɵɵelementEnd, ɵɵelementHostAttrs, ɵɵelementHostClassProp, ɵɵelementHostStyleProp, ɵɵelementHostStyling, ɵɵelementHostStylingApply, ɵɵelementProperty, ɵɵelementStart, ɵɵelementStyleProp, ɵɵelementStyling, ɵɵelementStylingApply, ɵɵembeddedViewEnd, ɵɵembeddedViewStart, ɵɵinterpolation1, ɵɵinterpolation2, ɵɵinterpolation3, ɵɵinterpolation4, ɵɵinterpolation5, ɵɵinterpolation6, ɵɵinterpolation7, ɵɵinterpolation8, ɵɵinterpolationV, ɵɵprojection, ɵɵprojectionDef, ɵɵreference, ɵɵselect, ɵɵtemplate, ɵɵtext, ɵɵtextBinding} from '../../src/render3/instructions/all';
import {MONKEY_PATCH_KEY_NAME} from '../../src/render3/interfaces/context';
import {RenderFlags} from '../../src/render3/interfaces/definition';
import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from '../../src/render3/interfaces/renderer';
@ -1425,8 +1425,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleProp(0, 0, ctx.color);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, ctx.color);
ɵɵelementStylingApply();
}
}, 1);
@ -1452,8 +1453,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleProp(0, 0, ctx.time, 'px');
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, ctx.time, 'px');
ɵɵelementStylingApply();
}
}, 1);
@ -1486,8 +1488,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementClassProp(0, 0, ctx.class);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementClassProp(0, ctx.class);
ɵɵelementStylingApply();
}
}, 1);
@ -1527,8 +1530,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementClassProp(0, 1, ctx.class);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementClassProp(1, ctx.class);
ɵɵelementStylingApply();
}
}, 1);
@ -1559,8 +1563,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementClassProp(0, 0, ctx.class);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementClassProp(0, ctx.class);
ɵɵelementStylingApply();
}
}, 1, 0, [MyComp]);
@ -1622,8 +1627,9 @@ describe('render3 integration test', () => {
}
if (rf & RenderFlags.Update) {
const foo = ɵɵreference(1) as any;
ɵɵelementClassProp(2, 0, ctx.class);
ɵɵelementStylingApply(2);
ɵɵselect(2);
ɵɵelementClassProp(0, ctx.class);
ɵɵelementStylingApply();
ɵɵelementProperty(2, 'tmp', ɵɵbind(foo));
}
}, 3, 1, [StructuralComp]);
@ -1685,7 +1691,8 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStylingApply();
}
}, 1, 0, [DirWithClassDirective]);
@ -1707,7 +1714,8 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStylingApply();
}
}, 1, 0, [DirWithStyleDirective]);
@ -1727,8 +1735,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementClassMap(0, 'cucumber grape');
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementClassMap('cucumber grape');
ɵɵelementStylingApply();
}
}, 1, 0, [DirWithClassDirective]);
@ -1748,8 +1757,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleMap(0, {width: '200px', height: '500px'});
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleMap({width: '200px', height: '500px'});
ɵɵelementStylingApply();
}
}, 1, 0, [DirWithStyleDirective]);
@ -1939,8 +1949,9 @@ describe('render3 integration test', () => {
ɵɵelementStyling(null, ['width']);
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleProp(0, 0, ctx.width);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, ctx.width);
ɵɵelementStylingApply();
}
}, 1, 0, [Dir1WithStyle, Dir2WithStyle]);
@ -2040,9 +2051,10 @@ describe('render3 integration test', () => {
ɵɵelementStyling();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleMap(0, ctx.stylesExp);
ɵɵelementClassMap(0, ctx.classesExp);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleMap(ctx.stylesExp);
ɵɵelementClassMap(ctx.classesExp);
ɵɵelementStylingApply();
}
}, 1, 0, [Dir1WithStyling, Dir2WithStyling]);
@ -2118,8 +2130,9 @@ describe('render3 integration test', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementClassMap(0, ɵɵinterpolation2('-', ctx.name, '-', ctx.age, '-'));
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementClassMap(ɵɵinterpolation2('-', ctx.name, '-', ctx.age, '-'));
ɵɵelementStylingApply();
}
}, 1, 2);
@ -2618,7 +2631,8 @@ describe('element discovery', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStylingApply();
}
}
});

View File

@ -9,7 +9,7 @@ import {createLView, createTView} from '@angular/core/src/render3/instructions/s
import {createRootContext} from '../../../src/render3/component';
import {getLContext} from '../../../src/render3/context_discovery';
import {ɵɵdefineComponent, ɵɵdefineDirective, ɵɵelementClassMap, ɵɵelementClassProp, ɵɵelementEnd, ɵɵelementHostClassProp, ɵɵelementHostStyleProp, ɵɵelementHostStyling, ɵɵelementHostStylingApply, ɵɵelementStart, ɵɵelementStyleMap, ɵɵelementStyleProp, ɵɵelementStyling, ɵɵelementStylingApply, ɵɵnamespaceSVG} from '../../../src/render3/index';
import {ɵɵdefineComponent, ɵɵdefineDirective, ɵɵelementClassMap, ɵɵelementClassProp, ɵɵelementEnd, ɵɵelementHostClassProp, ɵɵelementHostStyleProp, ɵɵelementHostStyling, ɵɵelementHostStylingApply, ɵɵelementStart, ɵɵelementStyleMap, ɵɵelementStyleProp, ɵɵelementStyling, ɵɵelementStylingApply, ɵɵnamespaceSVG, ɵɵselect} from '../../../src/render3/index';
import {RenderFlags} from '../../../src/render3/interfaces/definition';
import {AttributeMarker, TAttributes} from '../../../src/render3/interfaces/node';
import {BindingStore, BindingType, PlayState, Player, PlayerContext, PlayerFactory, PlayerHandler} from '../../../src/render3/interfaces/player';
@ -396,9 +396,10 @@ describe('style and class based bindings', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleMap(0, ctx.myStyles);
ɵɵelementStyleProp(0, 0, ctx.myWidth);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleMap(ctx.myStyles);
ɵɵelementStyleProp(0, ctx.myWidth);
ɵɵelementStylingApply();
}
}
@ -434,9 +435,10 @@ describe('style and class based bindings', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleProp(0, 0, ctx.diameter, 'px');
ɵɵelementStyleProp(0, 1, ctx.diameter, 'px');
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, ctx.diameter, 'px');
ɵɵelementStyleProp(1, ctx.diameter, 'px');
ɵɵelementStylingApply();
}
}
});
@ -473,9 +475,10 @@ describe('style and class based bindings', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleProp(0, 0, ctx.borderWidth);
ɵɵelementStyleProp(0, 1, ctx.borderColor);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, ctx.borderWidth);
ɵɵelementStyleProp(1, ctx.borderColor);
ɵɵelementStylingApply();
}
}
});
@ -3110,11 +3113,12 @@ describe('style and class based bindings', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleMap(0, styleMapFactory);
ɵɵelementClassMap(0, classMapFactory);
ɵɵelementStyleProp(0, 0, widthFactory);
ɵɵelementClassProp(0, 0, fooFactory);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleMap(styleMapFactory);
ɵɵelementClassMap(classMapFactory);
ɵɵelementStyleProp(0, widthFactory);
ɵɵelementClassProp(0, fooFactory);
ɵɵelementStylingApply();
}
}
});
@ -3184,11 +3188,12 @@ describe('style and class based bindings', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleMap(0, styleMapFactory);
ɵɵelementClassMap(0, classMapFactory);
ɵɵelementStyleProp(0, 0, widthFactory);
ɵɵelementClassProp(0, 0, fooFactory);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleMap(styleMapFactory);
ɵɵelementClassMap(classMapFactory);
ɵɵelementStyleProp(0, widthFactory);
ɵɵelementClassProp(0, fooFactory);
ɵɵelementStylingApply();
}
}
});
@ -3281,9 +3286,10 @@ describe('style and class based bindings', () => {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStyleProp(0, 0, ctx.widthFactory);
ɵɵelementClassProp(0, 0, ctx.fooFactory);
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStyleProp(0, ctx.widthFactory);
ɵɵelementClassProp(0, ctx.fooFactory);
ɵɵelementStylingApply();
}
}
});

View File

@ -9,7 +9,7 @@ import {QueryList} from '@angular/core';
import {RenderFlags} from '@angular/core/src/render3';
import {getHostElement, ɵɵdefineComponent, ɵɵloadViewQuery, ɵɵviewQuery} from '../../../src/render3/index';
import {markDirty, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵelementStyling, ɵɵelementStylingApply} from '../../../src/render3/instructions/all';
import {markDirty, ɵɵelement, ɵɵelementEnd, ɵɵelementStart, ɵɵelementStyling, ɵɵelementStylingApply, ɵɵselect} from '../../../src/render3/instructions/all';
import {PlayState, Player, PlayerHandler} from '../../../src/render3/interfaces/player';
import {RElement} from '../../../src/render3/interfaces/renderer';
import {addPlayer, getPlayers} from '../../../src/render3/players';
@ -262,7 +262,8 @@ class CompWithStyling {
ɵɵelementEnd();
}
if (rf & RenderFlags.Update) {
ɵɵelementStylingApply(0);
ɵɵselect(0);
ɵɵelementStylingApply();
}
}
});