add-evt-listener
Advanced tools
Comparing version 0.0.5 to 0.1.0
{ | ||
"name": "add-evt-listener", | ||
"version": "0.0.5", | ||
"description": "convenient addEvtListener utility", | ||
"version": "0.1.0", | ||
"description": "convenient addEventListener utility", | ||
"main": "index.cjs", | ||
"repository": "https://github.com/tranvansang/add-evt-listener", | ||
"author": "Tran Sang <t@sang.jp>", | ||
"author": "Sang Tran <t@sang.jp>", | ||
"license": "MIT", | ||
@@ -21,5 +21,2 @@ "files": [ | ||
}, | ||
"scripts": { | ||
"prepublish": "./compile.sh" | ||
}, | ||
"devDependencies": { | ||
@@ -26,0 +23,0 @@ "typescript": "^5.1.6" |
# add-evt-listener | ||
- Install: `yarn add add-evt-listener`. | ||
- Exported functions: | ||
- Usage | ||
```typescript | ||
import {addEvtListener, addEvtListenerOnce, addEvtListenerSelf, addEvtListenerSelfOnce} from 'add-evt-listener' | ||
``` | ||
```javascript | ||
import addEvtListener from 'add-evt-listener' | ||
// or | ||
const addEvtListener = require('add-evt-listener') | ||
# API | ||
- Parameter: `target`, `name` (event name), `handler`, `option`. | ||
- Specs: call `target.addEventListener(name, handler, option)`. | ||
- Return: a callback function that takes zero argument, used to remove the event listener via `target.removeEventListener`. | ||
const removeEvtListener = addEvtListener(target, event, handler, option) | ||
// equivalent to | ||
target.addEventListener(event, handler, option) | ||
`target.removeEventListener` is called at most once regardless of how many times the returned callback is called. | ||
## Variant | ||
- `Once`: remove the event listener after the first call. | ||
- `Self`: only trigger the event listener when `evt.currentTarget === evt.target` (`evt` is the first parameter in `handler`). | ||
removeEvtListener() | ||
// equivalent to | ||
target.removeEventListener(event, handler, option) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2893
13
19