event-target-shim
An implementation of WHATWG EventTarget
interface and WHATWG Event
interface. This implementation supports constructor, passive
, once
, and signal
.
This implementation is designed ...
- Working fine on both browsers and Node.js.
- TypeScript friendly.
💿 Installation
Use npm or a compatible tool.
npm install event-target-shim
📖 Getting started
import { EventTarget, Event } from "event-target-shim";
const myNode = new EventTarget();
myNode.addEventListener(
"hello",
(e) => {
e.preventDefault();
},
{ passive: true }
);
myNode.addEventListener("hello", listener, { once: true });
myNode.dispatchEvent(new Event("hello"));
const ac = new AbortController();
myNode.addEventListener("hello", listener, { signal: ac.signal });
ac.abort();
- For browsers, use a bundler such as Webpack to bundle.
- If you want to support IE11, use
import {} from "event-target-shim/es5"
instead. It's a transpiled code by babel. It depends on @baebl/runtime
(^7.12.0
) package.
- The
AbortController
class was added to the standard on 14 Jul 2017. If you want the shim of that, use abort-controller package.
📚 API Reference
See docs/reference.md.
💥 Migrating to v6
See docs/migrating-to-v6.md.
📰 Changelog
See GitHub releases.
🍻 Contributing
Contributing is welcome ❤️
Please use GitHub issues/PRs.
Development tools
npm install
installs dependencies for development.npm test
runs tests and measures code coverage.npm run watch:mocha
runs tests on each file change.