@firefox-devtools/react-contextmenu
Version:
Context Menu implemented in React
41 lines (40 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _actions = require("./actions");
var _helpers = require("./helpers");
class GlobalEventListener {
constructor() {
this.callbacks = {};
if (_helpers.canUseDOM) {
window.addEventListener(_actions.MENU_SHOW, this.handleShowEvent);
window.addEventListener(_actions.MENU_HIDE, this.handleHideEvent);
}
}
handleShowEvent = event => {
for (const id in this.callbacks) {
if ((0, _helpers.hasOwnProp)(this.callbacks, id)) this.callbacks[id].show(event);
}
};
handleHideEvent = event => {
for (const id in this.callbacks) {
if ((0, _helpers.hasOwnProp)(this.callbacks, id)) this.callbacks[id].hide(event);
}
};
register = (showCallback, hideCallback) => {
const id = (0, _helpers.uniqueId)();
this.callbacks[id] = {
show: showCallback,
hide: hideCallback
};
return id;
};
unregister = id => {
if (id && this.callbacks[id]) {
delete this.callbacks[id];
}
};
}
var _default = exports.default = new GlobalEventListener();