feat(TemplateConfig): support array of arrays in TemplateConfig directives
Fixes #592 Closes #600
This commit is contained in:
parent
8844671c8d
commit
6d8ccaa8e4
|
@ -30,6 +30,21 @@ export class DirectiveMetadataReader {
|
||||||
|
|
||||||
componentDirectivesMetadata(annotation:Component):List<Type> {
|
componentDirectivesMetadata(annotation:Component):List<Type> {
|
||||||
var template = annotation.template;
|
var template = annotation.template;
|
||||||
return isPresent(template) && isPresent(template.directives) ? template.directives : [];
|
var result:List<Type> = ListWrapper.create();
|
||||||
|
if (isPresent(template) && isPresent(template.directives)) {
|
||||||
|
this._buildList(result, template.directives);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildList(out:List<Type>, tree:List<any>) {
|
||||||
|
for (var i = 0; i < tree.length; i++) {
|
||||||
|
var item = tree[i];
|
||||||
|
if (ListWrapper.isList(item)) {
|
||||||
|
this._buildList(out, item);
|
||||||
|
} else {
|
||||||
|
ListWrapper.push(out, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {TemplateConfig} from 'angular2/src/core/annotations/template_config';
|
||||||
import {DirectiveMetadata} from 'angular2/src/core/compiler/directive_metadata';
|
import {DirectiveMetadata} from 'angular2/src/core/compiler/directive_metadata';
|
||||||
import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
||||||
import {CONST} from 'angular2/src/facade/lang';
|
import {CONST} from 'angular2/src/facade/lang';
|
||||||
|
import {If, Foreach} from 'angular2/directives';
|
||||||
|
|
||||||
|
|
||||||
@Decorator({
|
@Decorator({
|
||||||
|
@ -29,7 +30,13 @@ class ComponentWithoutDirectives {}
|
||||||
})
|
})
|
||||||
class ComponentWithDirectives {}
|
class ComponentWithDirectives {}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'withDirectivesTree',
|
||||||
|
template: new TemplateConfig({
|
||||||
|
directives: [[SomeDirective, [Foreach, If]], ComponentWithoutDirectives]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
class ComponentWithDirectivesTree {}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe("DirectiveMetadataReader", () => {
|
describe("DirectiveMetadataReader", () => {
|
||||||
|
@ -61,6 +68,11 @@ export function main() {
|
||||||
var cmp = reader.read(ComponentWithDirectives);
|
var cmp = reader.read(ComponentWithDirectives);
|
||||||
expect(cmp.componentDirectives).toEqual([ComponentWithoutDirectives]);
|
expect(cmp.componentDirectives).toEqual([ComponentWithoutDirectives]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return a list of directives specified in the template config as a tree", () => {
|
||||||
|
var cmp = reader.read(ComponentWithDirectivesTree);
|
||||||
|
expect(cmp.componentDirectives).toEqual([SomeDirective, Foreach, If, ComponentWithoutDirectives]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ class PushBasedComp {
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: new TemplateConfig({
|
template: new TemplateConfig({
|
||||||
directives: [MyDir, ChildComp, SomeTemplate, PushBasedComp]
|
directives: [MyDir, [[ChildComp], SomeTemplate, PushBasedComp]]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
class MyComp {
|
class MyComp {
|
||||||
|
@ -305,4 +305,3 @@ class MyService {
|
||||||
this.greeting = 'hello';
|
this.greeting = 'hello';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue