-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventOptions.js
32 lines (26 loc) · 977 Bytes
/
EventOptions.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
class EventOptions {
constructor(options = {}) {
['capture', 'once', 'passive'].forEach(option => {
this[option] = !!options[option];
});
}
shouldHandle(e, captureRound, target, listener) {
if (captureRound !== this.capture) return false;
if (captureRound && e.eventPhase !== 1) return false;
if (e.eventPhase === 2 && event.target !== target) return false;
if (e.eventPhase === 3 && event.target === target) return false;
if (this.once) target.removeEventListener(event.type, listener, this);
return true;
}
equal(options) {
return ['capture', 'once', 'passive'].every(option => {
return this[option] === !!options[option];
});
}
like(options) {
return ['capture', 'passive'].every(option => {
return this[option] === !!options[option];
});
}
}
export default EventOptions;