The @jamilservices/sb-module-notify
provides a robust solution for managing event-driven notifications. This module encapsulates the functionality required to create, manage, and destroy notifications, ensuring a clean and maintainable interface for event handling.
- Centralized Event Management: Centralizes the creation and management of event listeners, allowing for systematic handling of cross-component communication.
- Simplified API: Offers a simple API to subscribe to events, emit events, and clean up listeners with minimal code.
- Module Integrity: The API is frozen to prevent modifications at runtime, ensuring the reliability and security of the module.
Install this module using pnpm, npm or yarn:
pnpm add @jamilservices/sb-module-notify
npm install @jamilservices/sb-module-notify
yarn add @jamilservices/sb-module-notify
Note
This will add the @jamilservices/sb-module-notify
as a development dependency in your project.
You can use the following CDN links to include the module:
https://cdn.skypack.dev/@jamilservices/sb-module-notify@latest/lib/main.min.js
https://cdn.jsdelivr.net/npm/@jamilservices/sb-module-notify@latest/lib/main.min.js
https://unpkg.com/@jamilservices/sb-module-notify@latest/lib/main.min.js
- from install (pnpm/npm/yarn):
import { NotifyModule } from '@jamilservices/sb-module-notify';
- from cdn:
import { NotifyModule } from 'https://cdn.jsdelivr.net/npm/@jamilservices/sb-module-notify@latest/lib/main.min.js';
const notify = NotifyModule.instance("myEventName");
notify.subscribe({
id: "uniqueListenerId",
fn: data => console.log("Event data:", data)
});
notify.unsubscribe("uniqueListenerId");
notify.emit({ key: "value" });
NotifyModule.destroy();
- Description: Creates/retrieves and returns a new/existing notification instance associated with the specified event name.
- Parameters:
name
: The name of the event channel.
- Description: Cleans up and removes all event listeners created through any instance of the notification module.
Interested in contributing? We welcome your contributions to enhance the backend capabilities of @jamilservices/sb-module-notify
.
Please check our Contribution Guidelines for more details.
@jamilservices/sb-module-notify
is available under the MIT License by @jamilservicos.
- You are free to modify and reuse the code.
- The original license must be included with copies of this software.
- We encourage linking back to this repository if you use a significant portion of the source code.