1.1.4 • Published 2 years ago
@mwx521/teleport v1.1.4
Teleport
Teleport is a lightweight and flexible event handling library for TypeScript, inspired by RxJS. It allows you to manage and communicate events in your application through a singleton pattern. This pattern ensures that there is a single instance of the event manager, making it easy to coordinate and handle events across different parts of your codebase.
Features
- Singleton Pattern: Enforces a singleton pattern to provide a single, centralized instance for managing events.
- Event Queues: Supports the queuing of event handlers, allowing you to add handlers even before the corresponding events are created.
- Event Emission: Easily emit events with associated data and optional callback functions.
- Event Handling: Register handlers for specific events, making it straightforward to respond to different scenarios in your application.
- Cleanup: Provides methods to remove specific event handlers, clear all handlers, and reset the entire event manager.
Installation
Install the Teleport library using npm:
npm install @mwx521/teleportUsage
Importing
import { TeleportSingleton } from '@mwx521/teleport';Getting or Creating the Singleton Instance
const teleport = TeleportSingleton.getInstantce();Emitting an Event
teleport.emit('eventName', eventData, () => {
    // Optional callback function
    console.log('Event emitted successfully!');
});Receiving and Handling an Event
teleport.receive('eventName', (data) => {
    // Handle the event data
    console.log('Event data:', data);
});Removing a Specific Event Handler
teleport.removeHandle('eventName');Removing All Event Handlers
teleport.removeAllHandlers();Clearing the Event Manager
teleport.clear();Contribution
Contributions are welcome! Feel free to open issues, submit pull requests, or provide suggestions to improve the Teleport library.
License
This project is licensed under the MIT License - see the LICENSE file for details.