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
If you need IE support, you can keep using delegate
npm install delegate-it
const delegate = require('delegate-it');
import delegate from 'delegate-it';
document
)delegate('.btn', 'click', event => {
console.log(event.delegateTarget);
});
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);
});
const delegation = delegate(document.body, '.btn', 'click', event => {
console.log(event.delegateTarget);
});
delegation.destroy();
Note: selectors are always treated as multiple elements, even if one or none are matched. delegate()
will return an array.
const delegations = delegate('.container', '.btn', 'click', event => {
console.log(event.delegateTarget);
});
delegations.forEach(function (delegation) {
delegation.destroy();
});
If you're using TypeScript and have event types that are custom, you can override the EventType
via declaration merging. e.g. say you have a types/globals.d.ts
file, you can add the following.
declare module "delegate-it" {
// Custom event types used in RGH
export type EventType = keyof GlobalEventHandlersEventMap | 'details:toggled';
}
In the file that import EventType
, you will now be able to set an 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 ✔ |
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.