v3.0.0
- Make it more strongly-typed when used with TypeScript (#25) cceddeb
- Improve type inference for the listener callback (#19) 46a07f7
This release is a breaking change only for TypeScript users, making the types more strict and exact. Example upgrade:
v2-
delegate(document, 'button.primary', 'click', event => {
// event is Event
// event.delegateTarget is HTMLElement
});
delegate<HTMLButtonElement, MouseEvent>(document, 'button.primary', 'click', event => {
// event is MouseEvent
// event.delegateTarget is HTMLButtonElement
});
v3+
As long as the selector correctly includes the tag name, typed-query-selector will parse it to detect the expected element type. Events are matched via GlobalEventHandlersEventMap
as was already documented in readme.
delegate(document, 'button.primary', 'click', event => {
// event is MouseEvent, automatically
// event.delegateTarget is HTMLButtonElement, automatically parsing the selector
});