fix(core): Remove ChangeDetectorRef Paramter from KeyValueDifferFactory and IterableDifferFactory (#14311)

BREAKING CHANGE:

- `KeyValueDifferFactory` and `IterableDifferFactory` no longer have `ChangeDetectorRef` as 
  a parameter. It was not used and has been there for historical reasons. If you call 
  `DifferFactory.create(...)` remove the `ChangeDetectorRef` argument.
This commit is contained in:
FrozenPandaz 2017-02-09 16:33:44 -05:00 committed by Miško Hevery
parent 56e2f84fe8
commit 45cc444154
9 changed files with 41 additions and 14 deletions

View File

@ -69,9 +69,9 @@ export class NgClass implements DoCheck {
if (this._rawClass) {
if (isListLikeIterable(this._rawClass)) {
this._iterableDiffer = this._iterableDiffers.find(this._rawClass).create(null);
this._iterableDiffer = this._iterableDiffers.find(this._rawClass).create();
} else {
this._keyValueDiffer = this._keyValueDiffers.find(this._rawClass).create(null);
this._keyValueDiffer = this._keyValueDiffers.find(this._rawClass).create();
}
}
}

View File

@ -112,7 +112,7 @@ export class NgForOf<T> implements DoCheck,
constructor(
private _viewContainer: ViewContainerRef, private _template: TemplateRef<NgForOfRow<T>>,
private _differs: IterableDiffers, private _cdr: ChangeDetectorRef) {}
private _differs: IterableDiffers) {}
@Input()
set ngForTemplate(value: TemplateRef<NgForOfRow<T>>) {
@ -130,7 +130,7 @@ export class NgForOf<T> implements DoCheck,
const value = changes['ngForOf'].currentValue;
if (!this._differ && value) {
try {
this._differ = this._differs.find(value).create(this._cdr, this.ngForTrackBy);
this._differ = this._differs.find(value).create(this.ngForTrackBy);
} catch (e) {
throw new Error(
`Cannot find a differ supporting object '${value}' of type '${getTypeNameForDebugging(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
@ -253,4 +253,4 @@ class RecordViewTuple<T> {
*
* @deprecated v4.0.0 - Use `NgForOf<T>` instead.
*/
export class NgFor extends NgForOf<any> {}
export class NgFor extends NgForOf<any> {}

View File

@ -42,7 +42,7 @@ export class NgStyle implements DoCheck {
set ngStyle(v: {[key: string]: string}) {
this._ngStyle = v;
if (!this._differ && v) {
this._differ = this._differs.find(v).create(null);
this._differ = this._differs.find(v).create();
}
}

View File

@ -16,8 +16,16 @@ import {IterableChangeRecord, IterableChanges, IterableDiffer, IterableDifferFac
export class DefaultIterableDifferFactory implements IterableDifferFactory {
constructor() {}
supports(obj: Object): boolean { return isListLikeIterable(obj); }
create<V>(cdRef: ChangeDetectorRef, trackByFn?: TrackByFunction<any>): DefaultIterableDiffer<V> {
return new DefaultIterableDiffer<V>(trackByFn);
create<V>(trackByFn?: TrackByFunction<any>): DefaultIterableDiffer<V>;
/**
* @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter
*/
create<V>(
cdRefOrTrackBy?: ChangeDetectorRef|TrackByFunction<any>,
trackByFn?: TrackByFunction<any>): DefaultIterableDiffer<V> {
return new DefaultIterableDiffer<V>(trackByFn || <TrackByFunction<any>>cdRefOrTrackBy);
}
}

View File

@ -17,7 +17,12 @@ export class DefaultKeyValueDifferFactory<K, V> implements KeyValueDifferFactory
constructor() {}
supports(obj: any): boolean { return obj instanceof Map || isJsObject(obj); }
create<K, V>(cdRef: ChangeDetectorRef): KeyValueDiffer<K, V> {
create<K, V>(): DefaultKeyValueDiffer<K, V>;
/**
* @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter
*/
create<K, V>(cd?: ChangeDetectorRef): KeyValueDiffer<K, V> {
return new DefaultKeyValueDiffer<K, V>();
}
}

View File

@ -137,7 +137,13 @@ export interface TrackByFunction<T> { (index: number, item: T): any; }
*/
export interface IterableDifferFactory {
supports(objects: any): boolean;
create<V>(cdRef: ChangeDetectorRef, trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
create<V>(trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
/**
* @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter
*/
create<V>(_cdr?: ChangeDetectorRef|TrackByFunction<V>, trackByFn?: TrackByFunction<V>):
IterableDiffer<V>;
}
/**

View File

@ -10,6 +10,7 @@ import {Optional, Provider, SkipSelf} from '../../di';
import {ChangeDetectorRef} from '../change_detector_ref';
/**
* A differ that tracks changes made to an object over time.
*
@ -108,7 +109,12 @@ export interface KeyValueDifferFactory {
/**
* Create a `KeyValueDiffer`.
*/
create<K, V>(cdRef: ChangeDetectorRef): KeyValueDiffer<K, V>;
create<K, V>(): KeyValueDiffer<K, V>;
/**
* @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter
*/
create<K, V>(_cdr?: ChangeDetectorRef): KeyValueDiffer<K, V>;
}
/**

View File

@ -137,7 +137,7 @@ export declare class NgForOf<T> implements DoCheck, OnChanges {
ngForOf: NgIterable<T>;
ngForTemplate: TemplateRef<NgForOfRow<T>>;
ngForTrackBy: TrackByFunction<T>;
constructor(_viewContainer: ViewContainerRef, _template: TemplateRef<NgForOfRow<T>>, _differs: IterableDiffers, _cdr: ChangeDetectorRef);
constructor(_viewContainer: ViewContainerRef, _template: TemplateRef<NgForOfRow<T>>, _differs: IterableDiffers);
ngDoCheck(): void;
ngOnChanges(changes: SimpleChanges): void;
}

View File

@ -556,7 +556,8 @@ export interface IterableDiffer<V> {
/** @stable */
export interface IterableDifferFactory {
create<V>(cdRef: ChangeDetectorRef, trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
create<V>(trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
/** @deprecated */ create<V>(_cdr?: ChangeDetectorRef | TrackByFunction<V>, trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
supports(objects: any): boolean;
}
@ -598,7 +599,8 @@ export interface KeyValueDiffer<K, V> {
/** @stable */
export interface KeyValueDifferFactory {
create<K, V>(cdRef: ChangeDetectorRef): KeyValueDiffer<K, V>;
create<K, V>(): KeyValueDiffer<K, V>;
/** @deprecated */ create<K, V>(_cdr?: ChangeDetectorRef): KeyValueDiffer<K, V>;
supports(objects: any): boolean;
}