Prerequisite: #595
Goal
A given Component needs to be able to use different templates per locale, device type (and test). This requires that we decouple @Component definition from TemplateConfig (and rename TemplateConfig to @Template)
Example
Simple Component (with separate Template annotation)
@Component({ selector: 'my-component' })
@Template({
url: 'some/url'
})
class MyComponent {
}
As more local devices get added to the system we can add @Template()
@Component({ selector: 'my-component' })
@Template({
url: 'some/url',
directives: [DirA, DirB]
})
@Template({
locale: 'en',
device: 'mobile',
url: 'some/url_en',
directives: [DirA, DirC]
})
class MyComponent {
}
NOTE: different Templates can have different directive imports.
This works with existing Reflector Since the above can be rewritten as:
class MyComponent{}
Reflector.addAnnotation(MyComponent, new Component({ selector: 'my-component' }));
Reflector.addAnnotation(MyComponent, new Template({url: 'some/url', directives: [DirA, DirB]});
Reflector.addAnnotation(MyComponent, new Template({locale: 'en', url: 'some/url_en', directives: [DirA, DirC]});
Because it can be rewritten into the Reflector form, it can be properly tree shaken, based on locale
Compiler
To support this the Compiler needs to be aware of current locale/device while compiling the templates. The compiler will need a new TemplateResolver dependency which will select the right @Template per each ComponentType. The TemplateResolver can than also be used in tests to override the templates.
export class TemplateResolver {
resolve(component: Type): Template {
// ...
}
}
Compilation Pipeline
- We start with component
Type
- We use
TemplateResolver to convert Type to Template
- We use the
TemplateLoader to covert the Template into HTML.
Prerequisite: #595
Goal
A given Component needs to be able to use different templates per locale, device type (and test). This requires that we decouple
@Componentdefinition fromTemplateConfig(and renameTemplateConfigto@Template)Example
Simple Component (with separate
Templateannotation)As more local devices get added to the system we can add
@Template()NOTE: different Templates can have different directive imports.
This works with existing
ReflectorSince the above can be rewritten as:Because it can be rewritten into the Reflector form, it can be properly tree shaken, based on locale
Compiler
To support this the Compiler needs to be aware of current
locale/devicewhile compiling the templates. The compiler will need a newTemplateResolverdependency which will select the right@Templateper eachComponentType. TheTemplateResolvercan than also be used in tests to override the templates.Compilation Pipeline
TypeTemplateResolverto convertTypetoTemplateTemplateLoaderto covert theTemplateinto HTML.