run-event-handler-once
Version:
Run an event handler only once
63 lines (34 loc) • 1.67 kB
Markdown
    [](https://github.com/prettier/prettier)
Register an event handler to a desired target and ensure that the event handler is executed only once.
Install `run-event-handler-once` using npm:
> npm install --save run-event-handler-once
Or via yarn:
> yarn add run-event-handler-once
```javascript
const runEventHandlerOnce = require('run-event-handler-once')
const button = document.querySelector('button')
runEventHandlerOnce(button, 'click', function() {
console.log('Hello!')
})
```
Type: `EventTarget`
Register an event handler to a desired target.
Type: `string`
The event type.
Type: `function`
An event handler which receives a notification when an event of the specified type occurs.
Type: `object`
An options object that specifies characteristics about the event listener. The available options are:
- **`add`** - An options object that will be passed to `addEventListener`
- **`remove`** - An options object that will be passed to `removeEventListener`
MIT