@omnia/fx
Version:
Provide Omnia Fx typings and tooling for clientside Omnia development.
49 lines (48 loc) • 1.57 kB
TypeScript
import { Topic, TopicSettings } from "../../models";
/**
* A message bus where messages can be published and subscribed to based on a path
* @class MessageBus
*/
export declare class MessageBus {
private static _subscribers;
private static _subscriptionConfigs;
/**
* Publishes a message on the topic
*/
static publish<T>(topic: Topic<T>, obj: T): void;
/**
* Clears the message cache for the topic
*/
static clearCache<T>(topic: Topic<T>): number;
/**
* Subscribes to the specified Topic and triggers function when a message is published
*/
static subscribe<T>(topic: Topic<T>, fn: (obj: T) => void): void;
/**
* Unsubscribes from the specified Topic
*/
static unsubscribe<T>(topic: Topic<T>, fn: (obj: T) => void): void;
/**
* Creates a topic that messages can be published to, if topic already exists it will throw exception
*/
static createTopic<T>(topic: Topic<T>, settings?: TopicSettings): void;
/**
* Creates a topic if it dosent exists, if it already exists it will ignore and continue without exception
* @param topic
* @param settings
* @returns true/false created
*/
static ensureTopic<T>(topic: Topic<T>, settings?: TopicSettings): boolean;
/**
* Returns true if the topic exists already
*/
static topicExists<T>(topic: Topic<T>): boolean;
/**
* Builds the full path
*/
private static buildTopicPath;
/**
* Ensures the subscribers array on the path
*/
private static ensureSubscribers;
}