fix(transformer): Event getters now use property name not event name

This commit is contained in:
Jacob MacDonald 2015-07-13 08:36:44 -07:00
parent a9a552c112
commit cf103de4a7
4 changed files with 23 additions and 20 deletions

View File

@ -15,7 +15,7 @@ Future<String> createNgSettersAndGetters(
String code = ngDeps.code;
var setters = _generateSetters(_createPropertiesMap(ngDeps));
var getters = _generateGetters(_createEventsMap(ngDeps));
var getters = _generateGetters( _createEventPropertiesList(ngDeps));
if (setters.isEmpty && getters.isEmpty) return code;
var out = new StringBuffer();
@ -79,35 +79,36 @@ Map<String, String> _createPropertiesMap(NgDeps ngDeps) {
return bindMap;
}
/// Consumes the map generated by {@link _createEventsMap} to codegen getters.
List<String> _generateGetters(Map<String, String> bindMap) {
/// Consumes the list generated by {@link _createEventPropertiesList} to codegen
/// getters.
List<String> _generateGetters(List<String> eventProperties) {
var getters = [];
// TODO(kegluneq): Include types for receivers. See #886.
bindMap.forEach((getterName, eventName) {
if (!prop.isValid(eventName)) {
for (var property in eventProperties) {
if (!prop.isValid(property)) {
// TODO(kegluenq): Eagerly throw here once #1295 is addressed.
getters.add(prop.lazyInvalidGetter(eventName));
getters.add(prop.lazyInvalidGetter(property));
} else {
getters.add(''' '${prop.sanitize(eventName)}': (o) => o.$getterName''');
getters.add(''' '${prop.sanitize(property)}': (o) => o.$property''');
}
});
}
return getters;
}
/// Collapses all `events` in {@link ngDeps} into a map where the keys are
/// the property names for the event emitters and the values are the event name.
Map<String, String> _createEventsMap(NgDeps ngDeps) {
/// Collapses all `events` in {@link ngDeps} into a list of corresponding
/// property names.
List<String> _createEventPropertiesList(NgDeps ngDeps) {
var visitor = new ExtractNamedExpressionVisitor('events');
var bindMap = {};
var propertyNames = [];
ngDeps.registeredTypes.forEach((RegisteredType t) {
visitor.bindConfig.clear();
t.annotations.accept(visitor);
visitor.bindConfig.forEach((String config) {
// See comments for `Directive` in annotations_impl/annotations.ts for
// details on how `events` is specified.
var parts = config.split(':').map((p) => p.trim()).toList();
bindMap[parts[0]] = parts.length > 1 ? parts[1] : parts[0];
// details on how `events` is specified. We are pulling out the property
// name only (everything before the first `:`).
propertyNames.add(config.split(':').first.trim());
});
});
return bindMap;
return propertyNames;
}

View File

@ -10,7 +10,9 @@ class NullReflectionCapabilities implements ReflectionCapabilities {
_notImplemented(String name) => throw 'Not implemented: $name';
bool isReflectionEnabled() { return false; }
bool isReflectionEnabled() {
return false;
}
Function factory(Type type) => _notImplemented('factory');

View File

@ -13,7 +13,7 @@ void initReflector(reflector) {
'parameters': const [],
'annotations': const [
const Directive(
selector: '[tool-tip]', events: ['onOpen', 'close: onClose'])
selector: '[tool-tip]', events: const ['onOpen', 'close: onClose'])
]
});
}

View File

@ -13,8 +13,8 @@ void initReflector(reflector) {
'parameters': const [],
'annotations': const [
const Directive(
selector: '[tool-tip]', events: ['onOpen', 'close: onClose'])
selector: '[tool-tip]', events: const ['onOpen', 'close: onClose'])
]
})
..registerGetters({'onOpen': (o) => o.onOpen, 'onClose': (o) => o.close});
..registerGetters({'onOpen': (o) => o.onOpen, 'close': (o) => o.close});
}