refactor(ivy): handle animation metadata normalization in the compiler (#26481)

PR Close #26481
This commit is contained in:
Matias Niemelä 2018-10-16 11:09:04 -07:00 committed by Misko Hevery
parent 0f7d2ca7a8
commit 9e5d440a0b
4 changed files with 18 additions and 18 deletions

View File

@ -133,7 +133,9 @@ describe('compiler compliance: styling', () => {
vars: 0, vars: 0,
template: function MyComponent_Template(rf, $ctx$) { template: function MyComponent_Template(rf, $ctx$) {
}, },
data: {
animations: [{name: 'foo123'}, {name: 'trigger123'}] animations: [{name: 'foo123'}, {name: 'trigger123'}]
}
}); });
`; `;
@ -173,7 +175,9 @@ describe('compiler compliance: styling', () => {
vars: 0, vars: 0,
template: function MyComponent_Template(rf, $ctx$) { template: function MyComponent_Template(rf, $ctx$) {
}, },
data: {
animations: [] animations: []
}
}); });
`; `;

View File

@ -245,7 +245,8 @@ export function compileComponentFromMetadata(
// e.g. `animations: [trigger('123', [])]` // e.g. `animations: [trigger('123', [])]`
if (meta.animations !== null) { if (meta.animations !== null) {
definitionMap.set('animations', meta.animations); definitionMap.set(
'data', o.literalMap([{key: 'animations', value: meta.animations, quoted: false}]));
} }
// On the type side, remove newlines from the selector as it will need to fit into a TypeScript // On the type side, remove newlines from the selector as it will need to fit into a TypeScript

View File

@ -263,11 +263,6 @@ export function defineComponent<T>(componentDefinition: {
* `PipeDefs`s. The function is necessary to be able to support forward declarations. * `PipeDefs`s. The function is necessary to be able to support forward declarations.
*/ */
pipes?: PipeTypesOrFactory | null; pipes?: PipeTypesOrFactory | null;
/**
* Registry of the animation triggers present on the component that will be used by the view.
*/
animations?: any[] | null;
}): never { }): never {
const type = componentDefinition.type; const type = componentDefinition.type;
const pipeTypes = componentDefinition.pipes !; const pipeTypes = componentDefinition.pipes !;
@ -275,11 +270,7 @@ export function defineComponent<T>(componentDefinition: {
const declaredInputs: {[key: string]: string} = {} as any; const declaredInputs: {[key: string]: string} = {} as any;
const encapsulation = componentDefinition.encapsulation || ViewEncapsulation.Emulated; const encapsulation = componentDefinition.encapsulation || ViewEncapsulation.Emulated;
const styles: string[] = componentDefinition.styles || EMPTY_ARRAY; const styles: string[] = componentDefinition.styles || EMPTY_ARRAY;
const animations: any[]|null = componentDefinition.animations || null; const data = componentDefinition.data || {};
let data = componentDefinition.data || {};
if (animations) {
data.animations = animations;
}
const def: ComponentDef<any> = { const def: ComponentDef<any> = {
type: type, type: type,
diPublic: null, diPublic: null,

View File

@ -1605,10 +1605,12 @@ describe('render3 integration test', () => {
type: AnimComp, type: AnimComp,
consts: 0, consts: 0,
vars: 0, vars: 0,
data: {
animations: [ animations: [
animA, animA,
animB, animB,
], ],
},
selectors: [['foo']], selectors: [['foo']],
factory: () => new AnimComp(), factory: () => new AnimComp(),
template: (rf: RenderFlags, ctx: AnimComp) => {} template: (rf: RenderFlags, ctx: AnimComp) => {}
@ -1630,7 +1632,9 @@ describe('render3 integration test', () => {
type: AnimComp, type: AnimComp,
consts: 0, consts: 0,
vars: 0, vars: 0,
data: {
animations: [], animations: [],
},
selectors: [['foo']], selectors: [['foo']],
factory: () => new AnimComp(), factory: () => new AnimComp(),
template: (rf: RenderFlags, ctx: AnimComp) => {} template: (rf: RenderFlags, ctx: AnimComp) => {}