feat(compiler): added support for host actions

This commit is contained in:
vsavkin
2015-05-11 12:31:16 -07:00
parent a9ce0f7afb
commit f9c1de46b3
22 changed files with 330 additions and 17 deletions
@@ -25,7 +25,8 @@ export function main() {
someDirectiveWithHostProperties,
someDirectiveWithHostAttributes,
someDirectiveWithEvents,
someDirectiveWithGlobalEvents
someDirectiveWithGlobalEvents,
someDirectiveWithHostActions
];
parser = new Parser(new Lexer());
});
@@ -171,6 +172,14 @@ export function main() {
expect(eventBinding.source.source).toEqual('doItGlobal()');
});
it('should bind directive host actions', () => {
var results = process(
el('<div some-decor-host-actions></div>')
);
var directiveBinding = results[0].directives[0];
expect(directiveBinding.hostActions[0].actionName).toEqual('focus');
});
//TODO: assertions should be enabled when running tests: https://github.com/angular/angular/issues/1340
describe('component directives', () => {
it('should save the component id', () => {
@@ -276,6 +285,13 @@ var someDirectiveWithEvents = new DirectiveMetadata({
})
});
var someDirectiveWithHostActions = new DirectiveMetadata({
selector: '[some-decor-host-actions]',
hostActions: MapWrapper.createFromStringMap({
'focus': 'focus()'
})
});
var someDirectiveWithGlobalEvents = new DirectiveMetadata({
selector: '[some-decor-globalevents]',
hostListeners: MapWrapper.createFromStringMap({
@@ -287,4 +303,4 @@ var componentWithNonElementSelector = new DirectiveMetadata({
id: 'componentWithNonElementSelector',
selector: '[attr]',
type: DirectiveMetadata.COMPONENT_TYPE
});
});
+9 -1
View File
@@ -2,7 +2,7 @@ import {MapWrapper} from 'angular2/src/facade/collection';
import {DirectiveMetadata} from 'angular2/src/render/api';
import {directiveMetadataFromMap, directiveMetadataToMap} from
'angular2/src/render/dom/convert';
import {describe, expect, it} from 'angular2/test_lib';
import {ddescribe, describe, expect, it} from 'angular2/test_lib';
export function main() {
describe('convert', () => {
@@ -12,6 +12,8 @@ export function main() {
hostListeners: MapWrapper.createFromPairs([['listenKey', 'listenVal']]),
hostProperties:
MapWrapper.createFromPairs([['hostPropKey', 'hostPropVal']]),
hostActions:
MapWrapper.createFromPairs([['hostActionKey', 'hostActionVal']]),
id: 'someComponent',
properties: MapWrapper.createFromPairs([['propKey', 'propVal']]),
readAttributes: ['read1', 'read2'],
@@ -24,6 +26,8 @@ export function main() {
MapWrapper.createFromPairs([['listenKey', 'listenVal']]));
expect(MapWrapper.get(map, 'hostProperties')).toEqual(
MapWrapper.createFromPairs([['hostPropKey', 'hostPropVal']]));
expect(MapWrapper.get(map, 'hostActions')).toEqual(
MapWrapper.createFromPairs([['hostActionKey', 'hostActionVal']]));
expect(MapWrapper.get(map, 'id')).toEqual('someComponent');
expect(MapWrapper.get(map, 'properties')).toEqual(
MapWrapper.createFromPairs([['propKey', 'propVal']]));
@@ -39,6 +43,8 @@ export function main() {
['hostListeners', MapWrapper.createFromPairs([['testKey', 'testVal']])],
['hostProperties',
MapWrapper.createFromPairs([['hostPropKey', 'hostPropVal']])],
['hostActions',
MapWrapper.createFromPairs([['hostActionKey', 'hostActionVal']])],
['id', 'testId'],
['properties', MapWrapper.createFromPairs([['propKey', 'propVal']])],
['readAttributes', ['readTest1', 'readTest2']],
@@ -51,6 +57,8 @@ export function main() {
MapWrapper.createFromPairs([['testKey', 'testVal']]));
expect(meta.hostProperties).toEqual(
MapWrapper.createFromPairs([['hostPropKey', 'hostPropVal']]));
expect(meta.hostActions).toEqual(
MapWrapper.createFromPairs([['hostActionKey', 'hostActionVal']]));
expect(meta.id).toEqual('testId');
expect(meta.properties).toEqual(
MapWrapper.createFromPairs([['propKey', 'propVal']]));
@@ -96,6 +96,25 @@ export function main() {
});
}));
it('should call actions on the element',
inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
tb.compileAll([someComponent,
new ViewDefinition({
componentId: 'someComponent',
template: '<div with-host-actions></div>',
directives: [directiveWithHostActions]
})
]).then( (protoViewDtos) => {
var views = tb.createRootViews(protoViewDtos);
var componentView = views[1];
tb.renderer.callAction(componentView.viewRef, 0, 'setAttribute("key", "value")', null);
expect(DOM.getOuterHTML(tb.rootEl)).toContain('key="value"');
async.done();
});
}));
it('should add and remove views to and from containers',
inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
tb.compileAll([someComponent,
@@ -152,3 +171,12 @@ var someComponent = new DirectiveMetadata({
type: DirectiveMetadata.COMPONENT_TYPE,
selector: 'some-comp'
});
var directiveWithHostActions = new DirectiveMetadata({
id: 'withHostActions',
type: DirectiveMetadata.DIRECTIVE_TYPE,
selector: '[with-host-actions]',
hostActions: MapWrapper.createFromStringMap({
'setAttr' : 'setAttribute("key", "value")'
})
});