Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/so1ve/lite-emit
A simple, lightweight, and fast event emitter.
https://github.com/so1ve/lite-emit
emit emits emits-events emitter events nodejs pubsub
Last synced: 9 days ago
JSON representation
A simple, lightweight, and fast event emitter.
- Host: GitHub
- URL: https://github.com/so1ve/lite-emit
- Owner: so1ve
- License: mit
- Created: 2022-08-10T03:41:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T19:00:30.000Z (7 months ago)
- Last Synced: 2024-04-14T09:43:37.445Z (7 months ago)
- Topics: emit, emits, emits-events, emitter, events, nodejs, pubsub
- Language: TypeScript
- Homepage:
- Size: 741 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lite-emit
[![NPM version](https://img.shields.io/npm/v/lite-emit?color=a1b858&label=)](https://www.npmjs.com/package/lite-emit)
A simple, lightweight, and fast event emitter.
## Usage
```ts
import { LiteEmit } from "lite-emit";interface Events {
foo: [string];
bar: ["bar", number, symbol];
baz: [42];
}const emitter = new LiteEmit();
function fooListener1(str: string) {
console.log(str);
}function fooListener2(str: string) {
console.log(str);
}function fooListener3(str: string) {
console.log(str);
}// Add listeners
// Chainable
emitter.on("foo", fooListener1);
emitter.on("foo", fooListener2);
emitter.on("foo", fooListener3).emit("foo", "hello");
emitter
.on("baz", (num) => {
console.log(num);
})
.emit("baz", "42");
// 42// Remove a specified listener for a specified event
emitter.off("foo", fooListener1).emit("foo", "hello");
// Output:
// hello
// hello// Remove all listeners for a specified event
emitter.off("foo");
// Output:
//emitter.emit("baz", 42);
// Output:
// 42// Remove all wildcard listeners
emitter.off("*");// Remove all listeners for all events
emitter.off();
```## License
[MIT](./LICENSE) License © 2022 [Ray](https://github.com/so1ve)