2015-02-05 13:08:05 -08:00
|
|
|
import {isPresent} from 'angular2/src/facade/lang';
|
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
2015-02-27 13:38:25 -08:00
|
|
|
import {BindingPropagationConfig} from './binding_propagation_config';
|
2015-02-01 12:09:35 -08:00
|
|
|
import {ChangeDetector, CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from './interfaces';
|
2015-01-21 12:05:52 -08:00
|
|
|
|
|
|
|
export class AbstractChangeDetector extends ChangeDetector {
|
|
|
|
children:List;
|
|
|
|
parent:ChangeDetector;
|
2015-02-06 13:29:24 -08:00
|
|
|
mode:string;
|
2015-02-27 13:38:25 -08:00
|
|
|
bindingPropagationConfig:BindingPropagationConfig;
|
2015-01-21 12:05:52 -08:00
|
|
|
|
|
|
|
constructor() {
|
2015-02-06 13:38:52 -08:00
|
|
|
super();
|
2015-01-21 12:05:52 -08:00
|
|
|
this.children = [];
|
2015-02-27 13:38:25 -08:00
|
|
|
this.bindingPropagationConfig = new BindingPropagationConfig(this);
|
2015-02-06 13:29:24 -08:00
|
|
|
this.mode = CHECK_ALWAYS;
|
2015-01-21 12:05:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
addChild(cd:ChangeDetector) {
|
|
|
|
ListWrapper.push(this.children, cd);
|
|
|
|
cd.parent = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
removeChild(cd:ChangeDetector) {
|
|
|
|
ListWrapper.remove(this.children, cd);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove() {
|
|
|
|
this.parent.removeChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
detectChanges() {
|
|
|
|
this._detectChanges(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
checkNoChanges() {
|
|
|
|
this._detectChanges(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
_detectChanges(throwOnChange:boolean) {
|
2015-02-01 12:09:35 -08:00
|
|
|
if (this.mode === DETACHED || this.mode === CHECKED) return;
|
|
|
|
|
2015-01-21 12:05:52 -08:00
|
|
|
this.detectChangesInRecords(throwOnChange);
|
|
|
|
this._detectChangesInChildren(throwOnChange);
|
2015-03-26 14:36:25 -07:00
|
|
|
this.notifyOnAllChangesDone();
|
2015-02-01 12:09:35 -08:00
|
|
|
|
|
|
|
if (this.mode === CHECK_ONCE) this.mode = CHECKED;
|
|
|
|
}
|
|
|
|
|
2015-01-21 12:05:52 -08:00
|
|
|
detectChangesInRecords(throwOnChange:boolean){}
|
2015-03-26 14:36:25 -07:00
|
|
|
notifyOnAllChangesDone(){}
|
2015-01-21 12:05:52 -08:00
|
|
|
|
|
|
|
_detectChangesInChildren(throwOnChange:boolean) {
|
|
|
|
var children = this.children;
|
|
|
|
for(var i = 0; i < children.length; ++i) {
|
|
|
|
children[i]._detectChanges(throwOnChange);
|
|
|
|
}
|
|
|
|
}
|
2015-02-11 16:28:10 -08:00
|
|
|
|
|
|
|
markPathToRootAsCheckOnce() {
|
|
|
|
var c = this;
|
|
|
|
while(isPresent(c) && c.mode != DETACHED) {
|
|
|
|
if (c.mode === CHECKED) c.mode = CHECK_ONCE;
|
|
|
|
c = c.parent;
|
|
|
|
}
|
|
|
|
}
|
2015-01-21 12:05:52 -08:00
|
|
|
}
|