2.0.0 • Published 7 years ago

addeventlistener v2.0.0

Weekly downloads
7
License
CC0-1.0
Repository
github
Last release
7 years ago

addeventlistener

addEventListener that takes options as an object and returns a function to remove the listener.

install

$ npm install addeventlistener

api

addEventListener(element, eventName, listener, options)

import addEventListener from 'addeventlistener'

const removeEventListener = addEventListener(
  document.body,
  'touchmove',
  e => {},
  { passive: false }
)

once(element, eventName, listener, options)

Listen for the event and stop listening after it has occurred once. You can still use the returned function to stop listening if you want to stop listening before the event has occurred once.

import { once } from 'addeventlistener'

const removeEventListener = once(window, 'click', console.log)

CommonJS

const { default: addEventListener, once } = require('addeventlistener')