-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-component.js
34 lines (30 loc) · 1.01 KB
/
my-component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Component from '@ember/component';
import { action } from '@ember/object';
export default Component.extend({
iconNames: undefined,
init() {
this._super(...arguments);
this.iconNames = ['a', 'b', 'c'];
document.addEventListener('click', this.handleDocumentClick);
},
willDestroy() {
document.removeEventListener('click', this.handleDocumentClick);
},
click() {
// eslint-disable-next-line no-console
console.log(`some action that forces our {{each}} subject to update before
the click event propagates to our document click handler below`);
this.set('iconNames', this.iconNames.slice());
},
handleDocumentClick: action(function(event) {
let eventTargetIsAttachedToDOM = Boolean(event.target.closest('html'));
// eslint-disable-next-line no-console
console.log({
eventTarget: event.target,
eventTargetIsAttachedToDOM,
})
if (!eventTargetIsAttachedToDOM) {
throw new Error('event target no longer attached to the DOM');
}
}),
});