Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
delegate-it
Advanced tools
Lightweight event delegation
This is a fork of the popular delegate
with some improvements:
WeakMap
and Element.closest()
)addEventListener
AbortSignal
If you need IE support, you can keep using delegate
npm install delegate-it
// This module is only offered as a ES Module
import delegate from 'delegate-it';
delegate(document.body, '.btn', 'click', event => {
console.log(event.delegateTarget);
});
delegate('.container', '.btn', 'click', event => {
console.log(event.delegateTarget);
});
delegate(document.querySelectorAll('.container'), '.btn', 'click', event => {
console.log(event.delegateTarget);
});
delegate(document.body, '.btn', 'click', event => {
console.log(event.delegateTarget);
}, true);
// Or equivalent:
delegate(document.body, '.btn', 'click', event => {
console.log(event.delegateTarget);
}, {
capture: true
});
Note: the once
option is currently not supported.
const controller = delegate(document.body, '.btn', 'click', event => {
console.log(event.delegateTarget);
});
controller.abort();
const controller = new AbortController();
delegate(document.body, '.btn', 'click', event => {
console.log(event.delegateTarget);
}, {
signal: controller.signal,
});
controller.abort();
If you're using TypeScript and have event types that are custom, you can override the global GlobalEventHandlersEventMap
interface via declaration merging. e.g. say you have a types/globals.d.ts
file, you can add the following.
interface GlobalEventHandlersEventMap {
'details:toggle': UIEvent;
}
In the file that imports EventType
, you will now be able to set the event type to 'details:toggled'
.
import {EventType} from 'delegate-it';
const someEventType1: EventType = 'details:toggled'; // all good
const someEventType2: EventType = 'click'; // all good
const someEventType3: EventType = 'some-invalid-event-type'; // no good
Latest ✔ | Latest ✔ | Latest ✔ | No ✕ | Latest ✔ | Latest ✔ |
querySelector
/All
wrapper that outputs an Array.DocumentFragment
or one Element
, in a few bytes.FAQs
Lightweight and modern event delegation in the browser
The npm package delegate-it receives a total of 7,056 weekly downloads. As such, delegate-it popularity was classified as popular.
We found that delegate-it demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.