notifijs
v2.0.2
Published
A lightweight and generic Observer pattern implementation in JavaScript using JSDoc type annotations. Ideal for decoupling logic and managing subscriptions to changes in your app.
Readme
NotifiJs
A strongly-typed, lightweight, and zero-dependency Observer Pattern implementation in TypeScript — ideal for decoupling logic and managing event subscriptions in a reactive way.
Features
- ✅ Fully typed with TypeScript generics
- ✅ Extremely lightweight (no dependencies)
- ✅ Observer pattern compliant
- ✅ Safe and isolated notifications
- ✅ Modern and minimal API
Installation
npm install notifijsOr with Yarn:
yarn add notifijsUsage
import { Subject } from 'notifijs';
const counter = new Subject<number>();
const logger = (value: number) => {
console.log(`Value changed to ${value}`);
};
counter.subscribe(logger);
counter.notify(1); // Console: Value changed to 1
counter.notify(2); // Console: Value changed to 2
counter.unsubscribe(logger);
counter.notify(3); // No outputAPI Reference
new Subject<T>()
Creates a new Subject instance for a given data type T.
.subscribe(observer: (value: T) => void): void
Adds an observer to the subscription list.
.unsubscribe(observer: (value: T) => void): void
Removes an observer.
.notify(value: T): void
Notifies all observers with the provided value. Each observer is executed independently with error isolation.
.clear(): void
Removes all observers.
.count(): number
Returns the number of subscribed observers.
Use Cases
- Reactivity in UI frameworks
- Logging and analytics hooks
- Pub/Sub for services or internal modules
- Decoupling side-effects from main logic
- Custom state management
Development
git clone https://github.com/MendoncaGabriel/Notifi-Js.git
cd Notifi-Js
npm install
npm run buildLinks
👨💻 Author
Gabriel Mendonça Full-stack Developer | TypeScript Lover LinkedIn • GitHub
📝 License
This project is licensed under the MIT License.
