refactor: rename annotations to metadata
BREAKING CHANGE (maybe) Well as long as our customers use public API this should not be a breaking change, but we have changed import structure as well as internal names, so it could be breaking. import: angular2/annotations => angular2/metadata Classes: *Annotations => *Metadata renderer.DirectiveMetadata => renderer.RendererDirectiveMetadata renderer.ElementBinder => renderer.RendererElementBinder impl.Directive => impl.DirectiveMetadata impl.Component => impl.ComponentMetadata impl.View => impl.ViewMetadata Closes #3660
This commit is contained in:

committed by
Miško Hevery

parent
5e6317fecc
commit
ea6673947c
@ -22,8 +22,7 @@ import {AppProtoView} from 'angular2/src/core/compiler/view';
|
||||
import {ElementBinder} from 'angular2/src/core/compiler/element_binder';
|
||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||
import {PipeResolver} from 'angular2/src/core/compiler/pipe_resolver';
|
||||
import {Attribute, View, Component, Directive, Pipe} from 'angular2/annotations';
|
||||
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
|
||||
import {Attribute, ViewMetadata, Component, Directive, Pipe} from 'angular2/metadata';
|
||||
import {internalProtoView} from 'angular2/src/core/compiler/view_ref';
|
||||
import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
import {ViewResolver} from 'angular2/src/core/compiler/view_resolver';
|
||||
@ -35,7 +34,16 @@ import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
|
||||
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
import {AppRootUrl} from 'angular2/src/services/app_root_url';
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
import {
|
||||
ProtoViewDto,
|
||||
ViewType,
|
||||
RenderProtoViewRef,
|
||||
ViewDefinition,
|
||||
RenderProtoViewMergeMapping,
|
||||
RenderDirectiveMetadata,
|
||||
DirectiveBinder,
|
||||
RenderElementBinder
|
||||
} from 'angular2/src/render/api';
|
||||
// TODO(tbosch): Spys don't support named modules...
|
||||
import {RenderCompiler} from 'angular2/src/render/api';
|
||||
import {PipeBinding} from 'angular2/src/core/pipes/pipe_binding';
|
||||
@ -48,8 +56,7 @@ export function main() {
|
||||
cmpUrlMapper, rootProtoView;
|
||||
var renderCompileRequests: any[];
|
||||
|
||||
function createCompiler(renderCompileResults:
|
||||
List<renderApi.ProtoViewDto | Promise<renderApi.ProtoViewDto>>,
|
||||
function createCompiler(renderCompileResults: List<ProtoViewDto | Promise<ProtoViewDto>>,
|
||||
protoViewFactoryResults: List<AppProtoView>) {
|
||||
var urlResolver = new UrlResolver();
|
||||
renderCompileRequests = [];
|
||||
@ -73,12 +80,12 @@ export function main() {
|
||||
renderCompiler = new SpyRenderCompiler();
|
||||
renderCompiler.spy('compileHost')
|
||||
.andCallFake((componentId) => {
|
||||
return PromiseWrapper.resolve(createRenderProtoView(
|
||||
[createRenderComponentElementBinder(0)], renderApi.ViewType.HOST));
|
||||
return PromiseWrapper.resolve(
|
||||
createRenderProtoView([createRenderComponentElementBinder(0)], ViewType.HOST));
|
||||
});
|
||||
renderCompiler.spy('mergeProtoViewsRecursively')
|
||||
.andCallFake((protoViewRefs: List<renderApi.RenderProtoViewRef | List<any>>) => {
|
||||
return PromiseWrapper.resolve(new renderApi.RenderProtoViewMergeMapping(
|
||||
.andCallFake((protoViewRefs: List<RenderProtoViewRef | List<any>>) => {
|
||||
return PromiseWrapper.resolve(new RenderProtoViewMergeMapping(
|
||||
new MergedRenderProtoViewRef(protoViewRefs), 1, [], 0, [], [], [null]));
|
||||
});
|
||||
// TODO spy on .compile and return RenderProtoViewRef, same for compileHost
|
||||
@ -87,7 +94,7 @@ export function main() {
|
||||
|
||||
describe('serialize template', () => {
|
||||
|
||||
function captureTemplate(template: viewAnn.View): Promise<renderApi.ViewDefinition> {
|
||||
function captureTemplate(template: ViewMetadata): Promise<ViewDefinition> {
|
||||
tplResolver.setView(MainComponent, template);
|
||||
var compiler =
|
||||
createCompiler([createRenderProtoView()], [rootProtoView, createProtoView()]);
|
||||
@ -98,8 +105,8 @@ export function main() {
|
||||
});
|
||||
}
|
||||
|
||||
function captureDirective(directive): Promise<renderApi.DirectiveMetadata> {
|
||||
return captureTemplate(new viewAnn.View({template: '<div></div>', directives: [directive]}))
|
||||
function captureDirective(directive): Promise<RenderDirectiveMetadata> {
|
||||
return captureTemplate(new ViewMetadata({template: '<div></div>', directives: [directive]}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.directives.length).toBe(1);
|
||||
return renderTpl.directives[0];
|
||||
@ -107,7 +114,7 @@ export function main() {
|
||||
}
|
||||
|
||||
it('should fill the componentId', inject([AsyncTestCompleter], (async) => {
|
||||
captureTemplate(new viewAnn.View({template: '<div></div>'}))
|
||||
captureTemplate(new ViewMetadata({template: '<div></div>'}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.componentId).toEqual(stringify(MainComponent));
|
||||
async.done();
|
||||
@ -115,7 +122,7 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should fill inline template', inject([AsyncTestCompleter], (async) => {
|
||||
captureTemplate(new viewAnn.View({template: '<div></div>'}))
|
||||
captureTemplate(new ViewMetadata({template: '<div></div>'}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.template).toEqual('<div></div>');
|
||||
async.done();
|
||||
@ -125,7 +132,7 @@ export function main() {
|
||||
it('should fill templateAbsUrl given inline templates',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
|
||||
captureTemplate(new viewAnn.View({template: '<div></div>'}))
|
||||
captureTemplate(new ViewMetadata({template: '<div></div>'}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.templateAbsUrl).toEqual('http://www.app.com/cmp/main.js');
|
||||
async.done();
|
||||
@ -135,7 +142,7 @@ export function main() {
|
||||
it('should not fill templateAbsUrl given no inline template or template url',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
|
||||
captureTemplate(new viewAnn.View({template: null, templateUrl: null}))
|
||||
captureTemplate(new ViewMetadata({template: null, templateUrl: null}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.templateAbsUrl).toBe(null);
|
||||
async.done();
|
||||
@ -144,7 +151,7 @@ export function main() {
|
||||
|
||||
it('should fill templateAbsUrl given url template', inject([AsyncTestCompleter], (async) => {
|
||||
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
|
||||
captureTemplate(new viewAnn.View({templateUrl: 'tpl/main.html'}))
|
||||
captureTemplate(new ViewMetadata({templateUrl: 'tpl/main.html'}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.templateAbsUrl).toEqual('http://www.app.com/cmp/tpl/main.html');
|
||||
async.done();
|
||||
@ -153,7 +160,7 @@ export function main() {
|
||||
|
||||
it('should fill styleAbsUrls given styleUrls', inject([AsyncTestCompleter], (async) => {
|
||||
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
|
||||
captureTemplate(new viewAnn.View({styleUrls: ['css/1.css', 'css/2.css']}))
|
||||
captureTemplate(new ViewMetadata({styleUrls: ['css/1.css', 'css/2.css']}))
|
||||
.then((renderTpl) => {
|
||||
expect(renderTpl.styleAbsUrls)
|
||||
.toEqual(
|
||||
@ -181,7 +188,7 @@ export function main() {
|
||||
it('should fill directive.type for components', inject([AsyncTestCompleter], (async) => {
|
||||
captureDirective(MainComponent)
|
||||
.then((renderDir) => {
|
||||
expect(renderDir.type).toEqual(renderApi.DirectiveMetadata.COMPONENT_TYPE);
|
||||
expect(renderDir.type).toEqual(RenderDirectiveMetadata.COMPONENT_TYPE);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@ -190,7 +197,7 @@ export function main() {
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
captureDirective(SomeDynamicComponentDirective)
|
||||
.then((renderDir) => {
|
||||
expect(renderDir.type).toEqual(renderApi.DirectiveMetadata.COMPONENT_TYPE);
|
||||
expect(renderDir.type).toEqual(RenderDirectiveMetadata.COMPONENT_TYPE);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@ -199,7 +206,7 @@ export function main() {
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
captureDirective(SomeDirective)
|
||||
.then((renderDir) => {
|
||||
expect(renderDir.type).toEqual(renderApi.DirectiveMetadata.DIRECTIVE_TYPE);
|
||||
expect(renderDir.type).toEqual(RenderDirectiveMetadata.DIRECTIVE_TYPE);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@ -269,7 +276,7 @@ export function main() {
|
||||
describe('call ProtoViewFactory', () => {
|
||||
|
||||
it('should pass the ProtoViewDto', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var renderProtoView = createRenderProtoView();
|
||||
var expectedProtoView = createProtoView();
|
||||
var compiler = createCompiler([renderProtoView], [rootProtoView, expectedProtoView]);
|
||||
@ -282,7 +289,7 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should pass the component binding', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var compiler =
|
||||
createCompiler([createRenderProtoView()], [rootProtoView, createProtoView()]);
|
||||
compiler.compileInHost(MainComponent)
|
||||
@ -296,7 +303,7 @@ export function main() {
|
||||
it('should pass the directive bindings', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(
|
||||
MainComponent,
|
||||
new viewAnn.View({template: '<div></div>', directives: [SomeDirective]}));
|
||||
new ViewMetadata({template: '<div></div>', directives: [SomeDirective]}));
|
||||
var compiler =
|
||||
createCompiler([createRenderProtoView()], [rootProtoView, createProtoView()]);
|
||||
compiler.compileInHost(MainComponent)
|
||||
@ -310,7 +317,7 @@ export function main() {
|
||||
|
||||
it('should pass the pipe bindings', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent,
|
||||
new viewAnn.View({template: '<div></div>', pipes: [SomePipe]}));
|
||||
new ViewMetadata({template: '<div></div>', pipes: [SomePipe]}));
|
||||
var compiler =
|
||||
createCompiler([createRenderProtoView()], [rootProtoView, createProtoView()]);
|
||||
compiler.compileInHost(MainComponent)
|
||||
@ -324,7 +331,7 @@ export function main() {
|
||||
|
||||
it('should use the protoView of the ProtoViewFactory',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var compiler =
|
||||
createCompiler([createRenderProtoView()], [rootProtoView, createProtoView()]);
|
||||
compiler.compileInHost(MainComponent)
|
||||
@ -337,8 +344,8 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should load nested components', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(NestedComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
tplResolver.setView(NestedComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var mainProtoView =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, NestedComponent)]);
|
||||
var nestedProtoView = createProtoView();
|
||||
@ -361,17 +368,16 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should load nested components in viewcontainers', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(NestedComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
var viewportProtoView =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, NestedComponent)],
|
||||
renderApi.ViewType.EMBEDDED);
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
tplResolver.setView(NestedComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var viewportProtoView = createProtoView(
|
||||
[createComponentElementBinder(directiveResolver, NestedComponent)], ViewType.EMBEDDED);
|
||||
var mainProtoView = createProtoView([createViewportElementBinder(viewportProtoView)]);
|
||||
var nestedProtoView = createProtoView();
|
||||
var renderPvDtos = [
|
||||
createRenderProtoView([
|
||||
createRenderViewportElementBinder(createRenderProtoView(
|
||||
[createRenderComponentElementBinder(0)], renderApi.ViewType.EMBEDDED))
|
||||
createRenderViewportElementBinder(
|
||||
createRenderProtoView([createRenderComponentElementBinder(0)], ViewType.EMBEDDED))
|
||||
]),
|
||||
createRenderProtoView()
|
||||
];
|
||||
@ -391,7 +397,7 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should cache compiled host components', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var mainPv = createProtoView();
|
||||
var compiler = createCompiler([createRenderProtoView([])], [rootProtoView, mainPv]);
|
||||
compiler.compileInHost(MainComponent)
|
||||
@ -429,9 +435,9 @@ export function main() {
|
||||
|
||||
|
||||
it('should cache compiled nested components', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent2, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(NestedComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent2, new ViewMetadata({template: '<div></div>'}));
|
||||
tplResolver.setView(NestedComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var rootProtoView2 = createRootProtoView(directiveResolver, MainComponent2);
|
||||
var mainPv =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, NestedComponent)]);
|
||||
@ -459,9 +465,8 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should re-use components being compiled', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
var renderProtoViewCompleter: PromiseCompleter<renderApi.ProtoViewDto> =
|
||||
PromiseWrapper.completer();
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var renderProtoViewCompleter: PromiseCompleter<ProtoViewDto> = PromiseWrapper.completer();
|
||||
var expectedProtoView = createProtoView();
|
||||
var compiler = createCompiler([renderProtoViewCompleter.promise],
|
||||
[rootProtoView, rootProtoView, expectedProtoView]);
|
||||
@ -482,7 +487,7 @@ export function main() {
|
||||
|
||||
it('should throw on unconditional recursive components',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var mainProtoView =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, MainComponent)]);
|
||||
var compiler =
|
||||
@ -498,15 +503,14 @@ export function main() {
|
||||
|
||||
it('should allow recursive components that are connected via an embedded ProtoView',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
var viewportProtoView =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, MainComponent)],
|
||||
renderApi.ViewType.EMBEDDED);
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var viewportProtoView = createProtoView(
|
||||
[createComponentElementBinder(directiveResolver, MainComponent)], ViewType.EMBEDDED);
|
||||
var mainProtoView = createProtoView([createViewportElementBinder(viewportProtoView)]);
|
||||
var renderPvDtos = [
|
||||
createRenderProtoView([
|
||||
createRenderViewportElementBinder(createRenderProtoView(
|
||||
[createRenderComponentElementBinder(0)], renderApi.ViewType.EMBEDDED))
|
||||
createRenderViewportElementBinder(
|
||||
createRenderProtoView([createRenderComponentElementBinder(0)], ViewType.EMBEDDED))
|
||||
]),
|
||||
createRenderProtoView()
|
||||
];
|
||||
@ -530,15 +534,15 @@ export function main() {
|
||||
|
||||
it('should throw on recursive components that are connected via an embedded ProtoView with <ng-content>',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var viewportProtoView =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, MainComponent)],
|
||||
renderApi.ViewType.EMBEDDED, true);
|
||||
ViewType.EMBEDDED, true);
|
||||
var mainProtoView = createProtoView([createViewportElementBinder(viewportProtoView)]);
|
||||
var renderPvDtos = [
|
||||
createRenderProtoView([
|
||||
createRenderViewportElementBinder(createRenderProtoView(
|
||||
[createRenderComponentElementBinder(0)], renderApi.ViewType.EMBEDDED))
|
||||
createRenderViewportElementBinder(
|
||||
createRenderProtoView([createRenderComponentElementBinder(0)], ViewType.EMBEDDED))
|
||||
]),
|
||||
createRenderProtoView()
|
||||
];
|
||||
@ -554,10 +558,9 @@ export function main() {
|
||||
|
||||
|
||||
it('should create host proto views', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
|
||||
var rootProtoView =
|
||||
createProtoView([createComponentElementBinder(directiveResolver, MainComponent)],
|
||||
renderApi.ViewType.HOST);
|
||||
tplResolver.setView(MainComponent, new ViewMetadata({template: '<div></div>'}));
|
||||
var rootProtoView = createProtoView(
|
||||
[createComponentElementBinder(directiveResolver, MainComponent)], ViewType.HOST);
|
||||
var mainProtoView = createProtoView();
|
||||
var compiler = createCompiler([createRenderProtoView()], [rootProtoView, mainProtoView]);
|
||||
compiler.compileInHost(MainComponent)
|
||||
@ -582,13 +585,13 @@ function createDirectiveBinding(directiveResolver, type): DirectiveBinding {
|
||||
return DirectiveBinding.createFromType(type, annotation);
|
||||
}
|
||||
|
||||
function createProtoView(elementBinders = null, type: renderApi.ViewType = null,
|
||||
function createProtoView(elementBinders = null, type: ViewType = null,
|
||||
isEmbeddedFragment: boolean = false): AppProtoView {
|
||||
if (isBlank(type)) {
|
||||
type = renderApi.ViewType.COMPONENT;
|
||||
type = ViewType.COMPONENT;
|
||||
}
|
||||
var pv = new AppProtoView(type, isEmbeddedFragment, new renderApi.RenderProtoViewRef(), null,
|
||||
null, new Map(), null, null);
|
||||
var pv = new AppProtoView(type, isEmbeddedFragment, new RenderProtoViewRef(), null, null,
|
||||
new Map(), null, null);
|
||||
if (isBlank(elementBinders)) {
|
||||
elementBinders = [];
|
||||
}
|
||||
@ -607,30 +610,28 @@ function createViewportElementBinder(nestedProtoView): ElementBinder {
|
||||
return elBinder;
|
||||
}
|
||||
|
||||
function createRenderProtoView(elementBinders = null, type: renderApi.ViewType = null):
|
||||
renderApi.ProtoViewDto {
|
||||
function createRenderProtoView(elementBinders = null, type: ViewType = null): ProtoViewDto {
|
||||
if (isBlank(type)) {
|
||||
type = renderApi.ViewType.COMPONENT;
|
||||
type = ViewType.COMPONENT;
|
||||
}
|
||||
if (isBlank(elementBinders)) {
|
||||
elementBinders = [];
|
||||
}
|
||||
return new renderApi.ProtoViewDto(
|
||||
{elementBinders: elementBinders, type: type, render: new renderApi.RenderProtoViewRef()});
|
||||
return new ProtoViewDto(
|
||||
{elementBinders: elementBinders, type: type, render: new RenderProtoViewRef()});
|
||||
}
|
||||
|
||||
function createRenderComponentElementBinder(directiveIndex): renderApi.ElementBinder {
|
||||
return new renderApi.ElementBinder(
|
||||
{directives: [new renderApi.DirectiveBinder({directiveIndex: directiveIndex})]});
|
||||
function createRenderComponentElementBinder(directiveIndex): RenderElementBinder {
|
||||
return new RenderElementBinder(
|
||||
{directives: [new DirectiveBinder({directiveIndex: directiveIndex})]});
|
||||
}
|
||||
|
||||
function createRenderViewportElementBinder(nestedProtoView): renderApi.ElementBinder {
|
||||
return new renderApi.ElementBinder({nestedProtoView: nestedProtoView});
|
||||
function createRenderViewportElementBinder(nestedProtoView): RenderElementBinder {
|
||||
return new RenderElementBinder({nestedProtoView: nestedProtoView});
|
||||
}
|
||||
|
||||
function createRootProtoView(directiveResolver, type): AppProtoView {
|
||||
return createProtoView([createComponentElementBinder(directiveResolver, type)],
|
||||
renderApi.ViewType.HOST);
|
||||
return createProtoView([createComponentElementBinder(directiveResolver, type)], ViewType.HOST);
|
||||
}
|
||||
|
||||
@Component({selector: 'main-comp'})
|
||||
@ -699,16 +700,16 @@ class SpyDirectiveResolver extends SpyObject {
|
||||
}
|
||||
|
||||
class FakeViewResolver extends ViewResolver {
|
||||
_cmpViews: Map<Type, viewAnn.View> = new Map();
|
||||
_cmpViews: Map<Type, ViewMetadata> = new Map();
|
||||
|
||||
constructor() { super(); }
|
||||
|
||||
resolve(component: Type): viewAnn.View {
|
||||
resolve(component: Type): ViewMetadata {
|
||||
// returns null for dynamic components
|
||||
return this._cmpViews.has(component) ? this._cmpViews.get(component) : null;
|
||||
}
|
||||
|
||||
setView(component: Type, view: viewAnn.View): void { this._cmpViews.set(component, view); }
|
||||
setView(component: Type, view: ViewMetadata): void { this._cmpViews.set(component, view); }
|
||||
}
|
||||
|
||||
class FakeProtoViewFactory extends ProtoViewFactory {
|
||||
@ -719,15 +720,15 @@ class FakeProtoViewFactory extends ProtoViewFactory {
|
||||
this.requests = [];
|
||||
}
|
||||
|
||||
createAppProtoViews(componentBinding: DirectiveBinding, renderProtoView: renderApi.ProtoViewDto,
|
||||
createAppProtoViews(componentBinding: DirectiveBinding, renderProtoView: ProtoViewDto,
|
||||
directives: List<DirectiveBinding>, pipes: PipeBinding[]): AppProtoView[] {
|
||||
this.requests.push([componentBinding, renderProtoView, directives, pipes]);
|
||||
return collectEmbeddedPvs(ListWrapper.removeAt(this.results, 0));
|
||||
}
|
||||
}
|
||||
|
||||
class MergedRenderProtoViewRef extends renderApi.RenderProtoViewRef {
|
||||
constructor(public originals: renderApi.RenderProtoViewRef[]) { super(); }
|
||||
class MergedRenderProtoViewRef extends RenderProtoViewRef {
|
||||
constructor(public originals: RenderProtoViewRef[]) { super(); }
|
||||
}
|
||||
|
||||
function originalRenderProtoViewRefs(appProtoView: AppProtoView) {
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
proxy
|
||||
} from 'angular2/test_lib';
|
||||
|
||||
import {Directive, LifecycleEvent} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {DirectiveMetadata, LifecycleEvent} from '../../../src/core/metadata';
|
||||
import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
|
||||
export function main() {
|
||||
@ -25,87 +25,99 @@ export function main() {
|
||||
|
||||
describe("onChange", () => {
|
||||
it("should be true when the directive has the onChange method", () => {
|
||||
expect(metadata(DirectiveWithOnChangeMethod, new Directive({})).callOnChange).toBe(true);
|
||||
expect(metadata(DirectiveWithOnChangeMethod, new DirectiveMetadata({})).callOnChange)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onChange", () => {
|
||||
expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onChange]}))
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new DirectiveMetadata({lifecycle: [LifecycleEvent.onChange]}))
|
||||
.callOnChange)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise",
|
||||
() => { expect(metadata(DirectiveNoHooks, new Directive()).callOnChange).toBe(false); });
|
||||
it("should be false otherwise", () => {
|
||||
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnChange).toBe(false);
|
||||
});
|
||||
|
||||
it("should be false when empty lifecycle", () => {
|
||||
expect(metadata(DirectiveWithOnChangeMethod, new Directive({lifecycle: []})).callOnChange)
|
||||
expect(metadata(DirectiveWithOnChangeMethod, new DirectiveMetadata({lifecycle: []}))
|
||||
.callOnChange)
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onDestroy", () => {
|
||||
it("should be true when the directive has the onDestroy method", () => {
|
||||
expect(metadata(DirectiveWithOnDestroyMethod, new Directive({})).callOnDestroy)
|
||||
expect(metadata(DirectiveWithOnDestroyMethod, new DirectiveMetadata({})).callOnDestroy)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onDestroy", () => {
|
||||
expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onDestroy]}))
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new DirectiveMetadata({lifecycle: [LifecycleEvent.onDestroy]}))
|
||||
.callOnDestroy)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () => {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnDestroy).toBe(false);
|
||||
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnDestroy).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onInit", () => {
|
||||
it("should be true when the directive has the onInit method", () => {
|
||||
expect(metadata(DirectiveWithOnInitMethod, new Directive({})).callOnInit).toBe(true);
|
||||
expect(metadata(DirectiveWithOnInitMethod, new DirectiveMetadata({})).callOnInit)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onDestroy", () => {
|
||||
expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onInit]}))
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new DirectiveMetadata({lifecycle: [LifecycleEvent.onInit]}))
|
||||
.callOnInit)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise",
|
||||
() => { expect(metadata(DirectiveNoHooks, new Directive()).callOnInit).toBe(false); });
|
||||
it("should be false otherwise", () => {
|
||||
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnInit).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onCheck", () => {
|
||||
it("should be true when the directive has the onCheck method", () => {
|
||||
expect(metadata(DirectiveWithOnCheckMethod, new Directive({})).callOnCheck).toBe(true);
|
||||
expect(metadata(DirectiveWithOnCheckMethod, new DirectiveMetadata({})).callOnCheck)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onCheck", () => {
|
||||
expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onCheck]}))
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new DirectiveMetadata({lifecycle: [LifecycleEvent.onCheck]}))
|
||||
.callOnCheck)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise",
|
||||
() => { expect(metadata(DirectiveNoHooks, new Directive()).callOnCheck).toBe(false); });
|
||||
it("should be false otherwise", () => {
|
||||
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnCheck).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onAllChangesDone", () => {
|
||||
it("should be true when the directive has the onAllChangesDone method", () => {
|
||||
expect(
|
||||
metadata(DirectiveWithOnAllChangesDoneMethod, new Directive({})).callOnAllChangesDone)
|
||||
expect(metadata(DirectiveWithOnAllChangesDoneMethod, new DirectiveMetadata({}))
|
||||
.callOnAllChangesDone)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be true when the lifecycle includes onAllChangesDone", () => {
|
||||
expect(metadata(DirectiveNoHooks,
|
||||
new Directive({lifecycle: [LifecycleEvent.onAllChangesDone]}))
|
||||
new DirectiveMetadata({lifecycle: [LifecycleEvent.onAllChangesDone]}))
|
||||
.callOnAllChangesDone)
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("should be false otherwise", () => {
|
||||
expect(metadata(DirectiveNoHooks, new Directive()).callOnAllChangesDone).toBe(false);
|
||||
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnAllChangesDone)
|
||||
.toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/test_lib';
|
||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||
import {Directive} from 'angular2/annotations';
|
||||
import * as dirAnn from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {DirectiveMetadata, Directive} from 'angular2/metadata';
|
||||
|
||||
@Directive({selector: 'someDirective'})
|
||||
class SomeDirective {
|
||||
@ -21,7 +20,7 @@ export function main() {
|
||||
|
||||
it('should read out the Directive annotation', () => {
|
||||
var directiveMetadata = reader.resolve(SomeDirective);
|
||||
expect(directiveMetadata).toEqual(new dirAnn.Directive({selector: 'someDirective'}));
|
||||
expect(directiveMetadata).toEqual(new Directive({selector: 'someDirective'}));
|
||||
});
|
||||
|
||||
it('should throw if not matching annotation is found', () => {
|
||||
@ -31,7 +30,7 @@ export function main() {
|
||||
|
||||
it('should not read parent class Directive annotations', function() {
|
||||
var directiveMetadata = reader.resolve(SomeChildDirective);
|
||||
expect(directiveMetadata).toEqual(new dirAnn.Directive({selector: 'someChildDirective'}));
|
||||
expect(directiveMetadata).toEqual(new Directive({selector: 'someChildDirective'}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ import {
|
||||
|
||||
import {Injector} from 'angular2/di';
|
||||
import {NgIf} from 'angular2/directives';
|
||||
import {Component, View, LifecycleEvent} from 'angular2/annotations';
|
||||
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
|
||||
import {Component, View, ViewMetadata, LifecycleEvent} from 'angular2/metadata';
|
||||
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
|
||||
import {DOCUMENT} from 'angular2/src/render/render';
|
||||
@ -35,7 +34,7 @@ export function main() {
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp,
|
||||
new viewAnn.View(
|
||||
new ViewMetadata(
|
||||
{template: '<location #loc></location>', directives: [Location]}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
@ -53,7 +52,7 @@ export function main() {
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp,
|
||||
new viewAnn.View(
|
||||
new ViewMetadata(
|
||||
{template: '<location #loc></location>', directives: [Location]}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
@ -70,13 +69,13 @@ export function main() {
|
||||
it('should allow to dispose even if the location has been removed',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new viewAnn.View({
|
||||
template: '<child-cmp *ng-if="ctxBoolProp"></child-cmp>',
|
||||
directives: [NgIf, ChildComp]
|
||||
}))
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<child-cmp *ng-if="ctxBoolProp"></child-cmp>',
|
||||
directives: [NgIf, ChildComp]
|
||||
}))
|
||||
.overrideView(
|
||||
ChildComp,
|
||||
new viewAnn.View(
|
||||
new ViewMetadata(
|
||||
{template: '<location #loc></location>', directives: [Location]}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
@ -103,7 +102,7 @@ export function main() {
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp, new viewAnn.View(
|
||||
MyComp, new ViewMetadata(
|
||||
{template: '<location #loc></location>', directives: [Location]}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
@ -125,7 +124,7 @@ export function main() {
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp,
|
||||
new viewAnn.View(
|
||||
new ViewMetadata(
|
||||
{template: '<location #loc></location>', directives: [Location]}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
@ -140,10 +139,11 @@ export function main() {
|
||||
describe("loading next to a location", () => {
|
||||
it('should work', inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new viewAnn.View({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
}))
|
||||
tcb.overrideView(
|
||||
MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef)
|
||||
@ -160,10 +160,10 @@ export function main() {
|
||||
it('should return a disposable component ref',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new viewAnn.View({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
}))
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
}))
|
||||
.
|
||||
|
||||
createAsync(MyComp)
|
||||
@ -193,10 +193,10 @@ export function main() {
|
||||
it('should update host properties',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new viewAnn.View({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
}))
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
}))
|
||||
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
|
@ -32,14 +32,13 @@ import {
|
||||
DirectiveBinding,
|
||||
TreeNode
|
||||
} from 'angular2/src/core/compiler/element_injector';
|
||||
import * as dirAnn from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {
|
||||
Attribute,
|
||||
Query,
|
||||
Component,
|
||||
Directive,
|
||||
ComponentMetadata,
|
||||
DirectiveMetadata,
|
||||
LifecycleEvent
|
||||
} from 'angular2/annotations';
|
||||
} from 'angular2/metadata';
|
||||
import {bind, Injector, Binding, Optional, Inject, Injectable, Self, SkipSelf, InjectMetadata, Host, HostMetadata, SkipSelfMetadata} from 'angular2/di';
|
||||
import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
@ -420,7 +419,7 @@ export function main() {
|
||||
describe('event emitters', () => {
|
||||
it('should return a list of event accessors', () => {
|
||||
var binding = DirectiveBinding.createFromType(HasEventEmitter,
|
||||
new dirAnn.Directive({events: ['emitter']}));
|
||||
new DirectiveMetadata({events: ['emitter']}));
|
||||
|
||||
var inj = createPei(null, 0, [binding]);
|
||||
expect(inj.eventEmitterAccessors.length).toEqual(1);
|
||||
@ -432,7 +431,7 @@ export function main() {
|
||||
|
||||
it('should allow a different event vs field name', () => {
|
||||
var binding = DirectiveBinding.createFromType(HasEventEmitter,
|
||||
new dirAnn.Directive({events: ['emitter: publicEmitter']}));
|
||||
new DirectiveMetadata({events: ['emitter: publicEmitter']}));
|
||||
|
||||
var inj = createPei(null, 0, [binding]);
|
||||
expect(inj.eventEmitterAccessors.length).toEqual(1);
|
||||
@ -444,7 +443,7 @@ export function main() {
|
||||
|
||||
it('should return a list of hostAction accessors', () => {
|
||||
var binding = DirectiveBinding.createFromType(
|
||||
HasEventEmitter, new dirAnn.Directive({host: {'@hostActionName': 'onAction'}}));
|
||||
HasEventEmitter, new DirectiveMetadata({host: {'@hostActionName': 'onAction'}}));
|
||||
|
||||
var inj = createPei(null, 0, [binding]);
|
||||
expect(inj.hostActionAccessors.length).toEqual(1);
|
||||
@ -460,8 +459,8 @@ export function main() {
|
||||
var pei = createPei(null, 0, [
|
||||
DirectiveBinding.createFromType(
|
||||
SimpleDirective,
|
||||
new dirAnn.Component({bindings: [bind('injectable1').toValue('injectable1')]})),
|
||||
DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Component({
|
||||
new ComponentMetadata({bindings: [bind('injectable1').toValue('injectable1')]})),
|
||||
DirectiveBinding.createFromType(SomeOtherDirective, new ComponentMetadata({
|
||||
bindings: [bind('injectable2').toValue('injectable2')]
|
||||
}))
|
||||
]);
|
||||
@ -474,7 +473,7 @@ export function main() {
|
||||
|
||||
it("should collect view bindings from the component", () => {
|
||||
var pei = createPei(null, 0,
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
viewBindings: [bind('injectable1').toValue('injectable1')]
|
||||
}))],
|
||||
0, true);
|
||||
@ -487,7 +486,7 @@ export function main() {
|
||||
var pei = createPei(null, 0, [
|
||||
DirectiveBinding.createFromType(
|
||||
SimpleDirective,
|
||||
new dirAnn.Component({
|
||||
new ComponentMetadata({
|
||||
viewBindings: [[[bind('view').toValue('view')]]],
|
||||
bindings: [[[bind('host').toValue('host')]]]
|
||||
}))
|
||||
@ -595,11 +594,11 @@ export function main() {
|
||||
function() {
|
||||
var childInj = parentChildInjectors(
|
||||
ListWrapper.concat(
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
bindings: [bind('injectable1').toValue('injectable1')]
|
||||
}))],
|
||||
extraBindings),
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
bindings: [
|
||||
bind('injectable1')
|
||||
.toValue('new-injectable1'),
|
||||
@ -624,7 +623,7 @@ export function main() {
|
||||
|
||||
var inj = injector(ListWrapper.concat(
|
||||
[DirectiveBinding.createFromType(SimpleDirective,
|
||||
new dirAnn.Directive({bindings: bindings}))],
|
||||
new DirectiveMetadata({bindings: bindings}))],
|
||||
extraBindings));
|
||||
|
||||
expect(inj.get('injectable2')).toEqual('injectable1-injectable2');
|
||||
@ -642,7 +641,7 @@ export function main() {
|
||||
|
||||
|
||||
var inj = injector(ListWrapper.concat(
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
[DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
viewBindings: viewBindings}))], extraBindings),
|
||||
null, true);
|
||||
expect(inj.get('injectable2')).toEqual('injectable1-injectable2');
|
||||
@ -650,7 +649,7 @@ export function main() {
|
||||
|
||||
it("should instantiate components that depend on viewBindings bindings", () => {
|
||||
var inj = injector(
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new dirAnn.Component({
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new ComponentMetadata({
|
||||
viewBindings: [bind('service').toValue('service')]
|
||||
}))],
|
||||
extraBindings),
|
||||
@ -661,7 +660,7 @@ export function main() {
|
||||
it("should instantiate bindings lazily", () => {
|
||||
var created = false;
|
||||
var inj = injector(
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
bindings: [bind('service').toFactory(() => created = true)]
|
||||
}))],
|
||||
extraBindings),
|
||||
@ -677,7 +676,7 @@ export function main() {
|
||||
it("should instantiate view bindings lazily", () => {
|
||||
var created = false;
|
||||
var inj = injector(
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
viewBindings: [bind('service').toFactory(() => created = true)]
|
||||
}))],
|
||||
extraBindings),
|
||||
@ -692,7 +691,7 @@ export function main() {
|
||||
|
||||
it("should not instantiate other directives that depend on viewBindings bindings",
|
||||
() => {
|
||||
var directiveAnnotation = new dirAnn.Component({
|
||||
var directiveAnnotation = new ComponentMetadata({
|
||||
viewBindings: ListWrapper.concat([bind("service").toValue("service")], extraBindings)
|
||||
});
|
||||
var componentDirective =
|
||||
@ -704,7 +703,7 @@ export function main() {
|
||||
|
||||
it("should instantiate directives that depend on bindings bindings of other directives", () => {
|
||||
var shadowInj = hostShadowInjectors(
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata({
|
||||
bindings: [bind('service').toValue('hostService')]})
|
||||
)], extraBindings),
|
||||
ListWrapper.concat([NeedsService], extraBindings)
|
||||
@ -742,7 +741,7 @@ export function main() {
|
||||
|
||||
it("should prioritize viewBindings over bindings for the same binding", () => {
|
||||
var inj = injector(
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new dirAnn.Component({
|
||||
ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new ComponentMetadata({
|
||||
bindings: [bind('service').toValue('hostService')],
|
||||
viewBindings: [bind('service').toValue('viewService')]})
|
||||
)], extraBindings), null, true);
|
||||
@ -755,7 +754,7 @@ export function main() {
|
||||
hostShadowInjectors(
|
||||
ListWrapper.concat([
|
||||
SimpleDirective,
|
||||
DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Directive({
|
||||
DirectiveBinding.createFromType(SomeOtherDirective, new DirectiveMetadata({
|
||||
bindings: [bind('service').toValue('hostService')]})
|
||||
)], extraBindings),
|
||||
|
||||
@ -827,7 +826,7 @@ export function main() {
|
||||
|
||||
it("should instantiate directives that depend on the containing component", () => {
|
||||
var directiveBinding =
|
||||
DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component());
|
||||
DirectiveBinding.createFromType(SimpleDirective, new ComponentMetadata());
|
||||
var shadow = hostShadowInjectors(ListWrapper.concat([directiveBinding], extraBindings),
|
||||
[NeeedsDirectiveFromHost]);
|
||||
|
||||
@ -839,7 +838,7 @@ export function main() {
|
||||
it("should not instantiate directives that depend on other directives in the containing component's ElementInjector",
|
||||
() => {
|
||||
var directiveBinding =
|
||||
DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Component());
|
||||
DirectiveBinding.createFromType(SomeOtherDirective, new ComponentMetadata());
|
||||
expect(() =>
|
||||
{
|
||||
hostShadowInjectors(
|
||||
@ -855,7 +854,7 @@ export function main() {
|
||||
it("should call onDestroy on directives subscribed to this event", () => {
|
||||
var inj = injector(ListWrapper.concat(
|
||||
[DirectiveBinding.createFromType(DirectiveWithDestroy,
|
||||
new dirAnn.Directive({lifecycle: [LifecycleEvent.onDestroy]}))],
|
||||
new DirectiveMetadata({lifecycle: [LifecycleEvent.onDestroy]}))],
|
||||
extraBindings));
|
||||
var destroy = inj.get(DirectiveWithDestroy);
|
||||
inj.dehydrate();
|
||||
@ -865,7 +864,7 @@ export function main() {
|
||||
it("should work with services", () => {
|
||||
var inj = injector(ListWrapper.concat(
|
||||
[DirectiveBinding.createFromType(
|
||||
SimpleDirective, new dirAnn.Directive({bindings: [SimpleService]}))],
|
||||
SimpleDirective, new DirectiveMetadata({bindings: [SimpleService]}))],
|
||||
extraBindings));
|
||||
inj.dehydrate();
|
||||
});
|
||||
@ -942,7 +941,7 @@ export function main() {
|
||||
var childView = new DummyView();
|
||||
childView.changeDetector = cd;
|
||||
view.spy('getNestedView').andReturn(childView);
|
||||
var binding = DirectiveBinding.createFromType(ComponentNeedsChangeDetectorRef, new dirAnn.Component());
|
||||
var binding = DirectiveBinding.createFromType(ComponentNeedsChangeDetectorRef, new ComponentMetadata());
|
||||
var inj = injector(ListWrapper.concat([binding], extraBindings), null, true,
|
||||
new PreBuiltObjects(null, view, <any>new DummyElementRef(), null));
|
||||
|
||||
@ -953,7 +952,7 @@ export function main() {
|
||||
var cd = new DynamicChangeDetector(null, null, null, [], [], []);
|
||||
var view = <any>new DummyView();
|
||||
view.changeDetector =cd;
|
||||
var binding = DirectiveBinding.createFromType(DirectiveNeedsChangeDetectorRef, new dirAnn.Directive());
|
||||
var binding = DirectiveBinding.createFromType(DirectiveNeedsChangeDetectorRef, new DirectiveMetadata());
|
||||
var inj = injector(ListWrapper.concat([binding], extraBindings), null, false,
|
||||
new PreBuiltObjects(null, view, <any>new DummyElementRef(), null));
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,8 +23,6 @@ import {
|
||||
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
|
||||
|
||||
import {
|
||||
Component,
|
||||
Directive,
|
||||
@ -43,12 +41,12 @@ export function main() {
|
||||
describe('projection', () => {
|
||||
it('should support simple components',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<simple>' +
|
||||
'<div>A</div>' +
|
||||
'</simple>',
|
||||
directives: [Simple]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<simple>' +
|
||||
'<div>A</div>' +
|
||||
'</simple>',
|
||||
directives: [Simple]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
expect(main.nativeElement).toHaveText('SIMPLE(A)');
|
||||
@ -58,12 +56,12 @@ export function main() {
|
||||
|
||||
it('should support simple components with text interpolation as direct children',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '{{\'START(\'}}<simple>' +
|
||||
'{{text}}' +
|
||||
'</simple>{{\')END\'}}',
|
||||
directives: [Simple]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '{{\'START(\'}}<simple>' +
|
||||
'{{text}}' +
|
||||
'</simple>{{\')END\'}}',
|
||||
directives: [Simple]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -78,11 +76,10 @@ export function main() {
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
Simple,
|
||||
new viewAnn.View(
|
||||
new View(
|
||||
{template: 'SIMPLE(<div><ng-content></ng-content></div>)', directives: []}))
|
||||
.overrideView(
|
||||
MainComp,
|
||||
new viewAnn.View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
|
||||
.overrideView(MainComp,
|
||||
new View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -96,13 +93,14 @@ export function main() {
|
||||
|
||||
it('should support projecting text interpolation to a non bound element with other bound elements after it',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(Simple, new viewAnn.View({
|
||||
template: 'SIMPLE(<div><ng-content></ng-content></div><div [tab-index]="0">EL</div>)',
|
||||
directives: []
|
||||
}))
|
||||
.overrideView(
|
||||
MainComp,
|
||||
new viewAnn.View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
|
||||
tcb.overrideView(
|
||||
Simple, new View({
|
||||
template:
|
||||
'SIMPLE(<div><ng-content></ng-content></div><div [tab-index]="0">EL</div>)',
|
||||
directives: []
|
||||
}))
|
||||
.overrideView(MainComp,
|
||||
new View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -115,8 +113,7 @@ export function main() {
|
||||
|
||||
it('should not show the light dom even if there is no content tag',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp,
|
||||
new viewAnn.View({template: '<empty>A</empty>', directives: [Empty]}))
|
||||
tcb.overrideView(MainComp, new View({template: '<empty>A</empty>', directives: [Empty]}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -127,14 +124,14 @@ export function main() {
|
||||
|
||||
it('should support multiple content tags',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<multiple-content-tags>' +
|
||||
'<div>B</div>' +
|
||||
'<div>C</div>' +
|
||||
'<div class="left">A</div>' +
|
||||
'</multiple-content-tags>',
|
||||
directives: [MultipleContentTagsComponent]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<multiple-content-tags>' +
|
||||
'<div>B</div>' +
|
||||
'<div>C</div>' +
|
||||
'<div class="left">A</div>' +
|
||||
'</multiple-content-tags>',
|
||||
directives: [MultipleContentTagsComponent]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -145,13 +142,13 @@ export function main() {
|
||||
|
||||
it('should redistribute only direct children',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<multiple-content-tags>' +
|
||||
'<div>B<div class="left">A</div></div>' +
|
||||
'<div>C</div>' +
|
||||
'</multiple-content-tags>',
|
||||
directives: [MultipleContentTagsComponent]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<multiple-content-tags>' +
|
||||
'<div>B<div class="left">A</div></div>' +
|
||||
'<div>C</div>' +
|
||||
'</multiple-content-tags>',
|
||||
directives: [MultipleContentTagsComponent]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -162,13 +159,13 @@ export function main() {
|
||||
|
||||
it("should redistribute direct child viewcontainers when the light dom changes",
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<multiple-content-tags>' +
|
||||
'<template manual class="left"><div>A1</div></template>' +
|
||||
'<div>B</div>' +
|
||||
'</multiple-content-tags>',
|
||||
directives: [MultipleContentTagsComponent, ManualViewportDirective]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<multiple-content-tags>' +
|
||||
'<template manual class="left"><div>A1</div></template>' +
|
||||
'<div>B</div>' +
|
||||
'</multiple-content-tags>',
|
||||
directives: [MultipleContentTagsComponent, ManualViewportDirective]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -188,13 +185,13 @@ export function main() {
|
||||
|
||||
it("should support nested components",
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<outer-with-indirect-nested>' +
|
||||
'<div>A</div>' +
|
||||
'<div>B</div>' +
|
||||
'</outer-with-indirect-nested>',
|
||||
directives: [OuterWithIndirectNestedComponent]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<outer-with-indirect-nested>' +
|
||||
'<div>A</div>' +
|
||||
'<div>B</div>' +
|
||||
'</outer-with-indirect-nested>',
|
||||
directives: [OuterWithIndirectNestedComponent]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -205,14 +202,14 @@ export function main() {
|
||||
|
||||
it("should support nesting with content being direct child of a nested component",
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<outer>' +
|
||||
'<template manual class="left"><div>A</div></template>' +
|
||||
'<div>B</div>' +
|
||||
'<div>C</div>' +
|
||||
'</outer>',
|
||||
directives: [OuterComponent, ManualViewportDirective],
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<outer>' +
|
||||
'<template manual class="left"><div>A</div></template>' +
|
||||
'<div>B</div>' +
|
||||
'<div>C</div>' +
|
||||
'</outer>',
|
||||
directives: [OuterComponent, ManualViewportDirective],
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -229,14 +226,14 @@ export function main() {
|
||||
|
||||
it('should redistribute when the shadow dom changes',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<conditional-content>' +
|
||||
'<div class="left">A</div>' +
|
||||
'<div>B</div>' +
|
||||
'<div>C</div>' +
|
||||
'</conditional-content>',
|
||||
directives: [ConditionalContentComponent]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<conditional-content>' +
|
||||
'<div class="left">A</div>' +
|
||||
'<div>B</div>' +
|
||||
'<div>C</div>' +
|
||||
'</conditional-content>',
|
||||
directives: [ConditionalContentComponent]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -263,8 +260,7 @@ export function main() {
|
||||
|
||||
tcb.overrideView(
|
||||
MainComp,
|
||||
new viewAnn.View(
|
||||
{template: '<simple string-prop="text"></simple>', directives: [Simple]}))
|
||||
new View({template: '<simple string-prop="text"></simple>', directives: [Simple]}))
|
||||
.overrideTemplate(Simple, '<ng-content></ng-content><p>P,</p>{{stringProp}}')
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
@ -284,8 +280,7 @@ export function main() {
|
||||
|
||||
tcb.overrideView(
|
||||
MainComp,
|
||||
new viewAnn.View(
|
||||
{template: '<simple string-prop="text"></simple>', directives: [Simple]}))
|
||||
new View({template: '<simple string-prop="text"></simple>', directives: [Simple]}))
|
||||
.overrideTemplate(Simple, '<style></style><p>P,</p>{{stringProp}}')
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
@ -298,13 +293,13 @@ export function main() {
|
||||
|
||||
it('should support moving non projected light dom around',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<empty>' +
|
||||
' <template manual><div>A</div></template>' +
|
||||
'</empty>' +
|
||||
'START(<div project></div>)END',
|
||||
directives: [Empty, ProjectDirective, ManualViewportDirective],
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<empty>' +
|
||||
' <template manual><div>A</div></template>' +
|
||||
'</empty>' +
|
||||
'START(<div project></div>)END',
|
||||
directives: [Empty, ProjectDirective, ManualViewportDirective],
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -323,11 +318,11 @@ export function main() {
|
||||
|
||||
it('should support moving projected light dom around',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<simple><template manual><div>A</div></template></simple>' +
|
||||
'START(<div project></div>)END',
|
||||
directives: [Simple, ProjectDirective, ManualViewportDirective],
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<simple><template manual><div>A</div></template></simple>' +
|
||||
'START(<div project></div>)END',
|
||||
directives: [Simple, ProjectDirective, ManualViewportDirective],
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -346,15 +341,16 @@ export function main() {
|
||||
|
||||
it('should support moving ng-content around',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<conditional-content>' +
|
||||
'<div class="left">A</div>' +
|
||||
'<div>B</div>' +
|
||||
'</conditional-content>' +
|
||||
'START(<div project></div>)END',
|
||||
directives:
|
||||
[ConditionalContentComponent, ProjectDirective, ManualViewportDirective]
|
||||
}))
|
||||
tcb.overrideView(
|
||||
MainComp, new View({
|
||||
template: '<conditional-content>' +
|
||||
'<div class="left">A</div>' +
|
||||
'<div>B</div>' +
|
||||
'</conditional-content>' +
|
||||
'START(<div project></div>)END',
|
||||
directives:
|
||||
[ConditionalContentComponent, ProjectDirective, ManualViewportDirective]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -382,8 +378,7 @@ export function main() {
|
||||
// the presence of ng-content elements!
|
||||
it('should still allow to implement a recursive trees',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp,
|
||||
new viewAnn.View({template: '<tree></tree>', directives: [Tree]}))
|
||||
tcb.overrideView(MainComp, new View({template: '<tree></tree>', directives: [Tree]}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -402,12 +397,12 @@ export function main() {
|
||||
if (DOM.supportsNativeShadowDOM()) {
|
||||
it('should support native content projection',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MainComp, new viewAnn.View({
|
||||
template: '<simple-native>' +
|
||||
'<div>A</div>' +
|
||||
'</simple-native>',
|
||||
directives: [SimpleNative]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: '<simple-native>' +
|
||||
'<div>A</div>' +
|
||||
'</simple-native>',
|
||||
directives: [SimpleNative]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
|
||||
@ -422,10 +417,10 @@ export function main() {
|
||||
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]
|
||||
}))
|
||||
tcb.overrideView(MainComp, new View({
|
||||
template: `<conditional-text>a</conditional-text>`,
|
||||
directives: [ConditionalTextComponent]
|
||||
}))
|
||||
.createAsync(MainComp)
|
||||
.then((main) => {
|
||||
expect(main.nativeElement).toHaveText('MAIN()');
|
||||
|
@ -29,11 +29,18 @@ import {
|
||||
createDirectiveVariableBindings,
|
||||
createVariableLocations
|
||||
} from 'angular2/src/core/compiler/proto_view_factory';
|
||||
import {Component, Directive} from 'angular2/annotations';
|
||||
import {Component, Directive} from 'angular2/metadata';
|
||||
import {Key} from 'angular2/di';
|
||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||
import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
import {
|
||||
RenderElementBinder,
|
||||
EventBinding,
|
||||
RenderDirectiveMetadata,
|
||||
ViewType,
|
||||
ProtoViewDto,
|
||||
DirectiveBinder
|
||||
} from 'angular2/src/render/api';
|
||||
|
||||
export function main() {
|
||||
// TODO(tbosch): add missing tests
|
||||
@ -81,15 +88,15 @@ export function main() {
|
||||
describe("createDirectiveVariableBindings", () => {
|
||||
it("should calculate directive variable bindings", () => {
|
||||
var dvbs = createDirectiveVariableBindings(
|
||||
new renderApi.ElementBinder({
|
||||
new RenderElementBinder({
|
||||
variableBindings:
|
||||
MapWrapper.createFromStringMap<string>({"exportName": "templateName"})
|
||||
}),
|
||||
[
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})}),
|
||||
{metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})}),
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'otherName'})})
|
||||
{metadata: RenderDirectiveMetadata.create({exportAs: 'otherName'})})
|
||||
]);
|
||||
|
||||
expect(dvbs).toEqual(MapWrapper.createFromStringMap<number>({"templateName": 0}));
|
||||
@ -97,14 +104,14 @@ export function main() {
|
||||
|
||||
it("should set exportAs to $implicit for component with exportAs = null", () => {
|
||||
var dvbs = createDirectiveVariableBindings(
|
||||
new renderApi.ElementBinder({
|
||||
new RenderElementBinder({
|
||||
variableBindings:
|
||||
MapWrapper.createFromStringMap<string>({"$implicit": "templateName"})
|
||||
}),
|
||||
[
|
||||
directiveBinding({
|
||||
metadata: renderApi.DirectiveMetadata.create(
|
||||
{exportAs: null, type: renderApi.DirectiveMetadata.COMPONENT_TYPE})
|
||||
metadata: RenderDirectiveMetadata.create(
|
||||
{exportAs: null, type: RenderDirectiveMetadata.COMPONENT_TYPE})
|
||||
})
|
||||
]);
|
||||
|
||||
@ -114,13 +121,13 @@ export function main() {
|
||||
it("should throw we no directive exported with this name", () => {
|
||||
expect(() => {
|
||||
createDirectiveVariableBindings(
|
||||
new renderApi.ElementBinder({
|
||||
new RenderElementBinder({
|
||||
variableBindings:
|
||||
MapWrapper.createFromStringMap<string>({"someInvalidName": "templateName"})
|
||||
}),
|
||||
[
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})})
|
||||
{metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})})
|
||||
]);
|
||||
}).toThrowError(new RegExp("Cannot find directive with exportAs = 'someInvalidName'"));
|
||||
});
|
||||
@ -128,28 +135,26 @@ export function main() {
|
||||
it("should throw when binding to a name exported by two directives", () => {
|
||||
expect(() => {
|
||||
createDirectiveVariableBindings(
|
||||
new renderApi.ElementBinder({
|
||||
new RenderElementBinder({
|
||||
variableBindings:
|
||||
MapWrapper.createFromStringMap<string>({"exportName": "templateName"})
|
||||
}),
|
||||
[
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})}),
|
||||
{metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})}),
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})})
|
||||
{metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})})
|
||||
]);
|
||||
}).toThrowError(new RegExp("More than one directive have exportAs = 'exportName'"));
|
||||
});
|
||||
|
||||
it("should not throw when not binding to a name exported by two directives", () => {
|
||||
expect(() => {
|
||||
createDirectiveVariableBindings(
|
||||
new renderApi.ElementBinder({variableBindings: new Map()}), [
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})}),
|
||||
directiveBinding(
|
||||
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})})
|
||||
]);
|
||||
createDirectiveVariableBindings(new RenderElementBinder({variableBindings: new Map()}), [
|
||||
directiveBinding({metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})}),
|
||||
directiveBinding(
|
||||
{metadata: RenderDirectiveMetadata.create({exportAs: 'exportName'})})
|
||||
]);
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
@ -157,9 +162,9 @@ export function main() {
|
||||
describe('createVariableLocations', () => {
|
||||
it('should merge the names in the template for all ElementBinders', () => {
|
||||
expect(createVariableLocations([
|
||||
new renderApi.ElementBinder(
|
||||
new RenderElementBinder(
|
||||
{variableBindings: MapWrapper.createFromStringMap<string>({"x": "a"})}),
|
||||
new renderApi.ElementBinder(
|
||||
new RenderElementBinder(
|
||||
{variableBindings: MapWrapper.createFromStringMap<string>({"y": "b"})})
|
||||
|
||||
])).toEqual(MapWrapper.createFromStringMap<number>({'a': 0, 'b': 1}));
|
||||
@ -175,10 +180,10 @@ export function main() {
|
||||
it("should return template event records", () => {
|
||||
var rec = creator.getEventBindingRecords(
|
||||
[
|
||||
new renderApi.ElementBinder(
|
||||
{eventBindings: [new renderApi.EventBinding("a", null)], directives: []}),
|
||||
new renderApi.ElementBinder(
|
||||
{eventBindings: [new renderApi.EventBinding("b", null)], directives: []})
|
||||
new RenderElementBinder(
|
||||
{eventBindings: [new EventBinding("a", null)], directives: []}),
|
||||
new RenderElementBinder(
|
||||
{eventBindings: [new EventBinding("b", null)], directives: []})
|
||||
],
|
||||
[]);
|
||||
|
||||
@ -191,17 +196,15 @@ export function main() {
|
||||
it('should return host event records', () => {
|
||||
var rec = creator.getEventBindingRecords(
|
||||
[
|
||||
new renderApi.ElementBinder({
|
||||
new RenderElementBinder({
|
||||
eventBindings: [],
|
||||
directives: [
|
||||
new renderApi.DirectiveBinder({
|
||||
directiveIndex: 0,
|
||||
eventBindings: [new renderApi.EventBinding("a", null)]
|
||||
})
|
||||
new DirectiveBinder(
|
||||
{directiveIndex: 0, eventBindings: [new EventBinding("a", null)]})
|
||||
]
|
||||
})
|
||||
],
|
||||
[renderApi.DirectiveMetadata.create({id: 'some-id'})]);
|
||||
[RenderDirectiveMetadata.create({id: 'some-id'})]);
|
||||
|
||||
expect(rec.length).toEqual(1);
|
||||
expect(rec[0].eventName).toEqual("a");
|
||||
@ -216,10 +219,10 @@ function directiveBinding({metadata}: {metadata?: any} = {}) {
|
||||
return new DirectiveBinding(Key.get("dummy"), null, [], [], [], metadata);
|
||||
}
|
||||
|
||||
function createRenderProtoView(elementBinders = null, type: renderApi.ViewType = null,
|
||||
function createRenderProtoView(elementBinders = null, type: ViewType = null,
|
||||
variableBindings = null) {
|
||||
if (isBlank(type)) {
|
||||
type = renderApi.ViewType.COMPONENT;
|
||||
type = ViewType.COMPONENT;
|
||||
}
|
||||
if (isBlank(elementBinders)) {
|
||||
elementBinders = [];
|
||||
@ -227,7 +230,7 @@ function createRenderProtoView(elementBinders = null, type: renderApi.ViewType =
|
||||
if (isBlank(variableBindings)) {
|
||||
variableBindings = new Map();
|
||||
}
|
||||
return new renderApi.ProtoViewDto({
|
||||
return new ProtoViewDto({
|
||||
elementBinders: elementBinders,
|
||||
type: type,
|
||||
variableBindings: variableBindings,
|
||||
@ -237,12 +240,12 @@ function createRenderProtoView(elementBinders = null, type: renderApi.ViewType =
|
||||
}
|
||||
|
||||
function createRenderComponentElementBinder(directiveIndex) {
|
||||
return new renderApi.ElementBinder(
|
||||
{directives: [new renderApi.DirectiveBinder({directiveIndex: directiveIndex})]});
|
||||
return new RenderElementBinder(
|
||||
{directives: [new DirectiveBinder({directiveIndex: directiveIndex})]});
|
||||
}
|
||||
|
||||
function createRenderViewportElementBinder(nestedProtoView) {
|
||||
return new renderApi.ElementBinder({nestedProtoView: nestedProtoView});
|
||||
return new RenderElementBinder({nestedProtoView: nestedProtoView});
|
||||
}
|
||||
|
||||
@proxy
|
||||
|
@ -17,7 +17,7 @@ import {
|
||||
|
||||
import {Injectable, Optional} from 'angular2/di';
|
||||
import {QueryList, TemplateRef} from 'angular2/core';
|
||||
import {Query, ViewQuery, Component, Directive, View} from 'angular2/annotations';
|
||||
import {Query, ViewQuery, Component, Directive, View} from 'angular2/metadata';
|
||||
|
||||
import {NgIf, NgFor} from 'angular2/angular2';
|
||||
|
||||
|
@ -32,7 +32,7 @@ import {
|
||||
ProtoElementInjector
|
||||
} from 'angular2/src/core/compiler/element_injector';
|
||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||
import {Component} from 'angular2/annotations';
|
||||
import {Component} from 'angular2/metadata';
|
||||
import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils';
|
||||
import {
|
||||
RenderProtoViewMergeMapping,
|
||||
|
Reference in New Issue
Block a user