From cebd670a8ed24e0ae4040ad275ea53f0c07a12c1 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 28 Aug 2015 10:08:18 -0700 Subject: [PATCH] refactor(ChandeDetection): Rename ChangeDetectorRef.markForCheck BREAKING CHANGE Closes #3403 - ChangeDetectorRef.requestCheck() => ChangeDetectorRef.markForCheck() --- .../src/core/change_detection/abstract_change_detector.ts | 8 ++++---- .../src/core/change_detection/change_detector_ref.ts | 7 +++---- .../src/core/directives/observable_list_diff.dart | 2 +- modules/angular2/src/core/pipes/async_pipe.ts | 2 +- modules/angular2/test/core/compiler/integration_spec.ts | 2 +- .../test/core/directives/observable_list_diff_spec.dart | 2 +- modules/angular2/test/pipes/async_pipe_spec.ts | 4 ++-- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/angular2/src/core/change_detection/abstract_change_detector.ts b/modules/angular2/src/core/change_detection/abstract_change_detector.ts index 80b1b6022f..baf66e1f32 100644 --- a/modules/angular2/src/core/change_detection/abstract_change_detector.ts +++ b/modules/angular2/src/core/change_detection/abstract_change_detector.ts @@ -220,11 +220,11 @@ export class AbstractChangeDetector implements ChangeDetector { this._createArrayToStoreObservables(); if (isBlank(this.subscriptions[index])) { this.streams[index] = value.changes; - this.subscriptions[index] = value.changes.listen((_) => this.ref.requestCheck()); + this.subscriptions[index] = value.changes.listen((_) => this.ref.markForCheck()); } else if (this.streams[index] !== value.changes) { this.subscriptions[index].cancel(); this.streams[index] = value.changes; - this.subscriptions[index] = value.changes.listen((_) => this.ref.requestCheck()); + this.subscriptions[index] = value.changes.listen((_) => this.ref.markForCheck()); } } return value; @@ -236,7 +236,7 @@ export class AbstractChangeDetector implements ChangeDetector { this._createArrayToStoreObservables(); var arrayIndex = this.numberOfPropertyProtoRecords + index + 2; // +1 is component this.streams[arrayIndex] = value.changes; - this.subscriptions[arrayIndex] = value.changes.listen((_) => this.ref.requestCheck()); + this.subscriptions[arrayIndex] = value.changes.listen((_) => this.ref.markForCheck()); } return value; } @@ -247,7 +247,7 @@ export class AbstractChangeDetector implements ChangeDetector { this._createArrayToStoreObservables(); var index = this.numberOfPropertyProtoRecords + 1; this.streams[index] = value.changes; - this.subscriptions[index] = value.changes.listen((_) => this.ref.requestCheck()); + this.subscriptions[index] = value.changes.listen((_) => this.ref.markForCheck()); } return value; } diff --git a/modules/angular2/src/core/change_detection/change_detector_ref.ts b/modules/angular2/src/core/change_detection/change_detector_ref.ts index d03a2b5374..8e5bf2f17a 100644 --- a/modules/angular2/src/core/change_detection/change_detector_ref.ts +++ b/modules/angular2/src/core/change_detection/change_detector_ref.ts @@ -16,7 +16,7 @@ export class ChangeDetectorRef { /** * Request to check all OnPush ancestors. */ - requestCheck(): void { this._cd.markPathToRootAsCheckOnce(); } + markForCheck(): void { this._cd.markPathToRootAsCheckOnce(); } /** * Detaches the change detector from the change detector tree. @@ -29,11 +29,10 @@ export class ChangeDetectorRef { * Reattach the change detector to the change detector tree. * * This also requests a check of this change detector. This reattached change detector will be - *checked during the - * next change detection run. + * checked during the next change detection run. */ reattach(): void { this._cd.mode = ChangeDetectionStrategy.CheckAlways; - this.requestCheck(); + this.markForCheck(); } } diff --git a/modules/angular2/src/core/directives/observable_list_diff.dart b/modules/angular2/src/core/directives/observable_list_diff.dart index 52b42fd800..ac9800d92a 100644 --- a/modules/angular2/src/core/directives/observable_list_diff.dart +++ b/modules/angular2/src/core/directives/observable_list_diff.dart @@ -35,7 +35,7 @@ class ObservableListDiff extends DefaultIterableDiffer { if (_subscription != null) _subscription.cancel(); _subscription = collection.changes.listen((_) { _updated = true; - _ref.requestCheck(); + _ref.markForCheck(); }); _updated = false; return super.diff(collection); diff --git a/modules/angular2/src/core/pipes/async_pipe.ts b/modules/angular2/src/core/pipes/async_pipe.ts index c0c9359b95..08b0ae6963 100644 --- a/modules/angular2/src/core/pipes/async_pipe.ts +++ b/modules/angular2/src/core/pipes/async_pipe.ts @@ -124,7 +124,7 @@ export class AsyncPipe implements PipeTransform, PipeOnDestroy { _updateLatestValue(async: any, value: Object) { if (async === this._obj) { this._latestValue = value; - this._ref.requestCheck(); + this._ref.markForCheck(); } } } diff --git a/modules/angular2/test/core/compiler/integration_spec.ts b/modules/angular2/test/core/compiler/integration_spec.ts index 13ca2a012e..c911421db3 100644 --- a/modules/angular2/test/core/compiler/integration_spec.ts +++ b/modules/angular2/test/core/compiler/integration_spec.ts @@ -1685,7 +1685,7 @@ class PushCmpWithRef { return "fixed"; } - propagate() { this.ref.requestCheck(); } + propagate() { this.ref.markForCheck(); } } @Component({selector: 'push-cmp-with-async', changeDetection: ChangeDetectionStrategy.OnPush}) diff --git a/modules/angular2/test/core/directives/observable_list_diff_spec.dart b/modules/angular2/test/core/directives/observable_list_diff_spec.dart index ccb2ebb616..0097c55106 100644 --- a/modules/angular2/test/core/directives/observable_list_diff_spec.dart +++ b/modules/angular2/test/core/directives/observable_list_diff_spec.dart @@ -73,7 +73,7 @@ main() { c.add(3); flushMicrotasks(); - expect(changeDetectorRef.spy("requestCheck")).toHaveBeenCalledOnce(); + expect(changeDetectorRef.spy("markForCheck")).toHaveBeenCalledOnce(); })); it("should return the wrapped value after changing a collection", () { diff --git a/modules/angular2/test/pipes/async_pipe_spec.ts b/modules/angular2/test/pipes/async_pipe_spec.ts index 6336bb1bbf..154c426127 100644 --- a/modules/angular2/test/pipes/async_pipe_spec.ts +++ b/modules/angular2/test/pipes/async_pipe_spec.ts @@ -91,7 +91,7 @@ export function main() { ObservableWrapper.callNext(emitter, message); TimerWrapper.setTimeout(() => { - expect(ref.spy('requestCheck')).toHaveBeenCalled(); + expect(ref.spy('markForCheck')).toHaveBeenCalled(); async.done(); }, 0) })); @@ -178,7 +178,7 @@ export function main() { completer.resolve(message); TimerWrapper.setTimeout(() => { - expect(ref.spy('requestCheck')).toHaveBeenCalled(); + expect(ref.spy('markForCheck')).toHaveBeenCalled(); async.done(); }, timer) }));