Skip to content

Commit

Permalink
DOM event handler fix, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSoderholm committed Feb 4, 2018
1 parent cc57d92 commit d01d06e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resolve-handlers",
"version": "0.1.2",
"version": "0.1.3",
"description": "Resolve handlers from strings.",
"main": "index.js",
"dependencies": {},
Expand Down
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ export function getDOMEventHandler(handlerName, eventType, selector, useCapture,
}
// Handler method
const handler = (event, ...handlerArgs) => {
// If no selector, just call handler
if (!selector) {
this[handlerName](event, ...args.concat(handlerArgs));
return;
}
// Find closest parent that matches selector
const currentTarget = componentClosest(event.target, selector, event.currentTarget);
// If no selector or currentTarget found
if (!selector || currentTarget) {
// event proxy, override currentTarget property.
const eventProxy = new Proxy(event, {
// If currentTarget found
if (currentTarget) {
// Proxy event, override currentTarget property.
event = new Proxy(event, {
get: function(target, prop, receiver) {
if (prop === 'currentTarget') {
return currentTarget;
Expand All @@ -125,8 +130,8 @@ export function getDOMEventHandler(handlerName, eventType, selector, useCapture,
}
}
});
// Call handler
this[handlerName](eventProxy, ...args.concat(handlerArgs));
// Call if currentTarget found for selector
this[handlerName](event, ...args.concat(handlerArgs));
}
};
// Set attributes on handler for easy add/remove listeners
Expand Down

0 comments on commit d01d06e

Please sign in to comment.