perf(render): only create LightDom instances if the element has children

This commit is contained in:
Tobias Bosch
2015-06-10 15:54:10 -07:00
parent 4f27611ae6
commit ca09701343
5 changed files with 59 additions and 12 deletions
@@ -70,6 +70,25 @@ export function main() {
});
}));
it('should not create LightDom instances if the host element is empty',
inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
tb.compileAll([
someComponent,
new ViewDefinition({
componentId: 'someComponent', template: '<some-comp> <!-- comment -->\n </some-comp>',
directives: [someComponent]
})
])
.then((protoViewDtos) => {
var rootView = tb.createRootView(protoViewDtos[0]);
var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]);
expect(cmpView.rawView.proto.elementBinders[0].componentId).toBe('someComponent');
expect(cmpView.rawView.boundElements[0].lightDom).toBe(null);
async.done();
});
}));
it('should update text nodes', inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
tb.compileAll([
someComponent,
@@ -48,20 +48,24 @@ export function main() {
return new DomView(pv, [DOM.childNodes(root)[0]], [], boundElements);
}
function createElementBinder(parentIndex:number = 0, distanceToParent:number = 1) {
return new ElementBinder({parentIndex: parentIndex, distanceToParent:distanceToParent, textNodeIndices:[]});
}
describe('getDirectParentElement', () => {
it('should return the DomElement of the direct parent', () => {
var pv = createProtoView(
[new ElementBinder(), new ElementBinder({parentIndex: 0, distanceToParent: 1})]);
[createElementBinder(), createElementBinder(0, 1)]);
var view = createView(pv, 2);
expect(view.getDirectParentElement(1)).toBe(view.boundElements[0]);
});
it('should return null if the direct parent is not bound', () => {
var pv = createProtoView([
new ElementBinder(),
new ElementBinder(),
new ElementBinder({parentIndex: 0, distanceToParent: 2})
createElementBinder(),
createElementBinder(),
createElementBinder(0,2)
]);
var view = createView(pv, 3);
expect(view.getDirectParentElement(2)).toBe(null);