Namespace

pubsub

kiss.pubsub

A simple PubSub

  1. subscribe a function to a channel:
let subscriptionId = kiss.pubsub.subscribe("MY_CHANNEL_NAME", (messageData) => { console.log(messageData) })
  1. publish a message on a channel:
kiss.pubsub.publish("MY_CHANNEL_NAME", {foo: "bar"})
  1. unsubscribe a function:
kiss.pubsub.unsubscribe(subscriptionId)
  1. list all active subscriptions
kiss.pubsub.list()

View Source client/core/modules/pubsub.js, line 28

Methods

# static get(subscriptionId) → {function}

Get a subscription by id.

Mainly used for debug purpose, when you need to check which function is registered in the pubsub.

Parameters:
Name Type Description
subscriptionId string

The id of the subscription to retrieve

View Source client/core/modules/pubsub.js, line 187

The subscribed function

function

# static getCount() → {number}

Return the number of subscriptions.

Mainly used for debugging (useful to track memory leaks).

View Source client/core/modules/pubsub.js, line 170

number

# static list(showFunctionopt)

List all the subscriptions in the console.

Mainly used for debug purpose, when you need an overview of subscriptions.

Parameters:
Name Type Attributes Description
showFunction boolean <optional>

If true, show the subscribed function

View Source client/core/modules/pubsub.js, line 212

# static publish(channel, messageDataopt)

Publish a message on a specific channel + on the global channel, if any

The global channel is the "*" channel, which is a special channel that will be called for all messages. Sometimes, it can be convenient to observe all messages, without subscribing to a specific channel.

Parameters:
Name Type Attributes Description
channel string

The channel name

messageData object <optional>

The data published into the channel

View Source client/core/modules/pubsub.js, line 42

# static publishOnGlobalChannel(messageData)

Publish a message on the global channel (*)

Parameters:
Name Type Description
messageData *

View Source client/core/modules/pubsub.js, line 78

# static subscribe(channel, fn, descriptionopt) → {string}

Subscribe a function to a channel

The global channel is the "*" channel, which is a special channel that will be called for all messages. Sometimes, it can be convenient to observe all messages, without subscribing to a specific channel.

Parameters:
Name Type Attributes Description
channel string

The channel name, or "*" to subscribe to all channels

fn function

The function to subscribe to the channel

description string <optional>

Optional description of the subscription

View Source client/core/modules/pubsub.js, line 107

The subscription id

string

# static subscribeOnce(channel, fn, descriptionopt) → {string}

Subscribe a function to a channel, but unsubscribe it after the first call

Parameters:
Name Type Attributes Description
channel string

The channel name

fn function

The function to subscribe to the channel

description string <optional>

Optional description of the subscription

View Source client/core/modules/pubsub.js, line 129

The subscription id

string

# static unsubscribe(subscriptionId)

Unsubscribe a function from the pubsub

Parameters:
Name Type Description
subscriptionId string

The id of the subscription to remove

View Source client/core/modules/pubsub.js, line 147

Methods