zpubsub

  • Version 4.0.0
  • Published
  • No dependencies
  • ISC license

Install

npm i zpubsub
yarn add zpubsub
pnpm add zpubsub

Overview

A javascript implementation of a publish/subscribe pattern.

Index

Classes

class ZPubSub

class ZPubSub implements IZPubSub {}
  • Represents an implementation of the IZPubSub contract.

    {ZPubSub}

constructor

constructor();
  • Initializes a new instance of this object.

method deregister

deregister: (topic: string) => void;
  • Removes the convinence methods created by register.

    Parameter topic

    The topic to deregister.

method publish

publish: (topic: string, ...args: any[]) => any[];
  • Publishes an event.

    The argument list beyond the message is passed through.

    Parameter topic

    This is the string message that represents the event id.

    Parameter args

    The optional arguments to the callback.

    Returns

    {Array} The list of return values. This list can contain undefined and null values. If there are no callbacks, then you will receive an empty array. If you need just the first value of the array, use yell instead.

method register

register: (topic: string) => void;
  • Registers a series of method objects on the service for the given topic.

    This method creates convinence methods for a given topic name.

    You will get the following methods on this service by calling this function: 1. publish{topic}(args) => shortcut to publish(topic, args); 2. subscribe{topic}(owner, callback) => shortcut to subscribe(topic, owner, callback); 3. unsubscribe{topic}(owner, callback) => shortcut to unsubscribe(topic, owner, callback);

    It's good practice to make sure that the topic name is javascript friendly.

    Parameter topic

    The sur name of the convinence function.

method subscribe

subscribe: (
topic: string,
owner: any,
callback: (...args: any[]) => any
) => ZPubSubEventObject;
  • Subscribes to an event.

    Parameter topic

    The id of the event to subscribe to.

    Parameter owner

    The object that owns the subscription.

    Parameter callback

    The callback to invoke when the event is raised. This callback will be invoked with 3 arguments. The first is the data that gets passed to the publish method, and the 2nd is the owner of the message callback, and the 3rd argument is the message itself..

    {Object} This method returns an object that contains two properties: 1. owner: The passed owner object. 2. callback: The callback that will be invoked when msg is published.

method unsubscribe

unsubscribe: (
topic: string,
owner: any,
callback: (...args: any[]) => any
) => boolean;
  • Removes a subscription from the callback list.

    Parameter topic

    The id of the message to remove.

    Parameter owner

    The object that owns the subscription.

    Parameter callback

    The callback that was registered in the subscribe method.

    Returns

    {Boolean} True if the subscription list was modified, false otherwise.

method unsubscribeAll

unsubscribeAll: (owner: any) => boolean;
  • Removes all subscriptions from an owner.

    Parameter owner

    The object to remove all subscriptions for.

    Returns

    {boolean} True if the subscription list was modified, false otherwise.

method yell

yell: (topic: string, ...args: any[]) => any;
  • Publishes the message and arguments and returns the first defined response, if any.

    Parameter topic

    The message to publish.

    {Object} The first defined response to the publish message. Returns null if nobody responds.

class ZPubSubEventObject

class ZPubSubEventObject {}
  • Represents an implementation of the IZPubSubEventObject.

    {ZPubSubEventObject}

constructor

constructor(owner: any, callback: () => any);
  • Initializes a new instance of this object.

    Parameter owner

    The owner of the event.

    Parameter callback

    The callback for when the event is invoked.

property callback

callback: () => any;

    property owner

    owner: any;

      Interfaces

      interface IZPubSub

      interface IZPubSub {}
      • Represents an object that implements a messaging platform.

        This object is an object that encapsulates 3 different possible patterns: 1. Request/Receive 2. Event Aggregation 3. Command

        Unlike other publish/subscribe implementations, this one returns an array of responses from its publish method. This allows subscribers to give information about the event or command that was received.

      method deregister

      deregister: (topic: string) => void;
      • Removes the convinence methods created by register.

        Parameter topic

        The topic to deregister.

      method publish

      publish: (topic: string, ...args: any[]) => any[];
      • Publishes an event.

        The argument list beyond the message is passed through.

        Parameter topic

        This is the string message that represents the event id.

        Parameter args

        The optional arguments to the callback.

        Returns

        {Array} The list of return values. This list can contain undefined and null values. If there are no callbacks, then you will receive an empty array. If you need just the first value of the array, use yell instead.

      method register

      register: (topic: string) => void;
      • Registers a series of method objects on the service for the given topic.

        This method creates convinence methods for a given topic name.

        You will get the following methods on this service by calling this function: 1. publish{topic}(args) => shortcut to publish(topic, args); 2. subscribe{topic}(owner, callback) => shortcut to subscribe(topic, owner, callback); 3. unsubscribe{topic}(owner, callback) => shortcut to unsubscribe(topic, owner, callback);

        It's good practice to make sure that the topic name is javascript friendly.

        Parameter topic

        The sur name of the convinence function.

      method subscribe

      subscribe: (
      topic: string,
      owner: any,
      callback: (...args: any[]) => any
      ) => ZPubSubEventObject;
      • Subscribes to an event.

        Parameter topic

        The id of the event to subscribe to.

        Parameter owner

        The object that owns the subscription.

        Parameter callback

        The callback to invoke when the event is raised. This callback will be invoked with 3 arguments. The first is the data that gets passed to the publish method, and the 2nd is the owner of the message callback, and the 3rd argument is the message itself..

        {ZPubSubEventObject} This method returns an object that contains two properties: 1. owner: The passed owner object. 2. callback: The callback that will be invoked when msg is published.

      method unsubscribe

      unsubscribe: (
      topic: string,
      owner: any,
      callback: (...args: any[]) => any
      ) => boolean;
      • Removes a subscription from the callback list.

        Parameter topic

        The id of the message to remove.

        Parameter owner

        The object that owns the subscription.

        Parameter callback

        The callback that was registered in the subscribe method.

        Returns

        {Boolean} True if the subscription list was modified, false otherwise.

      method unsubscribeAll

      unsubscribeAll: (owner: any) => boolean;
      • Removes all subscriptions from an owner.

        Parameter owner

        The object to remove all subscriptions for.

        Returns

        {boolean} True if the subscription list was modified, false otherwise.

      method yell

      yell: (topic: string, ...args: any[]) => any;
      • Publishes the message and arguments and returns the first defined response, if any.

        Parameter topic

        The message to publish.

        {Object} The first defined response to the publish message. Returns null if nobody responds.

      Package Files (3)

      Dependencies (0)

      No dependencies.

      Dev Dependencies (18)

      Peer Dependencies (0)

      No peer dependencies.

      Badge

      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/zpubsub.

      • Markdown
        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/zpubsub)
      • HTML
        <a href="https://www.jsdocs.io/package/zpubsub"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>