All files index.js

100% Statements 21/21
94.12% Branches 16/17
100% Functions 4/4
100% Lines 20/20
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 35 36 37 38 39 40 41 42 43 44 45 46    1x       1x         1x 7x   4x     1x 4x   4x         1x 1x 7x 7x   7x   7x 7x   7x       1x   1x 1x 1x    
import {eventListenerOptionsSupported} from './utils';
 
const defaultOptions = {
  passive: true,
  capture: false
};
const supportedPassiveTypes = [
  'scroll', 'wheel',
  'touchstart', 'touchmove', 'touchenter', 'touchend', 'touchleave',
  'mouseout', 'mouseleave', 'mouseup', 'mousedown', 'mousemove', 'mouseenter', 'mousewheel', 'mouseover'
];
const getDefaultPassiveOption = (passive, eventName) => {
  if (passive !== undefined) return passive;
 
  return supportedPassiveTypes.indexOf(eventName) === -1 ? false : defaultOptions.passive;
};
 
const getWritableOptions = (options) => {
  const passiveDescriptor = Object.getOwnPropertyDescriptor(options, 'passive');
    
  return passiveDescriptor && passiveDescriptor.writable !== true && passiveDescriptor.set === undefined
    ? Object.assign({}, options)
    : options;
};
 
const overwriteAddEvent = (superMethod) => {
  EventTarget.prototype.addEventListener = function(type, listener, options) {
    const usesListenerOptions = typeof options === 'object';
    const useCapture = usesListenerOptions ? options.capture : options;
 
    options = usesListenerOptions ? getWritableOptions(options) : {};
 
    options.passive = getDefaultPassiveOption(options.passive, type);
    options.capture = useCapture !== undefined ? useCapture : defaultOptions.capture;
 
    superMethod.call(this, type, listener, options);
  };
};
 
const supportsPassive = eventListenerOptionsSupported();
 
Eif (supportsPassive) {
  const addEvent = EventTarget.prototype.addEventListener;
  overwriteAddEvent(addEvent);
}