diff --git a/modules/change_detection/src/abstract_change_detector.js b/modules/change_detection/src/abstract_change_detector.js index 3073463dae..d24c967e58 100644 --- a/modules/change_detection/src/abstract_change_detector.js +++ b/modules/change_detection/src/abstract_change_detector.js @@ -42,14 +42,6 @@ export class AbstractChangeDetector extends ChangeDetector { if (this.mode === CHECK_ONCE) this.mode = CHECKED; } - markAsCheckOnce(){ - var c = this; - while(isPresent(c) && (c.mode === CHECKED || c.mode === CHECK_ALWAYS)) { - if (c.mode === CHECKED) c.mode = CHECK_ONCE; - c = c.parent; - } - } - detectChangesInRecords(throwOnChange:boolean){} _detectChangesInChildren(throwOnChange:boolean) { diff --git a/modules/change_detection/src/change_detection_util.js b/modules/change_detection/src/change_detection_util.js index 31491c2200..e351b1cfc6 100644 --- a/modules/change_detection/src/change_detection_util.js +++ b/modules/change_detection/src/change_detection_util.js @@ -5,7 +5,7 @@ import {ArrayChanges} from './array_changes'; import {KeyValueChanges} from './keyvalue_changes'; import {ProtoRecord} from './proto_change_detector'; import {ExpressionChangedAfterItHasBeenChecked} from './exceptions'; -import {ChangeRecord} from './interfaces'; +import {ChangeRecord, ChangeDetector, CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from './interfaces'; export var uninitialized = new Object(); @@ -214,4 +214,12 @@ export class ChangeDetectionUtil { } return updatedRecords; } + + static markPathToRootAsCheckOnce(cd:ChangeDetector) { + var c = cd; + while(isPresent(c) && c.mode != DETACHED) { + if (c.mode === CHECKED) c.mode = CHECK_ONCE; + c = c.parent; + } + } } \ No newline at end of file diff --git a/modules/change_detection/src/interfaces.js b/modules/change_detection/src/interfaces.js index 25c79237c8..77a06a392d 100644 --- a/modules/change_detection/src/interfaces.js +++ b/modules/change_detection/src/interfaces.js @@ -56,6 +56,7 @@ export class ChangeDetector { removeChild(cd:ChangeDetector) {} remove() {} setContext(context:any) {} + markPathToRootAsCheckOnce() {} detectChanges() {} checkNoChanges() {} diff --git a/modules/change_detection/test/change_detection_spec.js b/modules/change_detection/test/change_detection_spec.js index 03adc37ce7..7cde272f63 100644 --- a/modules/change_detection/test/change_detection_spec.js +++ b/modules/change_detection/test/change_detection_spec.js @@ -8,12 +8,12 @@ import {Lexer} from 'change_detection/src/parser/lexer'; import {reflector} from 'reflection/src/reflection'; import {arrayChangesAsString, kvChangesAsString} from './util'; -import {ChangeDispatcher, DynamicChangeDetector, ChangeDetectionError, ContextWithVariableBindings} - from 'change_detection/change_detection'; +import {ChangeDispatcher, DynamicChangeDetector, ChangeDetectionError, ContextWithVariableBindings, + CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from 'change_detection/change_detection'; import {JitProtoChangeDetector, DynamicProtoChangeDetector} from 'change_detection/src/proto_change_detector'; -import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from 'change_detection/src/interfaces'; +import {ChangeDetectionUtil} from 'change_detection/src/change_detection_util'; export function main() { @@ -517,7 +517,7 @@ export function main() { }); }); - describe("markAsCheckOnce", () => { + describe("markPathToRootAsCheckOnce", () => { function changeDetector(mode, parent) { var cd = createProtoChangeDetector().instantiate(null, null); cd.mode = mode; @@ -531,16 +531,18 @@ export function main() { var root = changeDetector(CHECK_ALWAYS, null); var disabled = changeDetector(DETACHED, root); var parent = changeDetector(CHECKED, disabled); - var child = changeDetector(CHECK_ALWAYS, parent); - var grandChild = changeDetector(CHECKED, child); + var checkAlwaysChild = changeDetector(CHECK_ALWAYS, parent); + var checkOnceChild = changeDetector(CHECK_ONCE, checkAlwaysChild); + var checkedChild = changeDetector(CHECKED, checkOnceChild); - grandChild.markAsCheckOnce(); + ChangeDetectionUtil.markPathToRootAsCheckOnce(checkedChild); expect(root.mode).toEqual(CHECK_ALWAYS); expect(disabled.mode).toEqual(DETACHED); expect(parent.mode).toEqual(CHECK_ONCE); - expect(child.mode).toEqual(CHECK_ALWAYS); - expect(grandChild.mode).toEqual(CHECK_ONCE); + expect(checkAlwaysChild.mode).toEqual(CHECK_ALWAYS); + expect(checkOnceChild.mode).toEqual(CHECK_ONCE); + expect(checkedChild.mode).toEqual(CHECK_ONCE); }); }); }); diff --git a/modules/core/src/compiler/binding_propagation_config.js b/modules/core/src/compiler/binding_propagation_config.js index 0d23249614..164fd7ed66 100644 --- a/modules/core/src/compiler/binding_propagation_config.js +++ b/modules/core/src/compiler/binding_propagation_config.js @@ -12,7 +12,7 @@ export class BindingPropagationConfig { } shouldBePropagatedFromRoot() { - this._cd.markAsCheckOnce(); + this._cd.markPathToRootAsCheckOnce(); } shouldNotPropagate() {