@jay-js/system
Version:
A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.
40 lines • 1.12 kB
JavaScript
/**
* Subscriber manager for the state system
* Isolates the logic of managing the current subscriber and avoids using global variables
*/
class SubscriberManager {
constructor() {
// The current active subscriber
this._current = null;
}
/**
* Sets the current subscriber
* @param subscriber Function to be set as the current subscriber
*/
setSubscriber(subscriber) {
this._current = subscriber;
}
/**
* Gets the current subscriber
* @returns The current subscriber or null if none exists
*/
getSubscriber() {
return this._current;
}
/**
* Checks if there is an active subscriber
* @returns true if there is an active subscriber, false otherwise
*/
hasSubscriber() {
return this._current !== null;
}
/**
* Clears the current subscriber
*/
clearSubscriber() {
this._current = null;
}
}
// Exports a single instance of the manager to be shared across the application
export const subscriberManager = new SubscriberManager();
//# sourceMappingURL=subscriber.js.map