feat(transformers): added support for lifecycle events

This commit is contained in:
vsavkin
2015-05-28 17:28:53 -07:00
parent 6f0631c978
commit f19970a481
6 changed files with 95 additions and 5 deletions
@@ -15,7 +15,12 @@ export function main() {
properties: ['propKey: propVal'],
readAttributes: ['read1', 'read2'],
selector: 'some-comp',
type: DirectiveMetadata.COMPONENT_TYPE
type: DirectiveMetadata.COMPONENT_TYPE,
callOnDestroy: true,
callOnChange: true,
callOnCheck: true,
callOnInit: true,
callOnAllChangesDone: true
});
var map = directiveMetadataToMap(someComponent);
expect(MapWrapper.get(map, 'compileChildren')).toEqual(false);
@@ -30,6 +35,11 @@ export function main() {
expect(MapWrapper.get(map, 'readAttributes')).toEqual(['read1', 'read2']);
expect(MapWrapper.get(map, 'selector')).toEqual('some-comp');
expect(MapWrapper.get(map, 'type')).toEqual(DirectiveMetadata.COMPONENT_TYPE);
expect(MapWrapper.get(map, 'callOnDestroy')).toEqual(true);
expect(MapWrapper.get(map, 'callOnCheck')).toEqual(true);
expect(MapWrapper.get(map, 'callOnChange')).toEqual(true);
expect(MapWrapper.get(map, 'callOnInit')).toEqual(true);
expect(MapWrapper.get(map, 'callOnAllChangesDone')).toEqual(true);
});
it('mapToDirectiveMetadata', () => {
@@ -42,7 +52,12 @@ export function main() {
['properties', ['propKey: propVal']],
['readAttributes', ['readTest1', 'readTest2']],
['selector', 'testSelector'],
['type', DirectiveMetadata.DIRECTIVE_TYPE]
['type', DirectiveMetadata.DIRECTIVE_TYPE],
['callOnDestroy', true],
['callOnCheck', true],
['callOnInit', true],
['callOnChange', true],
['callOnAllChangesDone', true]
]);
var meta = directiveMetadataFromMap(map);
expect(meta.compileChildren).toEqual(false);
@@ -56,6 +71,11 @@ export function main() {
expect(meta.readAttributes).toEqual(['readTest1', 'readTest2']);
expect(meta.selector).toEqual('testSelector');
expect(meta.type).toEqual(DirectiveMetadata.DIRECTIVE_TYPE);
expect(meta.callOnDestroy).toEqual(true);
expect(meta.callOnCheck).toEqual(true);
expect(meta.callOnInit).toEqual(true);
expect(meta.callOnChange).toEqual(true);
expect(meta.callOnAllChangesDone).toEqual(true);
});
});
}
@@ -78,6 +78,16 @@ void allTests() {
expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)');
});
it('should parse lifecycle events.', () async {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/lifecycle.ng_deps.dart');
expect(metadata.callOnDestroy).toBe(true);
expect(metadata.callOnChange).toBe(true);
expect(metadata.callOnCheck).toBe(true);
expect(metadata.callOnInit).toBe(true);
expect(metadata.callOnAllChangesDone).toBe(true);
});
it('should fail when a class is annotated with multiple Directives.',
() async {
var ngDeps = await parser.parse(new AssetId('a',
@@ -0,0 +1,19 @@
library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show bootstrap, Component, Directive, View, NgElement, onChange, onDestroy, onInit, onCheck, onAllChangesDone;
var _visited = false;
void initReflector(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [const []],
'annotations': const [
const Component(lifecycle: [onChange, onDestroy, onInit, onCheck, onAllChangesDone])
]
});
}
@@ -10,6 +10,11 @@
"properties": [],
"readAttributes": [],
"type": 1,
"callOnDestroy": false,
"callOnCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"version": 1
}
}