Skip to content

Commit 4f57990

Browse files
committed
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.
1 parent 9dc1d6a commit 4f57990

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

modules/angular2/src/core/life_cycle/life_cycle.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ import {wtfLeave, wtfCreateScope, WtfScopeFn} from '../profile/profile';
3535
export class LifeCycle {
3636
static _tickScope: WtfScopeFn = wtfCreateScope('LifeCycle#tick()');
3737

38-
_changeDetector: ChangeDetector;
38+
_changeDetectors: ChangeDetector[];
3939
_enforceNoNewChanges: boolean;
4040
_runningTick: boolean = false;
4141

4242
constructor(changeDetector: ChangeDetector = null, enforceNoNewChanges: boolean = false) {
43-
this._changeDetector =
44-
changeDetector; // may be null when instantiated from application bootstrap
43+
this._changeDetectors = [];
44+
if (isPresent(changeDetector)) {
45+
this._changeDetectors.push(changeDetector);
46+
}
4547
this._enforceNoNewChanges = enforceNoNewChanges;
4648
}
4749

@@ -50,7 +52,7 @@ export class LifeCycle {
5052
*/
5153
registerWith(zone: NgZone, changeDetector: ChangeDetector = null) {
5254
if (isPresent(changeDetector)) {
53-
this._changeDetector = changeDetector;
55+
this._changeDetectors.push(changeDetector);
5456
}
5557
zone.overrideOnTurnDone(() => this.tick());
5658
}
@@ -78,9 +80,9 @@ export class LifeCycle {
7880
var s = LifeCycle._tickScope();
7981
try {
8082
this._runningTick = true;
81-
this._changeDetector.detectChanges();
83+
this._changeDetectors.forEach((detector) => detector.detectChanges());
8284
if (this._enforceNoNewChanges) {
83-
this._changeDetector.checkNoChanges();
85+
this._changeDetectors.forEach((detector) => detector.checkNoChanges());
8486
}
8587
} finally {
8688
this._runningTick = false;

0 commit comments

Comments
 (0)