A simple PubSub
- subscribe a function to a channel:
let subscriptionId = kiss.pubsub.subscribe("MY_CHANNEL_NAME", (messageData) => { console.log(messageData) })
- publish a message on a channel:
kiss.pubsub.publish("MY_CHANNEL_NAME", {foo: "bar"})
- unsubscribe a function:
kiss.pubsub.unsubscribe(subscriptionId)
- list all active subscriptions
kiss.pubsub.list()
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 |
The subscribed function
function
# static getCount() → {number}
Return the number of subscriptions.
Mainly used for debugging (useful to track memory leaks).
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 |
# static publish(channel, messageDataopt)
Publish a message on a specific channel
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
channel |
string
|
The channel name |
|
messageData |
object
|
<optional> |
The data published into the channel |
# static subscribe(channel, fn, descriptionopt) → {string}
Subscribe a function to a channel
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 |
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 |