feat(core): Support multiple ChangeDetectors in a single LifeCycle.
This allows a single LifeCycle to be shared among multiple root components, since each root component has its own ChangeDetector configured.
This commit is contained in:
parent
9dc1d6ae81
commit
4f57990d45
|
@ -35,13 +35,15 @@ import {wtfLeave, wtfCreateScope, WtfScopeFn} from '../profile/profile';
|
||||||
export class LifeCycle {
|
export class LifeCycle {
|
||||||
static _tickScope: WtfScopeFn = wtfCreateScope('LifeCycle#tick()');
|
static _tickScope: WtfScopeFn = wtfCreateScope('LifeCycle#tick()');
|
||||||
|
|
||||||
_changeDetector: ChangeDetector;
|
_changeDetectors: ChangeDetector[];
|
||||||
_enforceNoNewChanges: boolean;
|
_enforceNoNewChanges: boolean;
|
||||||
_runningTick: boolean = false;
|
_runningTick: boolean = false;
|
||||||
|
|
||||||
constructor(changeDetector: ChangeDetector = null, enforceNoNewChanges: boolean = false) {
|
constructor(changeDetector: ChangeDetector = null, enforceNoNewChanges: boolean = false) {
|
||||||
this._changeDetector =
|
this._changeDetectors = [];
|
||||||
changeDetector; // may be null when instantiated from application bootstrap
|
if (isPresent(changeDetector)) {
|
||||||
|
this._changeDetectors.push(changeDetector);
|
||||||
|
}
|
||||||
this._enforceNoNewChanges = enforceNoNewChanges;
|
this._enforceNoNewChanges = enforceNoNewChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ export class LifeCycle {
|
||||||
*/
|
*/
|
||||||
registerWith(zone: NgZone, changeDetector: ChangeDetector = null) {
|
registerWith(zone: NgZone, changeDetector: ChangeDetector = null) {
|
||||||
if (isPresent(changeDetector)) {
|
if (isPresent(changeDetector)) {
|
||||||
this._changeDetector = changeDetector;
|
this._changeDetectors.push(changeDetector);
|
||||||
}
|
}
|
||||||
zone.overrideOnTurnDone(() => this.tick());
|
zone.overrideOnTurnDone(() => this.tick());
|
||||||
}
|
}
|
||||||
|
@ -78,9 +80,9 @@ export class LifeCycle {
|
||||||
var s = LifeCycle._tickScope();
|
var s = LifeCycle._tickScope();
|
||||||
try {
|
try {
|
||||||
this._runningTick = true;
|
this._runningTick = true;
|
||||||
this._changeDetector.detectChanges();
|
this._changeDetectors.forEach((detector) => detector.detectChanges());
|
||||||
if (this._enforceNoNewChanges) {
|
if (this._enforceNoNewChanges) {
|
||||||
this._changeDetector.checkNoChanges();
|
this._changeDetectors.forEach((detector) => detector.checkNoChanges());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this._runningTick = false;
|
this._runningTick = false;
|
||||||
|
|
Loading…
Reference in New Issue