From 4f57990d45cb3876449f8431a43482609bcf3907 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Wed, 2 Sep 2015 15:19:17 -0700 Subject: [PATCH] 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. --- modules/angular2/src/core/life_cycle/life_cycle.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/angular2/src/core/life_cycle/life_cycle.ts b/modules/angular2/src/core/life_cycle/life_cycle.ts index 6b65bc07c8..9c3d4bf291 100644 --- a/modules/angular2/src/core/life_cycle/life_cycle.ts +++ b/modules/angular2/src/core/life_cycle/life_cycle.ts @@ -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;