This commit is contained in:
vsavkin 2015-02-02 17:40:54 -08:00 committed by Alex Eagle
parent fc6e421e7e
commit 4b8105c165
5 changed files with 22 additions and 19 deletions

View File

@ -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) {

View File

@ -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;
}
}
}

View File

@ -56,6 +56,7 @@ export class ChangeDetector {
removeChild(cd:ChangeDetector) {}
remove() {}
setContext(context:any) {}
markPathToRootAsCheckOnce() {}
detectChanges() {}
checkNoChanges() {}

View File

@ -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);
});
});
});

View File

@ -12,7 +12,7 @@ export class BindingPropagationConfig {
}
shouldBePropagatedFromRoot() {
this._cd.markAsCheckOnce();
this._cd.markPathToRootAsCheckOnce();
}
shouldNotPropagate() {