Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): key-value differ changes iteration #15968

Merged
merged 1 commit into from Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -120,7 +120,6 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal
}

this._removalsHead = insertBefore;
this._removalsTail = insertBefore;

for (let record = insertBefore; record !== null; record = record._nextRemoved) {
if (record === this._mapHead) {
Expand All @@ -135,6 +134,10 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal
}
}

// Make sure tails have no next records from previous runs
if (this._changesTail) this._changesTail._nextChanged = null;
if (this._additionsTail) this._additionsTail._nextAdded = null;

return this.isDirty;
}

Expand Down Expand Up @@ -222,7 +225,7 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal

this._changesHead = this._changesTail = null;
this._additionsHead = this._additionsTail = null;
this._removalsHead = this._removalsTail = null;
this._removalsHead = null;
}
}

Expand Down Expand Up @@ -254,28 +257,17 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal
}

toString(): string {
const items: any[] = [];
const previous: any[] = [];
const changes: any[] = [];
const additions: any[] = [];
const removals: any[] = [];
let record: KeyValueChangeRecord_<K, V>|null;

for (record = this._mapHead; record !== null; record = record._next) {
items.push(stringify(record));
}
for (record = this._previousMapHead; record !== null; record = record._nextPrevious) {
previous.push(stringify(record));
}
for (record = this._changesHead; record !== null; record = record._nextChanged) {
changes.push(stringify(record));
}
for (record = this._additionsHead; record !== null; record = record._nextAdded) {
additions.push(stringify(record));
}
for (record = this._removalsHead; record !== null; record = record._nextRemoved) {
removals.push(stringify(record));
}
const items: string[] = [];
const previous: string[] = [];
const changes: string[] = [];
const additions: string[] = [];
const removals: string[] = [];

this.forEachItem(r => items.push(stringify(r)));
this.forEachPreviousItem(r => previous.push(stringify(r)));
this.forEachChangedItem(r => changes.push(stringify(r)));
this.forEachAddedItem(r => additions.push(stringify(r)));
this.forEachRemovedItem(r => removals.push(stringify(r)));

return 'map: ' + items.join(', ') + '\n' +
'previous: ' + previous.join(', ') + '\n' +
Expand Down
Expand Up @@ -194,6 +194,19 @@ export function main() {
}));
});

// https://github.com/angular/angular/issues/14997
it('should work regardless key order', () => {
differ.check({a: 1, b: 2});
differ.check({b: 3, a: 2});
differ.check({a: 1, b: 2});

expect(differ.toString()).toEqual(kvChangesAsString({
map: ['a[2->1]', 'b[3->2]'],
previous: ['b[3->2]', 'a[2->1]'],
changes: ['a[2->1]', 'b[3->2]']
}));
});

it('should when the first item is moved', () => {
differ.check({a: 'a', b: 'b'});
differ.check({c: 'c', a: 'a'});
Expand Down