ab-subscription
v0.0.1
Published
Simple subscription library
Downloads
81
Readme
Subscription
A simple subscription management utility for handling event subscriptions and dispatching in TypeScript.
Features
- Subscribe to events with callback functions.
- Dispatch events to all active subscribers.
- Unsubscribe at any time.
Installation
You can install the package via npm:
npm i ab-subscription
Usage
Import the subscription function and create a subscription instance:
import subscription from "ab-subscription";
const { subscribe, dispatch } = subscription();
// Subscribe to an event
const unsubscribe = subscribe((event) => {
console.log("Received event:", event);
});
// Dispatch an event to all subscribers
dispatch("Hello, Subscribers!");
// Unsubscribe from the event
unsubscribe();