Skip to content

Commit b6dbd71

Browse files
committed
Reactivate unbound-method
1 parent 939f901 commit b6dbd71

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

ember-basic-dropdown/eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export default ts.config(
8787
extends: [...ts.configs.recommendedTypeChecked, ember.configs.gts],
8888
rules: {
8989
'@typescript-eslint/no-unsafe-call': 'off',
90-
'@typescript-eslint/unbound-method': 'off',
9190
},
9291
},
9392
{

ember-basic-dropdown/src/components/basic-dropdown-content.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,17 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
202202
);
203203
}
204204

205-
window.addEventListener('resize', this.runloopAwareReposition);
206-
window.addEventListener('orientationchange', this.runloopAwareReposition);
205+
window.addEventListener('resize', this.runloopAwareRepositionBound);
206+
window.addEventListener('orientationchange', this.runloopAwareRepositionBound);
207207

208208
if (this.isTouchDevice) {
209-
document.addEventListener('touchstart', this.touchStartHandler, true);
209+
document.addEventListener('touchstart', this.touchStartHandlerBound, true);
210210
document.addEventListener('touchend', this.handleRootMouseDown, true);
211211

212212
if (rootElement) {
213213
rootElement.addEventListener(
214214
'touchstart',
215-
this.touchStartHandler,
215+
this.touchStartHandlerBound,
216216
true,
217217
);
218218
rootElement.addEventListener(
@@ -259,7 +259,7 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
259259
if (this.isTouchDevice) {
260260
document.removeEventListener(
261261
'touchstart',
262-
this.touchStartHandler,
262+
this.touchStartHandlerBound,
263263
true,
264264
);
265265
document.removeEventListener(
@@ -271,7 +271,7 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
271271
if (rootElement) {
272272
rootElement.removeEventListener(
273273
'touchstart',
274-
this.touchStartHandler,
274+
this.touchStartHandlerBound,
275275
true,
276276
);
277277
rootElement.removeEventListener(
@@ -369,28 +369,28 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
369369

370370
@action
371371
touchStartHandler(): void {
372-
document.addEventListener('touchmove', this.touchMoveHandler, true);
372+
document.addEventListener('touchmove', this.touchMoveHandlerBound, true);
373373

374374
if (
375375
this._contentWormhole &&
376376
this._contentWormhole.getRootNode() instanceof ShadowRoot
377377
) {
378378
const rootElement = this._contentWormhole.getRootNode() as HTMLElement;
379-
rootElement.addEventListener('touchmove', this.touchMoveHandler, true);
379+
rootElement.addEventListener('touchmove', this.touchMoveHandlerBound, true);
380380
}
381381
}
382382

383383
@action
384384
touchMoveHandler(e: TouchEvent): void {
385385
this.touchMoveEvent = e;
386-
document.removeEventListener('touchmove', this.touchMoveHandler, true);
386+
document.removeEventListener('touchmove', this.touchMoveHandlerBound, true);
387387

388388
if (
389389
this._contentWormhole &&
390390
this._contentWormhole.getRootNode() instanceof ShadowRoot
391391
) {
392392
const rootElement = this._contentWormhole.getRootNode() as HTMLElement;
393-
rootElement.removeEventListener('touchmove', this.touchMoveHandler, true);
393+
rootElement.removeEventListener('touchmove', this.touchMoveHandlerBound, true);
394394
}
395395
}
396396

@@ -411,13 +411,17 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
411411

412412
@action
413413
removeGlobalEvents(): void {
414-
window.removeEventListener('resize', this.runloopAwareReposition);
414+
window.removeEventListener('resize', this.runloopAwareRepositionBound);
415415
window.removeEventListener(
416416
'orientationchange',
417-
this.runloopAwareReposition,
417+
this.runloopAwareRepositionBound,
418418
);
419419
}
420420

421+
touchMoveHandlerBound = (e: TouchEvent) => this.touchMoveHandler(e);
422+
runloopAwareRepositionBound = () => this.runloopAwareReposition();
423+
touchStartHandlerBound = () => this.touchStartHandler();
424+
421425
// Methods
422426
addScrollHandling(dropdownElement: Element): void {
423427
if (this.args.preventScroll === true) {
@@ -497,7 +501,7 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
497501
};
498502
} else {
499503
this.addScrollEvents();
500-
this.removeScrollHandling = this.removeScrollEvents;
504+
this.removeScrollHandling = this.removeScrollEvents.bind(this);
501505
}
502506
}
503507

@@ -508,15 +512,15 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
508512
// These two functions wire up scroll handling if `preventScroll` is false.
509513
// These trigger reposition of the dropdown.
510514
addScrollEvents(): void {
511-
window.addEventListener('scroll', this.runloopAwareReposition);
515+
window.addEventListener('scroll', this.runloopAwareRepositionBound);
512516
this.scrollableAncestors.forEach((el) => {
513-
el.addEventListener('scroll', this.runloopAwareReposition);
517+
el.addEventListener('scroll', this.runloopAwareRepositionBound);
514518
});
515519
}
516520
removeScrollEvents(): void {
517-
window.removeEventListener('scroll', this.runloopAwareReposition);
521+
window.removeEventListener('scroll', this.runloopAwareRepositionBound);
518522
this.scrollableAncestors.forEach((el) => {
519-
el.removeEventListener('scroll', this.runloopAwareReposition);
523+
el.removeEventListener('scroll', this.runloopAwareRepositionBound);
520524
});
521525
}
522526
}

ember-basic-dropdown/src/components/basic-dropdown.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ export default class BasicDropdown extends Component<BasicDropdownSignature> {
116116
this.args.dropdownId || `ember-basic-dropdown-content-${this._uid}`;
117117
private _previousDisabled = UNINITIALIZED;
118118
private _actions: DropdownActions = {
119-
open: this.open,
120-
close: this.close,
121-
toggle: this.toggle,
122-
reposition: this.reposition,
123-
registerTriggerElement: this.registerTriggerElement,
124-
registerDropdownElement: this.registerDropdownElement,
119+
open: this.open.bind(this),
120+
close: this.close.bind(this),
121+
toggle: this.toggle.bind(this),
122+
reposition: this.reposition.bind(this),
123+
registerTriggerElement: this.registerTriggerElement.bind(this),
124+
registerDropdownElement: this.registerDropdownElement.bind(this),
125125
getTriggerElement: () => this.triggerElement,
126126
};
127127

ember-basic-dropdown/src/modifiers/basic-dropdown-trigger.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ export default class DropdownTriggerModifier extends Modifier<Signature> {
6363

6464
if (!element.getAttribute('role')) element.setAttribute('role', 'button');
6565

66-
element.addEventListener('click', this.handleMouseEvent);
67-
element.addEventListener('mousedown', this.handleMouseEvent);
68-
element.addEventListener('keydown', this.handleKeyDown);
69-
element.addEventListener('touchstart', this.handleTouchStart, {
66+
element.addEventListener('click', this.handleMouseEventBound);
67+
element.addEventListener('mousedown', this.handleMouseEventBound);
68+
element.addEventListener('keydown', this.handleKeyDownBound);
69+
element.addEventListener('touchstart', this.handleTouchStartBound, {
7070
passive: false,
7171
});
72-
element.addEventListener('touchend', this.handleTouchEnd);
72+
element.addEventListener('touchend', this.handleTouchEndBound);
7373
}
7474

7575
update(
@@ -142,11 +142,11 @@ export default class DropdownTriggerModifier extends Modifier<Signature> {
142142

143143
@action
144144
handleTouchStart(): void {
145-
document.addEventListener('touchmove', this._touchMoveHandler);
145+
document.addEventListener('touchmove', this.touchMoveHandlerBound);
146146
if (this.triggerElement?.getRootNode() instanceof ShadowRoot) {
147147
(this.triggerElement?.getRootNode() as HTMLElement).addEventListener(
148148
'touchmove',
149-
this._touchMoveHandler,
149+
this.touchMoveHandlerBound,
150150
);
151151
}
152152
}
@@ -164,7 +164,7 @@ export default class DropdownTriggerModifier extends Modifier<Signature> {
164164
actions.toggle(e);
165165
}
166166
this.touchMoveEvent = undefined;
167-
document.removeEventListener('touchmove', this._touchMoveHandler);
167+
document.removeEventListener('touchmove', this.touchMoveHandlerBound);
168168
// This next three lines are stolen from hammertime. This prevents the default
169169
// behaviour of the touchend, but synthetically trigger a focus and a (delayed) click
170170
// to simulate natural behaviour.
@@ -207,34 +207,40 @@ export default class DropdownTriggerModifier extends Modifier<Signature> {
207207
@action
208208
_touchMoveHandler(e: TouchEvent): void {
209209
this.touchMoveEvent = e;
210-
document.removeEventListener('touchmove', this._touchMoveHandler);
210+
document.removeEventListener('touchmove', this.touchMoveHandlerBound);
211211

212212
if (this.triggerElement?.getRootNode() instanceof ShadowRoot) {
213213
(this.triggerElement?.getRootNode() as HTMLElement).removeEventListener(
214214
'touchmove',
215-
this._touchMoveHandler,
215+
this.touchMoveHandlerBound,
216216
);
217217
}
218218
}
219+
220+
handleMouseEventBound = (e: MouseEvent) => this.handleMouseEvent(e);
221+
handleKeyDownBound = (e: KeyboardEvent) => this.handleKeyDown(e);
222+
handleTouchStartBound = () => this.handleTouchStart();
223+
handleTouchEndBound = (e: TouchEvent) => this.handleTouchEnd(e);
224+
touchMoveHandlerBound = (e: TouchEvent) => this._touchMoveHandler(e);
219225
}
220226

221227
function cleanup(instance: DropdownTriggerModifier) {
222228
const { triggerElement } = instance;
223229
if (triggerElement) {
224230
if (typeof document !== 'undefined')
225-
document.removeEventListener('touchmove', instance._touchMoveHandler);
231+
document.removeEventListener('touchmove', instance.touchMoveHandlerBound);
226232

227233
if (triggerElement?.getRootNode() instanceof ShadowRoot) {
228234
(triggerElement?.getRootNode() as HTMLElement).removeEventListener(
229235
'touchmove',
230-
instance._touchMoveHandler,
236+
instance.touchMoveHandlerBound,
231237
);
232238
}
233239

234-
triggerElement.removeEventListener('click', instance.handleMouseEvent);
235-
triggerElement.removeEventListener('mousedown', instance.handleMouseEvent);
236-
triggerElement.removeEventListener('keydown', instance.handleKeyDown);
237-
triggerElement.removeEventListener('touchstart', instance.handleTouchStart);
238-
triggerElement.removeEventListener('touchend', instance.handleTouchEnd);
240+
triggerElement.removeEventListener('click', instance.handleMouseEventBound);
241+
triggerElement.removeEventListener('mousedown', instance.handleMouseEventBound);
242+
triggerElement.removeEventListener('keydown', instance.handleKeyDownBound);
243+
triggerElement.removeEventListener('touchstart', instance.handleTouchStartBound);
244+
triggerElement.removeEventListener('touchend', instance.handleTouchEndBound);
239245
}
240246
}

0 commit comments

Comments
 (0)