-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from janczizikow/feat/passive-event-listeners
feat: support passive event listeners
- Loading branch information
Showing
2 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Used to detect browser support for adding an event listener with options | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners | ||
* @returns Boolean | ||
*/ | ||
export default function supportsPassiveEvents () { | ||
let passiveSupported = false | ||
|
||
try { | ||
const options = { | ||
get passive () { | ||
// This function will be called when the browser | ||
// attempts to access the passive property. | ||
passiveSupported = true | ||
return false | ||
}, | ||
} | ||
|
||
window.addEventListener('test', null, options) | ||
window.removeEventListener('test', null, options) | ||
} catch (err) { | ||
passiveSupported = false | ||
} | ||
|
||
return passiveSupported | ||
} |