0.2.4 • Published 11 months ago

rad-event-listener v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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

0.2.4

11 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago