From a09902e9ce282ae414473a06dd606c871df2e0fd Mon Sep 17 00:00:00 2001 From: FrozenPandaz Date: Thu, 9 Feb 2017 16:33:44 -0500 Subject: [PATCH] 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. --- modules/@angular/common/src/directives/ng_class.ts | 4 ++-- modules/@angular/common/src/directives/ng_for_of.ts | 6 +++--- modules/@angular/common/src/directives/ng_style.ts | 2 +- .../differs/default_iterable_differ.ts | 12 ++++++++++-- .../differs/default_keyvalue_differ.ts | 7 ++++++- .../src/change_detection/differs/iterable_differs.ts | 8 +++++++- .../src/change_detection/differs/keyvalue_differs.ts | 8 +++++++- tools/public_api_guard/common/index.d.ts | 2 +- tools/public_api_guard/core/index.d.ts | 6 ++++-- 9 files changed, 41 insertions(+), 14 deletions(-) diff --git a/modules/@angular/common/src/directives/ng_class.ts b/modules/@angular/common/src/directives/ng_class.ts index 7f96c75fe7d34..725965fe12995 100644 --- a/modules/@angular/common/src/directives/ng_class.ts +++ b/modules/@angular/common/src/directives/ng_class.ts @@ -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(); } } } diff --git a/modules/@angular/common/src/directives/ng_for_of.ts b/modules/@angular/common/src/directives/ng_for_of.ts index e8f0103422e16..c72e55c18e001 100644 --- a/modules/@angular/common/src/directives/ng_for_of.ts +++ b/modules/@angular/common/src/directives/ng_for_of.ts @@ -112,7 +112,7 @@ export class NgForOf implements DoCheck, constructor( private _viewContainer: ViewContainerRef, private _template: TemplateRef>, - private _differs: IterableDiffers, private _cdr: ChangeDetectorRef) {} + private _differs: IterableDiffers) {} @Input() set ngForTemplate(value: TemplateRef>) { @@ -130,7 +130,7 @@ export class NgForOf 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 { * * @deprecated v4.0.0 - Use `NgForOf` instead. */ -export class NgFor extends NgForOf {} \ No newline at end of file +export class NgFor extends NgForOf {} diff --git a/modules/@angular/common/src/directives/ng_style.ts b/modules/@angular/common/src/directives/ng_style.ts index 7949751177a35..fafb49e32c120 100644 --- a/modules/@angular/common/src/directives/ng_style.ts +++ b/modules/@angular/common/src/directives/ng_style.ts @@ -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(); } } diff --git a/modules/@angular/core/src/change_detection/differs/default_iterable_differ.ts b/modules/@angular/core/src/change_detection/differs/default_iterable_differ.ts index e61e4ed5ead06..e76592154f6a3 100644 --- a/modules/@angular/core/src/change_detection/differs/default_iterable_differ.ts +++ b/modules/@angular/core/src/change_detection/differs/default_iterable_differ.ts @@ -16,8 +16,16 @@ import {IterableChangeRecord, IterableChanges, IterableDiffer, IterableDifferFac export class DefaultIterableDifferFactory implements IterableDifferFactory { constructor() {} supports(obj: Object): boolean { return isListLikeIterable(obj); } - create(cdRef: ChangeDetectorRef, trackByFn?: TrackByFunction): DefaultIterableDiffer { - return new DefaultIterableDiffer(trackByFn); + + create(trackByFn?: TrackByFunction): DefaultIterableDiffer; + + /** + * @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter + */ + create( + cdRefOrTrackBy?: ChangeDetectorRef|TrackByFunction, + trackByFn?: TrackByFunction): DefaultIterableDiffer { + return new DefaultIterableDiffer(trackByFn || >cdRefOrTrackBy); } } diff --git a/modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.ts b/modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.ts index d47d50d9449ad..8659e7e8555bd 100644 --- a/modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.ts +++ b/modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.ts @@ -17,7 +17,12 @@ export class DefaultKeyValueDifferFactory implements KeyValueDifferFactory constructor() {} supports(obj: any): boolean { return obj instanceof Map || isJsObject(obj); } - create(cdRef: ChangeDetectorRef): KeyValueDiffer { + create(): DefaultKeyValueDiffer; + + /** + * @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter + */ + create(cd?: ChangeDetectorRef): KeyValueDiffer { return new DefaultKeyValueDiffer(); } } diff --git a/modules/@angular/core/src/change_detection/differs/iterable_differs.ts b/modules/@angular/core/src/change_detection/differs/iterable_differs.ts index 582f0c2b9d919..bede76228d301 100644 --- a/modules/@angular/core/src/change_detection/differs/iterable_differs.ts +++ b/modules/@angular/core/src/change_detection/differs/iterable_differs.ts @@ -137,7 +137,13 @@ export interface TrackByFunction { (index: number, item: T): any; } */ export interface IterableDifferFactory { supports(objects: any): boolean; - create(cdRef: ChangeDetectorRef, trackByFn?: TrackByFunction): IterableDiffer; + create(trackByFn?: TrackByFunction): IterableDiffer; + + /** + * @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter + */ + create(_cdr?: ChangeDetectorRef|TrackByFunction, trackByFn?: TrackByFunction): + IterableDiffer; } /** diff --git a/modules/@angular/core/src/change_detection/differs/keyvalue_differs.ts b/modules/@angular/core/src/change_detection/differs/keyvalue_differs.ts index 28dfd2c152182..401718ab8a592 100644 --- a/modules/@angular/core/src/change_detection/differs/keyvalue_differs.ts +++ b/modules/@angular/core/src/change_detection/differs/keyvalue_differs.ts @@ -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(cdRef: ChangeDetectorRef): KeyValueDiffer; + create(): KeyValueDiffer; + + /** + * @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter + */ + create(_cdr?: ChangeDetectorRef): KeyValueDiffer; } /** diff --git a/tools/public_api_guard/common/index.d.ts b/tools/public_api_guard/common/index.d.ts index 59e5a298f4f37..c86bbffa573a0 100644 --- a/tools/public_api_guard/common/index.d.ts +++ b/tools/public_api_guard/common/index.d.ts @@ -137,7 +137,7 @@ export declare class NgForOf implements DoCheck, OnChanges { ngForOf: NgIterable; ngForTemplate: TemplateRef>; ngForTrackBy: TrackByFunction; - constructor(_viewContainer: ViewContainerRef, _template: TemplateRef>, _differs: IterableDiffers, _cdr: ChangeDetectorRef); + constructor(_viewContainer: ViewContainerRef, _template: TemplateRef>, _differs: IterableDiffers); ngDoCheck(): void; ngOnChanges(changes: SimpleChanges): void; } diff --git a/tools/public_api_guard/core/index.d.ts b/tools/public_api_guard/core/index.d.ts index b816bbbc146fa..c13290b996544 100644 --- a/tools/public_api_guard/core/index.d.ts +++ b/tools/public_api_guard/core/index.d.ts @@ -556,7 +556,8 @@ export interface IterableDiffer { /** @stable */ export interface IterableDifferFactory { - create(cdRef: ChangeDetectorRef, trackByFn?: TrackByFunction): IterableDiffer; + create(trackByFn?: TrackByFunction): IterableDiffer; + /** @deprecated */ create(_cdr?: ChangeDetectorRef | TrackByFunction, trackByFn?: TrackByFunction): IterableDiffer; supports(objects: any): boolean; } @@ -598,7 +599,8 @@ export interface KeyValueDiffer { /** @stable */ export interface KeyValueDifferFactory { - create(cdRef: ChangeDetectorRef): KeyValueDiffer; + create(): KeyValueDiffer; + /** @deprecated */ create(_cdr?: ChangeDetectorRef): KeyValueDiffer; supports(objects: any): boolean; }