fix(core): remove support for Map/Set in [class]/[style] bindings (#35392)

Close FW-1863

PR Close #35392
This commit is contained in:
Misko Hevery 2020-02-12 10:36:53 -08:00 committed by Alex Rickabaugh
parent 5576031b44
commit 2ca7984d55
3 changed files with 11 additions and 34 deletions

View File

@ -119,9 +119,7 @@ export function ɵɵclassProp(
* *
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵstyleMap( export function ɵɵstyleMap(styles: {[styleName: string]: any} | string | undefined | null): void {
styles: {[styleName: string]: any} | Map<string, string|number|null|undefined>| string |
undefined | null): void {
checkStylingMap(styleKeyValueArraySet, styleStringParser, styles, false); checkStylingMap(styleKeyValueArraySet, styleStringParser, styles, false);
} }
@ -161,8 +159,7 @@ export function styleStringParser(keyValueArray: KeyValueArray<any>, text: strin
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵclassMap( export function ɵɵclassMap(
classes: {[className: string]: boolean | undefined | null} | classes: {[className: string]: boolean | undefined | null} | string | undefined | null): void {
Map<string, boolean|undefined|null>| Set<string>| string[] | string | undefined | null): void {
checkStylingMap(keyValueArraySet, classStringParser, classes, true); checkStylingMap(keyValueArraySet, classStringParser, classes, true);
} }
@ -626,8 +623,8 @@ export function getHostDirectiveDef(tData: TData): DirectiveDef<any>|null {
*/ */
export function toStylingKeyValueArray( export function toStylingKeyValueArray(
keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void, keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void,
stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void, value: string| stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void,
string[]|{[key: string]: any}|Map<any, any>|Set<any>|null|undefined): KeyValueArray<any> { value: string|string[]|{[key: string]: any}|null|undefined): KeyValueArray<any> {
if (value == null /*|| value === undefined */ || value === '') return EMPTY_ARRAY as any; if (value == null /*|| value === undefined */ || value === '') return EMPTY_ARRAY as any;
const styleKeyValueArray: KeyValueArray<any> = [] as any; const styleKeyValueArray: KeyValueArray<any> = [] as any;
if (Array.isArray(value)) { if (Array.isArray(value)) {
@ -635,15 +632,9 @@ export function toStylingKeyValueArray(
keyValueArraySet(styleKeyValueArray, value[i], true); keyValueArraySet(styleKeyValueArray, value[i], true);
} }
} else if (typeof value === 'object') { } else if (typeof value === 'object') {
if (value instanceof Map) { for (const key in value) {
value.forEach((v, k) => keyValueArraySet(styleKeyValueArray, k, v)); if (value.hasOwnProperty(key)) {
} else if (value instanceof Set) { keyValueArraySet(styleKeyValueArray, key, value[key]);
value.forEach((k) => keyValueArraySet(styleKeyValueArray, k, true));
} else {
for (const key in value) {
if (value.hasOwnProperty(key)) {
keyValueArraySet(styleKeyValueArray, key, value[key]);
}
} }
} }
} else if (typeof value === 'string') { } else if (typeof value === 'string') {
@ -674,11 +665,10 @@ function styleKeyValueArraySet(keyValueArray: KeyValueArray<any>, key: string, v
* Update map based styling. * Update map based styling.
* *
* Map based styling could be anything which contains more than one binding. For example `string`, * Map based styling could be anything which contains more than one binding. For example `string`,
* `Map`, `Set` or object literal. Dealing with all of these types would complicate the logic so * or object literal. Dealing with all of these types would complicate the logic so
* instead this function expects that the complex input is first converted into normalized * instead this function expects that the complex input is first converted into normalized
* `KeyValueArray`. The advantage of normalization is that we get the values sorted, which makes it * `KeyValueArray`. The advantage of normalization is that we get the values sorted, which makes it
* very * very cheap to compute deltas between the previous and current value.
* cheap to compute deltas between the previous and current value.
* *
* @param tView Associated `TView.data` contains the linked list of binding priorities. * @param tView Associated `TView.data` contains the linked list of binding priorities.
* @param tNode `TNode` where the binding is located. * @param tNode `TNode` where the binding is located.

View File

@ -440,19 +440,6 @@ describe('styling', () => {
] as any); ] as any);
}); });
}); });
describe('Map', () => {
it('should parse', () => {
expect(toStylingKeyValueArray(
keyValueArraySet, null !, new Map<string, string>([['X', 'x'], ['A', 'a']])))
.toEqual(['A', 'a', 'X', 'x'] as any);
});
});
describe('Iterable', () => {
it('should parse', () => {
expect(toStylingKeyValueArray(keyValueArraySet, null !, new Set<string>(['X', 'A'])))
.toEqual(['A', true, 'X', true] as any);
});
});
}); });
}); });

View File

@ -704,7 +704,7 @@ export declare function ɵɵattributeInterpolateV(attrName: string, values: any[
export declare function ɵɵclassMap(classes: { export declare function ɵɵclassMap(classes: {
[className: string]: boolean | undefined | null; [className: string]: boolean | undefined | null;
} | Map<string, boolean | undefined | null> | Set<string> | string[] | string | undefined | null): void; } | string | undefined | null): void;
export declare function ɵɵclassMapInterpolate1(prefix: string, v0: any, suffix: string): void; export declare function ɵɵclassMapInterpolate1(prefix: string, v0: any, suffix: string): void;
@ -1035,7 +1035,7 @@ export declare function ɵɵstaticViewQuery<T>(predicate: Type<any> | string[],
export declare function ɵɵstyleMap(styles: { export declare function ɵɵstyleMap(styles: {
[styleName: string]: any; [styleName: string]: any;
} | Map<string, string | number | null | undefined> | string | undefined | null): void; } | string | undefined | null): void;
export declare function ɵɵstyleProp(prop: string, value: string | number | SafeValue | undefined | null, suffix?: string | null): typeof ɵɵstyleProp; export declare function ɵɵstyleProp(prop: string, value: string | number | SafeValue | undefined | null, suffix?: string | null): typeof ɵɵstyleProp;