Luminex is a lightweight, type-safe event emitter library that seamlessly works in both browser and Node.js environments.
- 🌐 Cross-platform: Works in both browser and Node.js environments.
- 🧪 Type-safe: Utilizes TypeScript to ensure type safety for your events.
- 🚀 Simple API: Offers intuitive methods for common event emitter actions.
Install Luminex using npm:
npm install luminex
import { createLuminex } from "luminex";
type Events = {
SHOW: { message: string };
};
// Create an instance of Luminex using the createLuminex function
const luminex = createLuminex<Events>();
// Subscribe to an event
// "Hello Luminex"
const ray = luminex.on("SHOW", (data) => {
console.log(data.body);
});
// Emit an event
luminex.emit("SHOW", {
message: "Hello Luminex",
});
Method | Arguments | Description |
---|---|---|
on |
type: string , handler: function |
Binds the handler function to the specified type event. |
once |
type: string , handler: function |
Binds the handler function to the specified type event and unbinds it after one execution. |
off |
`type: instance of event binder | Unbinds the handler function from the specified type event |
emit |
type: string , ...data arguments |
Calls all handler functions bound to the specified type event. It passes all ...data arguments to those handlers. |
reset |
Removes all events of any and all types, including * . |
This project is licensed under the MIT License.