feat(ChangeDetector): change View to construct a WatchGroup hierarchy
This commit is contained in:
parent
384f0ae858
commit
f0d6464856
|
@ -94,6 +94,7 @@ export class WatchGroup {
|
||||||
this.prev = null;
|
this.prev = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// addRecord must be called before addChild
|
||||||
addRecord(record:Record) {
|
addRecord(record:Record) {
|
||||||
if (isPresent(this.tailRecord)) {
|
if (isPresent(this.tailRecord)) {
|
||||||
this.tailRecord.next = record;
|
this.tailRecord.next = record;
|
||||||
|
@ -156,14 +157,12 @@ export class WatchGroup {
|
||||||
addChild(child:WatchGroup) {
|
addChild(child:WatchGroup) {
|
||||||
if (isBlank(this.childTail)) {
|
if (isBlank(this.childTail)) {
|
||||||
this.childHead = this.childTail = child;
|
this.childHead = this.childTail = child;
|
||||||
this._attachRecordsFromWatchGroup(child);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.childTail.next = child;
|
this.childTail.next = child;
|
||||||
child.prev = this.childTail;
|
child.prev = this.childTail;
|
||||||
this.childTail = child;
|
this.childTail = child;
|
||||||
this._attachRecordsFromWatchGroup(child);
|
|
||||||
}
|
}
|
||||||
|
this._attachRecordsFromWatchGroup(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
_attachRecordsFromWatchGroup(child:WatchGroup) {
|
_attachRecordsFromWatchGroup(child:WatchGroup) {
|
||||||
|
@ -199,14 +198,6 @@ export class WatchGroup {
|
||||||
record.updateContext(context);
|
record.updateContext(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get _tailRecordIncludingChildren():Record {
|
|
||||||
var lastGroup = this;
|
|
||||||
while (lastGroup.childTail !== null) {
|
|
||||||
lastGroup = lastGroup.childTail;
|
|
||||||
}
|
|
||||||
return lastGroup.tailRecord;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WatchGroupDispatcher {
|
export class WatchGroupDispatcher {
|
||||||
|
|
|
@ -137,6 +137,22 @@ export function main() {
|
||||||
expect(parent.childHead).toBe(firstChild);
|
expect(parent.childHead).toBe(firstChild);
|
||||||
expect(parent.childTail).toBe(secondChild);
|
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", () => {
|
describe("enabling/disabling records", () => {
|
||||||
|
|
|
@ -65,6 +65,7 @@ export class View {
|
||||||
|
|
||||||
addChild(childView: View) {
|
addChild(childView: View) {
|
||||||
ListWrapper.push(this.childViews, childView);
|
ListWrapper.push(this.childViews, childView);
|
||||||
|
this.watchGroup.addChild(childView.watchGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,6 @@ export function main() {
|
||||||
|
|
||||||
cd.detectChanges();
|
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');
|
expect(view.nodes[0].shadowRoot.childNodes[0].nodeValue).toEqual('hello');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue