Skip to content

Commit

Permalink
fix(core): Remove ChangeDetectorRef Paramter from KeyValueDifferFacto…
Browse files Browse the repository at this point in the history
…ry and IterableDifferFactory (angular#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.
  • Loading branch information
FrozenPandaz authored and juleskremer committed Aug 24, 2017
1 parent 9231765 commit a09902e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 14 deletions.
4 changes: 2 additions & 2 deletions modules/@angular/common/src/directives/ng_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/@angular/common/src/directives/ng_for_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>>) {
Expand All @@ -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.`);
Expand Down Expand Up @@ -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> {}
2 changes: 1 addition & 1 deletion modules/@angular/common/src/directives/ng_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/common/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/public_api_guard/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a09902e

Please sign in to comment.