parent
0914dc35e8
commit
3f08efa35d
@ -66,6 +66,41 @@ export function main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// keyValueDiffer is sensitive to key order #9115
|
||||||
|
it('should change styles specified in an object expression',
|
||||||
|
inject(
|
||||||
|
[TestComponentBuilder, AsyncTestCompleter],
|
||||||
|
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||||
|
const template = `<div [ngStyle]="expr"></div>`;
|
||||||
|
|
||||||
|
tcb.overrideTemplate(TestComponent, template)
|
||||||
|
.createAsync(TestComponent)
|
||||||
|
.then((fixture) => {
|
||||||
|
fixture.debugElement.componentInstance.expr = {
|
||||||
|
// height, width order is important here
|
||||||
|
height: '10px',
|
||||||
|
width: '10px'
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
let el = fixture.debugElement.children[0].nativeElement;
|
||||||
|
expect(getDOM().getStyle(el, 'height')).toEqual('10px');
|
||||||
|
expect(getDOM().getStyle(el, 'width')).toEqual('10px');
|
||||||
|
|
||||||
|
fixture.debugElement.componentInstance.expr = {
|
||||||
|
// width, height order is important here
|
||||||
|
width: '5px',
|
||||||
|
height: '5px',
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(getDOM().getStyle(el, 'height')).toEqual('5px');
|
||||||
|
expect(getDOM().getStyle(el, 'width')).toEqual('5px');
|
||||||
|
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should remove styles when deleting a key in an object expression',
|
it('should remove styles when deleting a key in an object expression',
|
||||||
inject(
|
inject(
|
||||||
[TestComponentBuilder, AsyncTestCompleter],
|
[TestComponentBuilder, AsyncTestCompleter],
|
||||||
|
@ -79,7 +79,7 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
|
|||||||
throw new BaseException(`Error trying to diff '${map}'`);
|
throw new BaseException(`Error trying to diff '${map}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.check(map) ? this : null
|
return this.check(map) ? this : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() {}
|
onDestroy() {}
|
||||||
@ -96,11 +96,7 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
|
|||||||
let newSeqRecord: any;
|
let newSeqRecord: any;
|
||||||
if (oldSeqRecord && key === oldSeqRecord.key) {
|
if (oldSeqRecord && key === oldSeqRecord.key) {
|
||||||
newSeqRecord = oldSeqRecord;
|
newSeqRecord = oldSeqRecord;
|
||||||
if (!looseIdentical(value, oldSeqRecord.currentValue)) {
|
this._maybeAddToChanges(newSeqRecord, value);
|
||||||
oldSeqRecord.previousValue = oldSeqRecord.currentValue;
|
|
||||||
oldSeqRecord.currentValue = value;
|
|
||||||
this._addToChanges(oldSeqRecord);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
seqChanged = true;
|
seqChanged = true;
|
||||||
if (oldSeqRecord !== null) {
|
if (oldSeqRecord !== null) {
|
||||||
@ -109,6 +105,7 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
|
|||||||
}
|
}
|
||||||
if (records.has(key)) {
|
if (records.has(key)) {
|
||||||
newSeqRecord = records.get(key);
|
newSeqRecord = records.get(key);
|
||||||
|
this._maybeAddToChanges(newSeqRecord, value);
|
||||||
} else {
|
} else {
|
||||||
newSeqRecord = new KeyValueChangeRecord(key);
|
newSeqRecord = new KeyValueChangeRecord(key);
|
||||||
records.set(key, newSeqRecord);
|
records.set(key, newSeqRecord);
|
||||||
@ -179,6 +176,14 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _maybeAddToChanges(record: KeyValueChangeRecord, newValue: any): void {
|
||||||
|
if (!looseIdentical(newValue, record.currentValue)) {
|
||||||
|
record.previousValue = record.currentValue;
|
||||||
|
record.currentValue = newValue;
|
||||||
|
this._addToChanges(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_isInRemovals(record: KeyValueChangeRecord) {
|
_isInRemovals(record: KeyValueChangeRecord) {
|
||||||
return record === this._removalsHead || record._nextRemoved !== null ||
|
return record === this._removalsHead || record._nextRemoved !== null ||
|
||||||
|
@ -189,11 +189,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should work regardless key order', () => {
|
it('should work regardless key order', () => {
|
||||||
let m: {[k: string]: number} = {a: 0, b: 0};
|
differ.check({a: 0, b: 0});
|
||||||
differ.check(m);
|
differ.check({b: 1, a: 1});
|
||||||
|
|
||||||
m = {b: 1, a: 1};
|
|
||||||
differ.check(m);
|
|
||||||
|
|
||||||
expect(differ.toString()).toEqual(kvChangesAsString({
|
expect(differ.toString()).toEqual(kvChangesAsString({
|
||||||
map: ['b[0->1]', 'a[0->1]'],
|
map: ['b[0->1]', 'a[0->1]'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user