Skip to content

Commit

Permalink
Feature Capture Event
Browse files Browse the repository at this point in the history
added suggested improvements

capture added to removeEventListener and getEventName

Made the appropriate changes

Review Changes done
  • Loading branch information
vipulbhj committed Sep 9, 2020
1 parent cbf4985 commit 69185cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/updateAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ function setAttribute(node, attrName, attrValue, oldAttrValue, isSvgAttribute) {

// Handle event attributes
if (isEventAttr) {
let eventName = getEventName(attrName);
const isCaptureEvent = attrName.substr(-7) === 'Capture' && attrName.substr(-14, 7) !== 'Pointer';
let eventName = getEventName(attrName, isCaptureEvent);
eventName = getEffectiveEventName(eventName, node);

// get patched event handler
const patchedHandler = getPatchedEventHandler(node, attrName, attrValue);

// if new event handler is not there but it had old handler, remove the old one
if (oldAttrValue && !attrValue) {
node.removeEventListener(eventName, patchedHandler);

node.removeEventListener(eventName, patchedHandler, isCaptureEvent);
// if the event is getting added first time add a listener
} else if (!oldAttrValue && attrValue) {
node.addEventListener(eventName, patchedHandler);
node.addEventListener(eventName, patchedHandler, isCaptureEvent);
}

// handle style attributes
Expand Down
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export function getNodeName(node) {
return node.nodeName.toLowerCase();
}

export function getEventName(attrName) {
export function getEventName(attrName, isCaptureEvent) {
if(isCaptureEvent) {
attrName = attrName.replace(/Capture$/, '');
}
return attrName.replace('on', '').toLowerCase();
}

Expand Down

0 comments on commit 69185cc

Please sign in to comment.