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
@@ -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
}
}