fix(core): Add type information to differs

CHANGES:

- Remove unused `onDestroy` method on the `KeyValueDiffer` and
  `IterableDiffer`.

DEPRECATION:

- `CollectionChangeRecord` is renamed to `IterableChangeRecord`.
  `CollectionChangeRecord` is aliased to `IterableChangeRecord` and is
  marked as `@deprecated`. It will be removed in `v5.x.x`.
- Deprecate `DefaultIterableDiffer` as it is private class which
  was erroneously exposed.
- Deprecate `KeyValueDiffers#factories` as it is private field which
  was erroneously exposed.
- Deprecate `IterableDiffers#factories` as it is private field which
  was erroneously exposed.

BREAKING CHANGE:

- `IterableChangeRecord` is now an interface and parameterized on `<V>`.
  This should not be an issue unless your code does
  `new IterableChangeRecord` which it should not have a reason to do.
- `KeyValueChangeRecord` is now an interface and parameterized on `<V>`.
  This should not be an issue unless your code does
  `new IterableChangeRecord` which it should not have a reason to do.

Original PR #12570

Fixes #13382
This commit is contained in:
Joao Dias
2016-10-27 20:28:11 +02:00
committed by Matias Niemelä
parent 5d9cbd7d6f
commit 8c7e93bebe
12 changed files with 471 additions and 290 deletions

View File

@ -205,14 +205,8 @@ export interface ClassProvider {
useClass: Type<any>;
}
/** @stable */
export declare class CollectionChangeRecord {
currentIndex: number;
item: any;
previousIndex: number;
trackById: any;
constructor(item: any, trackById: any);
toString(): string;
/** @deprecated */
export interface CollectionChangeRecord<V> extends IterableChangeRecord<V> {
}
/** @stable */
@ -358,21 +352,21 @@ export declare class DebugNode {
constructor(nativeNode: any, parent: DebugNode, _debugInfo: RenderDebugInfo);
}
/** @stable */
export declare class DefaultIterableDiffer implements IterableDiffer {
/** @deprecated */
export declare class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChanges<V> {
collection: any;
isDirty: boolean;
length: number;
constructor(_trackByFn?: TrackByFn);
check(collection: any): boolean;
diff(collection: any): DefaultIterableDiffer;
forEachAddedItem(fn: Function): void;
forEachIdentityChange(fn: Function): void;
forEachItem(fn: Function): void;
forEachMovedItem(fn: Function): void;
forEachOperation(fn: (item: CollectionChangeRecord, previousIndex: number, currentIndex: number) => void): void;
forEachPreviousItem(fn: Function): void;
forEachRemovedItem(fn: Function): void;
check(collection: V[] | Set<V>[] | any): boolean;
diff(collection: V[] | Set<V>[] | any): DefaultIterableDiffer<V>;
forEachAddedItem(fn: (record: IterableChangeRecord_<V>) => void): void;
forEachIdentityChange(fn: (record: IterableChangeRecord_<V>) => void): void;
forEachItem(fn: (record: IterableChangeRecord_<V>) => void): void;
forEachMovedItem(fn: (record: IterableChangeRecord_<V>) => void): void;
forEachOperation(fn: (item: IterableChangeRecord_<V>, previousIndex: number, currentIndex: number) => void): void;
forEachPreviousItem(fn: (record: IterableChangeRecord_<V>) => void): void;
forEachRemovedItem(fn: (record: IterableChangeRecord_<V>) => void): void;
onDestroy(): void;
toString(): string;
}
@ -511,20 +505,38 @@ export declare const Input: InputDecorator;
export declare function isDevMode(): boolean;
/** @stable */
export interface IterableDiffer {
diff(object: any): any;
onDestroy(): any;
export interface IterableChangeRecord<V> {
currentIndex: number;
item: V;
previousIndex: number;
trackById: any;
}
/** @stable */
export interface IterableChanges<V> {
forEachAddedItem(fn: (record: IterableChangeRecord<V>) => void): void;
forEachIdentityChange(fn: (record: IterableChangeRecord<V>) => void): void;
forEachItem(fn: (record: IterableChangeRecord<V>) => void): void;
forEachMovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
forEachOperation(fn: (record: IterableChangeRecord<V>, previousIndex: number, currentIndex: number) => void): void;
forEachPreviousItem(fn: (record: IterableChangeRecord<V>) => void): void;
forEachRemovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
}
/** @stable */
export interface IterableDiffer<V> {
diff(object: V[] | Set<V> | any): IterableChanges<V>;
}
/** @stable */
export interface IterableDifferFactory {
create(cdRef: ChangeDetectorRef, trackByFn?: TrackByFn): IterableDiffer;
create<V>(cdRef: ChangeDetectorRef, trackByFn?: TrackByFn): IterableDiffer<V>;
supports(objects: any): boolean;
}
/** @stable */
export declare class IterableDiffers {
factories: IterableDifferFactory[];
/** @deprecated */ factories: IterableDifferFactory[];
constructor(factories: IterableDifferFactory[]);
find(iterable: any): IterableDifferFactory;
static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers;
@ -535,33 +547,42 @@ export declare class IterableDiffers {
export declare function keyframes(steps: AnimationStyleMetadata[]): AnimationKeyframesSequenceMetadata;
/** @stable */
export declare class KeyValueChangeRecord {
currentValue: any;
key: any;
previousValue: any;
constructor(key: any);
toString(): string;
export interface KeyValueChangeRecord<K, V> {
currentValue: V;
key: K;
previousValue: V;
}
/** @stable */
export interface KeyValueDiffer {
diff(object: any): any;
onDestroy(): any;
export interface KeyValueChanges<K, V> {
forEachAddedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
forEachChangedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
forEachItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
forEachPreviousItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
forEachRemovedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
}
/** @stable */
export interface KeyValueDiffer<K, V> {
diff(object: Map<K, V>): KeyValueChanges<K, V>;
diff(object: {
[key: string]: V;
}): KeyValueChanges<string, V>;
}
/** @stable */
export interface KeyValueDifferFactory {
create(cdRef: ChangeDetectorRef): KeyValueDiffer;
create<K, V>(cdRef: ChangeDetectorRef): KeyValueDiffer<K, V>;
supports(objects: any): boolean;
}
/** @stable */
export declare class KeyValueDiffers {
factories: KeyValueDifferFactory[];
/** @deprecated */ factories: KeyValueDifferFactory[];
constructor(factories: KeyValueDifferFactory[]);
find(kv: Object): KeyValueDifferFactory;
static create(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers;
static extend(factories: KeyValueDifferFactory[]): Provider;
find(kv: any): KeyValueDifferFactory;
static create<S>(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers;
static extend<S>(factories: KeyValueDifferFactory[]): Provider;
}
/** @experimental */