UNPKG

publisher-subscriber-ts

Version:
36 lines (35 loc) 1.45 kB
import { Topic } from './topic'; import { Subscriber } from './subscriber'; import { SubscribeOption } from './publisher.model'; /** * @author Harsh A. Mistry * * Publisher class to publish new topics and emit values */ export declare class Publisher { private static _topicMap; /** * Creates new topic for given topic name * @param {string} topicName Name for topic to be created * * @returns {Topic} New created topic */ static createTopic(topicName: string): Topic; /** * Subscribe to a particular topic by providing option and a callback function. * @param {SubscribeOption} option * @param {Function} callback * @throws {Topic name cannot be empty or null while subscribing} Error if topic name passed is null or empty * @throws {'Cannot find topic with name: ' ${topic_name} '. Please create one and then subscribe.'} If given topic name does not exist * * @returns {Subscriber} */ static subscribeTopic(option: SubscribeOption, callback: (...args: any[]) => void): Subscriber | undefined; /** * Unsubscribe any topic for given subscriber * @param {string} topicName * @throws {'Cannot find topic with name: ' ${topicName}} Thrown when given topic name is not found * @param {Subscriber} subscriber Subscriber of this topic */ static unsubscribeTopic(subscriber: Subscriber): void; }