1.1.4 • Published 5 months ago

@mwx521/teleport v1.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Teleport

npm version npm downloads

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/teleport

Usage

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.

1.1.1

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.0

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago