rad-event-listener
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

Rad Event Listener

minzip size install size dependency count

Please see the full README at https://github.com/JLarky/rad-event-listener

Before:

function handler(this: Document, e: MouseEvent) {
  console.log("mouse moved to", e.x, e.y, this === e.currentTarget);
};

document.addEventListener("mousemove", handler);

const cleanup = () => {
  document.removeEventListener("mousemove", handler);
};

After:

import { on, rad, radEventListener } from "rad-event-listener";

const cleanup = radEventListener(document, "mousemove", function (e) {
  console.log("mouse moved to", e.x, e.y, this === e.currentTarget);
});

Both of examples are written in a type-safe manner that will not allow you to make mistakes. But one of them made you work much more to get types of this and e right as well as made you do more work to remove the listener.

Live examples

Package Sidebar

Install

npm i rad-event-listener

Weekly Downloads

480

Version

0.2.4

License

MIT

Unpacked Size

5.67 kB

Total Files

8

Last publish

Collaborators

  • jlarky