fix(renderer): remove unecessary setElementStyles method

There is no need to expose this additional method inside of the Renderer
API. The functionality can be restored by looping and calling
`setElementStyle` instead.

Note that this change is changing code that was was introduced after
the last release therefore this fix is not a breaking change.

Closes #9000
Closes #9009
This commit is contained in:
Matias Niemelä 2016-06-03 14:59:42 -07:00
parent a6ad61d83e
commit e504d4eb05
12 changed files with 22 additions and 43 deletions

View File

@ -84,3 +84,4 @@ export var balanceAnimationKeyframes: typeof t.balanceAnimationKeyframes = r.bal
export var flattenStyles: typeof t.flattenStyles = r.flattenStyles;
export var clearStyles: typeof t.clearStyles = r.clearStyles;
export var collectAndResolveStyles: typeof r.collectAndResolveStyles = r.collectAndResolveStyles;
export var renderStyles: typeof t.renderStyles = r.renderStyles;

View File

@ -243,12 +243,16 @@ class _AnimationBuilder implements AnimationAstVisitor {
_ANIMATION_END_STATE_STYLES_VAR.set(EMPTY_MAP).toStmt()
]));
var RENDER_STYLES_FN = o.importExpr(Identifiers.renderStyles);
// before we start any animation we want to clear out the starting
// styles from the element's style property (since they were placed
// there at the end of the last animation
statements.push(
_ANIMATION_FACTORY_RENDERER_VAR.callMethod('setElementStyles', [
RENDER_STYLES_FN.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR,
_ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(Identifiers.clearStyles).callFn([_ANIMATION_START_STATE_STYLES_VAR])
]).toStmt());
@ -269,8 +273,9 @@ class _AnimationBuilder implements AnimationAstVisitor {
statements.push(
_ANIMATION_PLAYER_VAR.callMethod('onDone', [
o.fn([], [
_ANIMATION_FACTORY_RENDERER_VAR.callMethod('setElementStyles', [
RENDER_STYLES_FN.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR,
_ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(Identifiers.balanceAnimationStyles).callFn([
_ANIMATION_START_STATE_STYLES_VAR,
_ANIMATION_END_STATE_STYLES_VAR

View File

@ -49,6 +49,7 @@ import {
balanceAnimationKeyframes as impBalanceAnimationKeyframes,
clearStyles as impClearStyles,
collectAndResolveStyles as impCollectAndResolveStyles,
renderStyles as impRenderStyles,
SecurityContext
} from '../core_private';
@ -260,6 +261,11 @@ export class Identifiers {
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL,
runtime: impClearStyles
});
static renderStyles = new CompileIdentifierMetadata({
name: 'renderStyles',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL,
runtime: impRenderStyles
});
static collectAndResolveStyles = new CompileIdentifierMetadata({
name: 'collectAndResolveStyles',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL,

View File

@ -125,6 +125,7 @@ export declare namespace __core_private_types__ {
export var balanceAnimationKeyframes: typeof animationUtils.balanceAnimationKeyframes;
export var flattenStyles: typeof animationUtils.flattenStyles;
export var clearStyles: typeof animationUtils.clearStyles;
export var renderStyles: typeof animationUtils.renderStyles;
export var collectAndResolveStyles: typeof animationUtils.collectAndResolveStyles;
export type AnimationStyles = AnimationStyles_;
export var AnimationStyles: typeof AnimationStyles_;
@ -194,6 +195,7 @@ export var __core_private__ = {
balanceAnimationKeyframes: animationUtils.balanceAnimationKeyframes,
flattenStyles: animationUtils.flattenStyles,
clearStyles: animationUtils.clearStyles,
renderStyles: animationUtils.renderStyles,
collectAndResolveStyles: animationUtils.collectAndResolveStyles,
AnimationStyles: AnimationStyles_,
ANY_STATE: ANY_STATE_,

View File

@ -101,6 +101,12 @@ export function collectAndResolveStyles(collection: {[key: string]: string|numbe
});
}
export function renderStyles(element: any, renderer: any, styles: {[key: string]: string|number}): void {
StringMapWrapper.forEach(styles, (value, prop) => {
renderer.setElementStyle(element, prop, value);
});
}
export function flattenStyles(styles: {[key: string]: string|number}[]) {
var finalStyles = {};
styles.forEach(entry => {

View File

@ -134,17 +134,6 @@ export class DebugDomRenderer implements Renderer {
this._delegate.setElementClass(renderElement, className, isAdd);
}
setElementStyles(renderElement: any, styles: {[key: string]: string}) {
var debugEl = getDebugNode(renderElement);
if (isPresent(debugEl) && debugEl instanceof DebugElement) {
var elStyles = debugEl.styles;
StringMapWrapper.forEach(styles, (value, prop) => {
elStyles[prop] = value;
});
}
this._delegate.setElementStyles(renderElement, styles);
}
setElementStyle(renderElement: any, styleName: string, styleValue: string) {
var debugEl = getDebugNode(renderElement);
if (isPresent(debugEl) && debugEl instanceof DebugElement) {

View File

@ -61,8 +61,6 @@ export abstract class Renderer {
abstract setElementClass(renderElement: any, className: string, isAdd: boolean);
abstract setElementStyles(renderElement: any, styles: {[key: string]: string});
abstract setElementStyle(renderElement: any, styleName: string, styleValue: string);
abstract invokeElementMethod(renderElement: any, methodName: string, args?: any[]);

View File

@ -228,11 +228,6 @@ export class DomRenderer implements Renderer {
}
}
setElementStyles(renderElement: any, styles: {[key: string]: string}) {
StringMapWrapper.forEach(styles,
(value, prop) => this.setElementStyle(renderElement, prop, value));
}
setElementStyle(renderElement: any, styleName: string, styleValue: string): void {
if (isPresent(styleValue)) {
getDOM().setStyle(renderElement, styleName, stringify(styleValue));

View File

@ -59,9 +59,6 @@ export class MessageBasedRenderer {
broker.registerMethod("setElementStyle",
[RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
FunctionWrapper.bind(this._setElementStyle, this));
broker.registerMethod("setElementStyles",
[RenderStoreObject, RenderStoreObject, PRIMITIVE],
FunctionWrapper.bind(this._setElementStyles, this));
broker.registerMethod("invokeElementMethod",
[RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
FunctionWrapper.bind(this._invokeElementMethod, this));
@ -147,11 +144,6 @@ export class MessageBasedRenderer {
renderer.setElementStyle(renderElement, styleName, styleValue);
}
private _setElementStyles(renderer: Renderer, renderElement: any,
styles: {[key: string]: string}) {
renderer.setElementStyles(renderElement, styles);
}
private _invokeElementMethod(renderer: Renderer, renderElement: any, methodName: string,
args: any[]) {
renderer.invokeElementMethod(renderElement, methodName, args);

View File

@ -191,11 +191,6 @@ export class WebWorkerRenderer implements Renderer, RenderStoreObject {
]);
}
setElementStyles(renderElement: any, styles: {[key: string]: string}) {
this._runOnService('setElementStyles',
[new FnArg(renderElement, RenderStoreObject), new FnArg(styles, null)]);
}
setElementStyle(renderElement: any, styleName: string, styleValue: string) {
this._runOnService('setElementStyle', [
new FnArg(renderElement, RenderStoreObject),

View File

@ -156,15 +156,6 @@ export function main() {
renderer.setElementStyle(workerEl, 'width', null);
expect(getDOM().getStyle(el, 'width')).toEqual('');
renderer.setElementStyles(workerEl, {'height': '999px', 'opacity': '0.5'})
expect(getDOM().getStyle(el, 'height'))
.toEqual('999px');
expect(getDOM().getStyle(el, 'opacity')).toEqual('0.5');
renderer.setElementStyles(workerEl, {'height': '999px', 'opacity': null});
expect(getDOM().getStyle(el, 'height'))
.toEqual('999px');
expect(getDOM().getStyle(el, 'opacity')).toEqual('');
renderer.setElementAttribute(workerEl, 'someattr', 'someValue');
expect(getDOM().getAttribute(el, 'someattr')).toEqual('someValue');
};

View File

@ -457,7 +457,6 @@ const CORE = [
'Renderer.setElementClass(renderElement:any, className:string, isAdd:boolean):any',
'Renderer.setElementProperty(renderElement:any, propertyName:string, propertyValue:any):void',
'Renderer.setElementStyle(renderElement:any, styleName:string, styleValue:string):any',
'Renderer.setElementStyles(renderElement:any, styles:{[key:string]:string}):any',
'Renderer.setText(renderNode:any, text:string):any',
'ResolvedReflectiveBinding',
'ResolvedReflectiveFactory',