From f0d6464856a5aff7610606b26fe5822a307a5568 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 17 Nov 2014 17:22:45 -0800 Subject: [PATCH] feat(ChangeDetector): change View to construct a WatchGroup hierarchy --- modules/change_detection/src/watch_group.js | 13 ++----------- .../change_detection/test/watch_group_spec.js | 16 ++++++++++++++++ modules/core/src/compiler/view.js | 1 + modules/core/test/compiler/integration_spec.js | 4 ---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/change_detection/src/watch_group.js b/modules/change_detection/src/watch_group.js index 861cf73358..bf8c5f696e 100644 --- a/modules/change_detection/src/watch_group.js +++ b/modules/change_detection/src/watch_group.js @@ -94,6 +94,7 @@ export class WatchGroup { this.prev = null; } + /// addRecord must be called before addChild addRecord(record:Record) { if (isPresent(this.tailRecord)) { this.tailRecord.next = record; @@ -156,14 +157,12 @@ export class WatchGroup { addChild(child:WatchGroup) { if (isBlank(this.childTail)) { this.childHead = this.childTail = child; - this._attachRecordsFromWatchGroup(child); - } else { this.childTail.next = child; child.prev = this.childTail; this.childTail = child; - this._attachRecordsFromWatchGroup(child); } + this._attachRecordsFromWatchGroup(child); } _attachRecordsFromWatchGroup(child:WatchGroup) { @@ -199,14 +198,6 @@ export class WatchGroup { record.updateContext(context); } } - - get _tailRecordIncludingChildren():Record { - var lastGroup = this; - while (lastGroup.childTail !== null) { - lastGroup = lastGroup.childTail; - } - return lastGroup.tailRecord; - } } export class WatchGroupDispatcher { diff --git a/modules/change_detection/test/watch_group_spec.js b/modules/change_detection/test/watch_group_spec.js index 205d4d2fc1..bead04e19c 100644 --- a/modules/change_detection/test/watch_group_spec.js +++ b/modules/change_detection/test/watch_group_spec.js @@ -137,6 +137,22 @@ export function main() { expect(parent.childHead).toBe(firstChild); expect(parent.childTail).toBe(secondChild); }); + + // todo: vsavkin: enable after refactoring addChild + xit("should update head and tail of the parent when disabling the only record" + + "of the child", () => { + var parent = new WatchGroup(null, null); + + var child = new WatchGroup(null, null); + var record = createRecord(child); + child.addRecord(record); + parent.addChild(child); + + child.disableRecord(record); + + expect(parent.headRecord).toBeNull(); + expect(parent.tailRecord).toBeNull(); + }); }); describe("enabling/disabling records", () => { diff --git a/modules/core/src/compiler/view.js b/modules/core/src/compiler/view.js index 17a35db79e..b4dfb0c037 100644 --- a/modules/core/src/compiler/view.js +++ b/modules/core/src/compiler/view.js @@ -65,6 +65,7 @@ export class View { addChild(childView: View) { ListWrapper.push(this.childViews, childView); + this.watchGroup.addChild(childView.watchGroup); } } diff --git a/modules/core/test/compiler/integration_spec.js b/modules/core/test/compiler/integration_spec.js index 8877ae6494..040f654f5c 100644 --- a/modules/core/test/compiler/integration_spec.js +++ b/modules/core/test/compiler/integration_spec.js @@ -74,10 +74,6 @@ export function main() { cd.detectChanges(); - // TODO(rado): this should be removed once watchgroups addChild is implemented. - var childWatchGroup = view.childViews[0].watchGroup; - new ChangeDetector(childWatchGroup).detectChanges(); - expect(view.nodes[0].shadowRoot.childNodes[0].nodeValue).toEqual('hello'); done(); });