perf: remove passive event polyfill (#9590)

This commit is contained in:
neverland
2021-09-29 17:36:50 +08:00
committed by GitHub
parent 7aba794d80
commit ec5067ce7d
3 changed files with 7 additions and 58 deletions

View File

@@ -135,35 +135,12 @@ function throttle(action, delay) {
};
}
function testSupportsPassive() {
if (!inBrowser) return;
let support = false;
try {
const opts = Object.defineProperty({}, 'passive', {
// eslint-disable-next-line getter-return
get() {
support = true;
},
});
window.addEventListener('test', null, opts);
} catch (e) {
//
}
return support;
}
const supportsPassive = testSupportsPassive();
const _ = {
on(el, type, func, capture = false) {
if (supportsPassive) {
el.addEventListener(type, func, {
capture,
passive: true,
});
} else {
el.addEventListener(type, func, capture);
}
el.addEventListener(type, func, {
capture,
passive: true,
});
},
off(el, type, func, capture = false) {
el.removeEventListener(type, func, capture);