Skip to content

v6.0.0

Compare
Choose a tag to compare
@mysticatea mysticatea released this 07 Jan 09:25
· 127 commits to master since this release
487b9f7

This package has been rewritten with TypeScript.

💥 Breaking Changes

API has some breaking changes.
See Migration Guide for details.

✨ New Features

Event class is available

Previously, this package had not exported Event class as prefers using the native Event class. Since this version, this package exports it.

import { EventTarget, Event } from "event-target-shim";

const target = new EventTarget();
target.dispatchEvent(new Event("foo"));

signal option on EventTarget.prototype.addEventListener is available

It's a new feature that was added to the standard recently: whatwg/dom#919

import { EventTarget, Event } from "event-target-shim";
import { AbortController } from "abort-controller";

const target = new EventTarget();
const ac = new AbortController();

target.addEventListener("foo", listener, { signal: ac.signal });

// Remove the listener
ac.abort();

■ Customizing error/warning handling

Since this version, if a listener threw an exception, it causes the uncaughtException event on Node.js or the error event on window. Also, if an operation was ignored silently, it prints warnings with console.warn.

You can customize this behavior.

import { setErrorHandler, setWarningHandler } from "event-target-shim";

setErrorHandler((error) => {
  // Do something.
});
setWarningHandler((warning) => {
  // Do something.
});