2015-02-05 13:08:05 -08:00
|
|
|
import {isPresent} from 'angular2/src/facade/lang';
|
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
2015-04-14 07:47:12 -07:00
|
|
|
import {ChangeDetectorRef} from './change_detector_ref';
|
2015-03-30 16:54:10 -07:00
|
|
|
import {ChangeDetector} from './interfaces';
|
|
|
|
import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED, ON_PUSH} from './constants';
|
2015-01-21 12:05:52 -08:00
|
|
|
|
|
|
|
export class AbstractChangeDetector extends ChangeDetector {
|
2015-03-27 11:02:55 -07:00
|
|
|
lightDomChildren:List;
|
|
|
|
shadowDomChildren:List;
|
2015-01-21 12:05:52 -08:00
|
|
|
parent:ChangeDetector;
|
2015-02-06 13:29:24 -08:00
|
|
|
mode:string;
|
2015-04-14 08:54:09 -07:00
|
|
|
ref:ChangeDetectorRef;
|
2015-01-21 12:05:52 -08:00
|
|
|
|
|
|
|
constructor() {
|
2015-02-06 13:38:52 -08:00
|
|
|
super();
|
2015-03-27 11:02:55 -07:00
|
|
|
this.lightDomChildren = [];
|
|
|
|
this.shadowDomChildren = [];
|
2015-04-14 08:54:09 -07:00
|
|
|
this.ref = new ChangeDetectorRef(this);
|
2015-03-30 16:54:10 -07:00
|
|
|
this.mode = null;
|
2015-01-21 12:05:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
addChild(cd:ChangeDetector) {
|
2015-03-27 11:02:55 -07:00
|
|
|
ListWrapper.push(this.lightDomChildren, cd);
|
2015-01-21 12:05:52 -08:00
|
|
|
cd.parent = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
removeChild(cd:ChangeDetector) {
|
2015-03-27 11:02:55 -07:00
|
|
|
ListWrapper.remove(this.lightDomChildren, cd);
|
|
|
|
}
|
|
|
|
|
|
|
|
addShadowDomChild(cd:ChangeDetector) {
|
|
|
|
ListWrapper.push(this.shadowDomChildren, cd);
|
|
|
|
cd.parent = this;
|
2015-01-21 12:05:52 -08:00
|
|
|
}
|
|
|
|
|
2015-04-14 18:01:08 -07:00
|
|
|
removeShadowDomChild(cd:ChangeDetector) {
|
|
|
|
ListWrapper.remove(this.shadowDomChildren, cd);
|
|
|
|
}
|
|
|
|
|
2015-01-21 12:05:52 -08:00
|
|
|
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);
|
2015-03-27 11:02:55 -07:00
|
|
|
|
|
|
|
this._detectChangesInLightDomChildren(throwOnChange);
|
|
|
|
|
2015-03-31 07:47:26 -07:00
|
|
|
this.callOnAllChangesDone();
|
2015-02-01 12:09:35 -08:00
|
|
|
|
2015-03-27 11:02:55 -07:00
|
|
|
this._detectChangesInShadowDomChildren(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){}
|
2015-03-31 07:47:26 -07:00
|
|
|
callOnAllChangesDone(){}
|
2015-01-21 12:05:52 -08:00
|
|
|
|
2015-03-27 11:02:55 -07:00
|
|
|
_detectChangesInLightDomChildren(throwOnChange:boolean) {
|
|
|
|
var c = this.lightDomChildren;
|
|
|
|
for(var i = 0; i < c.length; ++i) {
|
|
|
|
c[i]._detectChanges(throwOnChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_detectChangesInShadowDomChildren(throwOnChange:boolean) {
|
|
|
|
var c = this.shadowDomChildren;
|
|
|
|
for(var i = 0; i < c.length; ++i) {
|
|
|
|
c[i]._detectChanges(throwOnChange);
|
2015-01-21 12:05:52 -08:00
|
|
|
}
|
|
|
|
}
|
2015-02-11 16:28:10 -08:00
|
|
|
|
2015-04-14 08:54:09 -07:00
|
|
|
markAsCheckOnce() {
|
|
|
|
this.mode = CHECK_ONCE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|