@okikio/emitter
A small Event Emitter written in typescript with performance and ease of use in mind, it weighs ~834 B (minified and gzipped).
Table of Contents
Installation
You can install @okikio/emitter from npm via npm i @okikio/emitter
, pnpm i @okikio/emitter
or yarn add @okikio/emitter
.
You can use @okikio/emitter
on the web via:
Once installed it can be used like this:
import { EventEmitter } from "@okikio/emitter";
import { EventEmitter } from "https://unpkg.com/@okikio/emitter";
import { EventEmitter } from "https://cdn.jsdelivr.net/npm/@okikio/emitter";
import { EventEmitter } from "https://cdn.skypack.dev/@okikio/emitter";
<script src="https://unpkg.com/@okikio/emitter/lib/api.js"></script>
const { EventEmitter } = window.emitter;
Getting started
The EventEmitter
class is what runs the show for the @okikio/emitter
library. To use it properly you need to create a new instance of EventEmitter
, the instance of EventEmitter
is what allows for event emitting, and listening.
EventEmitter
allows for an easy way to manage events. It inherits properties/methods from @okikio/manager.
const emitter = new EventEmitter();
emitter.on("new-event", () => {
console.log("A new event occured");
});
setTimeout(() => {
emitter.emit("new-event");
}, 3000);
Read through the API guide to learn more.
Browser & Node Support
Chrome | Edge | Firefox | IE |
---|
> 38 | > 12 | > 13 | > 11 |
Learn about polyfilling, bundling, and more in the platform support guide.
Contributing
If there is something I missed, a mistake, or a feature you would like added please create an issue or a pull request on the beta
branch and I'll try to get to it.
You can try out @okikio/emitter
using Gitpod:
Read through the contributing documentation for detailed guides.