refactor(core): remove toString() method from DefaultKeyValueDiffer

toString() from DefaultKeyValueDiffer is only used in tests and should not
be part of the production code. toString() methods from differs add
~ 0.3KB (min+gzip) to the production bundle size.
This commit is contained in:
Pawel Kozlowski
2017-06-15 15:29:02 +02:00
committed by Hans
parent f194f18dbd
commit 009651e14f
3 changed files with 58 additions and 56 deletions

View File

@ -6,6 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {KeyValueChangeRecord, KeyValueChanges} from '@angular/core/src/change_detection/differs/keyvalue_differs';
import {looseIdentical, stringify} from '../../src/util';
export function iterableChangesAsString(
@ -19,7 +22,30 @@ export function iterableChangesAsString(
'identityChanges: ' + identityChanges.join(', ') + '\n';
}
export function kvChangesAsString(
function kvcrAsString(kvcr: KeyValueChangeRecord<string, any>) {
return looseIdentical(kvcr.previousValue, kvcr.currentValue) ?
stringify(kvcr.key) :
(stringify(kvcr.key) + '[' + stringify(kvcr.previousValue) + '->' +
stringify(kvcr.currentValue) + ']');
}
export function kvChangesAsString(kvChanges: KeyValueChanges<string, any>) {
const map: string[] = [];
const previous: string[] = [];
const changes: string[] = [];
const additions: string[] = [];
const removals: string[] = [];
kvChanges.forEachItem(r => map.push(kvcrAsString(r)));
kvChanges.forEachPreviousItem(r => previous.push(kvcrAsString(r)));
kvChanges.forEachChangedItem(r => changes.push(kvcrAsString(r)));
kvChanges.forEachAddedItem(r => additions.push(kvcrAsString(r)));
kvChanges.forEachRemovedItem(r => removals.push(kvcrAsString(r)));
return testChangesAsString({map, previous, additions, changes, removals});
}
export function testChangesAsString(
{map, previous, additions, changes, removals}:
{map?: any[], previous?: any[], additions?: any[], changes?: any[], removals?: any[]}):
string {