Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neosiae/run-event-handler-once
Run an event handler only once
https://github.com/neosiae/run-event-handler-once
Last synced: 24 days ago
JSON representation
Run an event handler only once
- Host: GitHub
- URL: https://github.com/neosiae/run-event-handler-once
- Owner: neosiae
- License: mit
- Created: 2018-06-23T20:44:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T20:28:55.000Z (almost 2 years ago)
- Last Synced: 2023-08-24T06:47:24.368Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 152 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# run-event-handler-once
![npm](https://img.shields.io/npm/v/run-event-handler-once.svg?style=flat-square) ![Travis (.com) branch](https://img.shields.io/travis/com/neosiae/run-event-handler-once/master.svg?style=flat-square) ![npm](https://img.shields.io/npm/dw/run-event-handler-once.svg?style=flat-square) ![npm bundle size](https://img.shields.io/bundlephobia/min/run-event-handler-once.svg?style=flat-square) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
Register an event handler to a desired target and ensure that the event handler is executed only once.
## Installation
Install `run-event-handler-once` using npm:
> npm install --save run-event-handler-once
Or via yarn:
> yarn add run-event-handler-once
## Usage
```javascript
const runEventHandlerOnce = require('run-event-handler-once')const button = document.querySelector('button')
runEventHandlerOnce(button, 'click', function() {
console.log('Hello!')
})
```## API
### runEventHandlerOnce(target, type, listener, [options])
#### target
Type: `EventTarget`
Register an event handler to a desired target.
#### type
Type: `string`
The event type.
#### listener
Type: `function`
An event handler which receives a notification when an event of the specified type occurs.
#### options (Optional)
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`## License
MIT