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-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-01-21 12:05:52 -08:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.children = [];
|
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-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){}
|
|
|
|
|
|
|
|
_detectChangesInChildren(throwOnChange:boolean) {
|
|
|
|
var children = this.children;
|
|
|
|
for(var i = 0; i < children.length; ++i) {
|
|
|
|
children[i]._detectChanges(throwOnChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|