Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(eventHandler): Support snake-case event names instead of camelCase.
Browse files Browse the repository at this point in the history
Closes #1434
Closes #1478

Closes #1477
  • Loading branch information
jbdeboer authored and vsavkin committed Sep 18, 2014
1 parent dd16775 commit fd54c30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
20 changes: 5 additions & 15 deletions lib/core_dom/event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,16 @@ class EventHandler {
}

/**
* Converts event name into attribute. Event named 'someCustomEvent' needs to
* be transformed into on-some-custom-event.
* Converts event name into attribute name.
*/
static String eventNameToAttrName(String eventName) {
var part = eventName.replaceAllMapped(new RegExp("([A-Z])"), (Match match) {
return '-${match.group(0).toLowerCase()}';
});
return 'on-${part}';
}
static String eventNameToAttrName(String eventName) => 'on-$eventName';

/**
* Converts attribute into event name. Attribute 'on-some-custom-event'
* corresponds to event named 'someCustomEvent'.
* Converts attribute name into event name.
*/
static String attrNameToEventName(String attrName) {
var part = attrName.startsWith("on-") ? attrName.substring(3) : attrName;
part = part.replaceAllMapped(new RegExp(r'\-(\w)'), (Match match) {
return match.group(0).toUpperCase();
});
return part.replaceAll("-", "");
assert(attrName.startsWith('on-'));
return attrName.substring(3);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/core_dom/event_handler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ main() {
var e = compile(_,
'''<div on-my-new-event="invoked=true;"></div>''');

_.triggerEvent(e, 'myNewEvent');
_.triggerEvent(e, 'my-new-event');
expect(_.rootScope.context['invoked']).toEqual(true);
});

Expand Down

0 comments on commit fd54c30

Please sign in to comment.