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:
parent
56e2f84fe8
commit
45cc444154
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.`);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue