fix(render): allow to configure when templates are serialized to strings

Introduces the injectable `TemplateCloner` that can be configured via the new token `MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE_TOKEN`.

Also replaces `document.adoptNode` with `document.importNode` as otherwise
custom elements are not triggered in chrome 43.

Closes #3418
Closes #3433
This commit is contained in:
Tobias Bosch
2015-07-31 10:58:24 -07:00
parent 014b6cb397
commit dd06a871b7
24 changed files with 310 additions and 222 deletions

View File

@ -38,6 +38,8 @@ import {
ViewEncapsulation
} from 'angular2/angular2';
import {MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE_TOKEN} from 'angular2/src/render/render';
export function main() {
describe('projection', () => {
it('should support simple components',
@ -416,6 +418,44 @@ export function main() {
}));
}
describe('different proto view storages', () => {
function runTests() {
it('should support nested conditionals that contain ng-contents',
inject(
[TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MainComp, new viewAnn.View({
template: `<conditional-text>a</conditional-text>`,
directives: [ConditionalTextComponent]
}))
.createAsync(MainComp)
.then((main) => {
expect(main.nativeElement).toHaveText('MAIN()');
var viewportElement = main.componentViewChildren[0].componentViewChildren[0];
viewportElement.inject(ManualViewportDirective).show();
expect(main.nativeElement).toHaveText('MAIN(FIRST())');
viewportElement = main.componentViewChildren[0].componentViewChildren[1];
viewportElement.inject(ManualViewportDirective).show();
expect(main.nativeElement).toHaveText('MAIN(FIRST(SECOND(a)))');
async.done();
});
}));
}
describe('serialize templates', () => {
beforeEachBindings(() => [bind(MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE_TOKEN).toValue(0)]);
runTests();
});
describe("don't serialize templates", () => {
beforeEachBindings(() => [bind(MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE_TOKEN).toValue(-1)]);
runTests();
});
});
});
}
@ -508,6 +548,15 @@ class InnerInnerComponent {
class ConditionalContentComponent {
}
@Component({selector: 'conditional-text'})
@View({
template:
'MAIN(<template manual>FIRST(<template manual>SECOND(<ng-content></ng-content>)</template>)</template>)',
directives: [ManualViewportDirective]
})
class ConditionalTextComponent {
}
@Component({selector: 'tab'})
@View({
template: '<div><div *manual>TAB(<ng-content></ng-content>)</div></div>',