Skip to content

Commit a68663e

Browse files
authored
explicit capture option in addEventListener (atom#21562)
Based on the docs true is equal to {capture: true} > In older versions of the DOM specification, the third parameter of addEventListener() was a Boolean value indicating whether or not to use capture. Over time, it became clear that more options were needed. Rather than adding more parameters to the function (complicating things enormously when dealing with optional values), the third parameter was changed to an object that can contain various properties defining the values of options to configure the process of removing the event listener. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners
1 parent 37001d1 commit a68663e

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

src/atom-environment.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,16 @@ class AtomEnvironment {
340340
if (!this.unloading) this.saveState({ isUnloading: false });
341341
});
342342
}, this.saveStateDebounceInterval);
343-
this.document.addEventListener('mousedown', saveState, true);
344-
this.document.addEventListener('keydown', saveState, true);
343+
this.document.addEventListener('mousedown', saveState, { capture: true });
344+
this.document.addEventListener('keydown', saveState, { capture: true });
345345
this.disposables.add(
346346
new Disposable(() => {
347-
this.document.removeEventListener('mousedown', saveState, true);
348-
this.document.removeEventListener('keydown', saveState, true);
347+
this.document.removeEventListener('mousedown', saveState, {
348+
capture: true
349+
});
350+
this.document.removeEventListener('keydown', saveState, {
351+
capture: true
352+
});
349353
})
350354
);
351355
}

src/command-registry.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,9 @@ module.exports = class CommandRegistry {
421421

422422
commandRegistered(commandName) {
423423
if (this.rootNode != null && !this.registeredCommands[commandName]) {
424-
this.rootNode.addEventListener(
425-
commandName,
426-
this.handleCommandEvent,
427-
true
428-
);
424+
this.rootNode.addEventListener(commandName, this.handleCommandEvent, {
425+
capture: true
426+
});
429427
return (this.registeredCommands[commandName] = true);
430428
}
431429
}

src/initialize-benchmark-window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = async function() {
6363
ipcHelpers.call('window-method', 'copy');
6464
}
6565
},
66-
true
66+
{ capture: true }
6767
);
6868

6969
const clipboard = new Clipboard();

src/initialize-test-window.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ module.exports = ({blobStore}) ->
6262
# Copy: cmd-c / ctrl-c
6363
if (event.metaKey or event.ctrlKey) and event.keyCode is 67
6464
atom.clipboard.write(window.getSelection().toString())
65-
66-
window.addEventListener('keydown', handleKeydown, true)
65+
66+
window.addEventListener('keydown', handleKeydown, {capture: true})
6767

6868
# Add 'exports' to module search path.
6969
exportsPath = path.join(getWindowLoadSettings().resourcePath, 'exports')

src/pane-element.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class PaneElement extends HTMLElement {
6565
this.applicationDelegate.open({ pathsToOpen, here: true });
6666
}
6767
};
68-
this.addEventListener('focus', handleFocus, true);
69-
this.addEventListener('blur', handleBlur, true);
68+
this.addEventListener('focus', handleFocus, { capture: true });
69+
this.addEventListener('blur', handleBlur, { capture: true });
7070
this.addEventListener('dragover', handleDragOver);
7171
this.addEventListener('drop', handleDrop);
7272
}

src/tooltip.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ Tooltip.prototype.leave = function(event) {
259259
Tooltip.prototype.show = function() {
260260
if (this.hasContent() && this.enabled) {
261261
if (this.hideOnClickOutsideOfTooltip) {
262-
window.addEventListener('click', this.hideOnClickOutsideOfTooltip, true);
262+
window.addEventListener('click', this.hideOnClickOutsideOfTooltip, {
263+
capture: true
264+
});
263265
}
264266

265267
if (this.hideOnKeydownOutsideOfTooltip) {

src/workspace-element.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ class WorkspaceElement extends HTMLElement {
158158
this.verticalAxis.appendChild(this.paneContainer);
159159
this.addEventListener('focus', this.handleFocus.bind(this));
160160

161-
this.addEventListener('mousewheel', this.handleMousewheel.bind(this), true);
161+
this.addEventListener('mousewheel', this.handleMousewheel.bind(this), {
162+
capture: true
163+
});
162164
window.addEventListener('dragstart', this.handleDragStart);
163165
window.addEventListener('mousemove', this.handleEdgesMouseMove);
164166

@@ -208,8 +210,8 @@ class WorkspaceElement extends HTMLElement {
208210
const { item } = event.target;
209211
if (!item) return;
210212
this.model.setDraggingItem(item);
211-
window.addEventListener('dragend', this.handleDragEnd, true);
212-
window.addEventListener('drop', this.handleDrop, true);
213+
window.addEventListener('dragend', this.handleDragEnd, { capture: true });
214+
window.addEventListener('drop', this.handleDrop, { capture: true });
213215
}
214216

215217
handleDragEnd(event) {

0 commit comments

Comments
 (0)