feat(ChangeDetector): change View to construct a WatchGroup hierarchy

This commit is contained in:
vsavkin 2014-11-17 17:22:45 -08:00
parent 384f0ae858
commit f0d6464856
4 changed files with 19 additions and 15 deletions

View File

@ -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 {

View File

@ -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", () => {

View File

@ -65,6 +65,7 @@ export class View {
addChild(childView: View) {
ListWrapper.push(this.childViews, childView);
this.watchGroup.addChild(childView.watchGroup);
}
}

View File

@ -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();
});