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 {
|
||||
static _tickScope: WtfScopeFn = wtfCreateScope('LifeCycle#tick()');
|
||||
|
||||
_changeDetector: ChangeDetector;
|
||||
_changeDetectors: ChangeDetector[];
|
||||
_enforceNoNewChanges: boolean;
|
||||
_runningTick: boolean = false;
|
||||
|
||||
constructor(changeDetector: ChangeDetector = null, enforceNoNewChanges: boolean = false) {
|
||||
this._changeDetector =
|
||||
changeDetector; // may be null when instantiated from application bootstrap
|
||||
this._changeDetectors = [];
|
||||
if (isPresent(changeDetector)) {
|
||||
this._changeDetectors.push(changeDetector);
|
||||
}
|
||||
this._enforceNoNewChanges = enforceNoNewChanges;
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,7 @@ export class LifeCycle {
|
|||
*/
|
||||
registerWith(zone: NgZone, changeDetector: ChangeDetector = null) {
|
||||
if (isPresent(changeDetector)) {
|
||||
this._changeDetector = changeDetector;
|
||||
this._changeDetectors.push(changeDetector);
|
||||
}
|
||||
zone.overrideOnTurnDone(() => this.tick());
|
||||
}
|
||||
|
@ -78,9 +80,9 @@ export class LifeCycle {
|
|||
var s = LifeCycle._tickScope();
|
||||
try {
|
||||
this._runningTick = true;
|
||||
this._changeDetector.detectChanges();
|
||||
this._changeDetectors.forEach((detector) => detector.detectChanges());
|
||||
if (this._enforceNoNewChanges) {
|
||||
this._changeDetector.checkNoChanges();
|
||||
this._changeDetectors.forEach((detector) => detector.checkNoChanges());
|
||||
}
|
||||
} finally {
|
||||
this._runningTick = false;
|
||||
|
|
Loading…
Reference in New Issue