Skip to content

Commit

Permalink
fix: fix redundant event dispatch (#599)
Browse files Browse the repository at this point in the history
Including  multiple instances of the webcomponents on the same page
causes the global event handlers to be registered multiple times
This then causes multiple calls of the event handlers on the prototype
and multiple semantic events being fired.
  • Loading branch information
pskelin authored Jul 1, 2019
1 parent b0d09a9 commit dc0cda2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/base/src/DOMEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,25 @@ const getParentDOMNode = function getParentDOMNode(node) {
return parentNode;
};

const isOtherInstanceRegistered = () => {
return window["@ui5/webcomponents-base/DOMEventHandler"];
};

const registerInstance = () => {
window["@ui5/webcomponents-base/DOMEventHandler"] = true;
};

class DOMEventHandler {
constructor() {
throw new Error("Static class");
}

static start() {
ManagedEvents.bindAllEvents(handleEvent);
// register the handlers just once in case other bundles include and call this method multiple times
if (!isOtherInstanceRegistered()) {
ManagedEvents.bindAllEvents(handleEvent);
registerInstance();
}
}

static stop() {
Expand Down

0 comments on commit dc0cda2

Please sign in to comment.