Class HS.Controller.PubSub
PubSub
Defined in: controller.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Global implementation of PubSub methods used to synchronize states and execute the actions based on events.
|
Field Attributes | Field Name and Description |
---|---|
<inner> <static> |
HS.Controller.PubSub.channels
An object containing string: object pairs based on channel names and their respective data.
|
<inner> <static> |
HS.Controller.PubSub.channelsList
An array containing the names of all the channels create and sub-channel byproducts
|
Method Attributes | Method Name and Description |
---|---|
<inner> <static> |
HS.Controller.PubSub.$statics.async(fn, data)
this function is used to execute a function asynchronously via setTimeout 0
|
<inner> <static> |
HS.Controller.PubSub.$statics.hasSubscribers(channel)
this function is used determine if a pubsub channel has subscribers at this time.
|
<inner> <static> |
HS.Controller.PubSub.createChannel(channel)
creates a new channel as well as any sub-channels
|
<inner> <static> |
HS.Controller.PubSub.deliver(channel, data)
executes the channels subscribers callbacks with a new set of data but
does not execute the sub-channels
|
<inner> <static> |
HS.Controller.PubSub.publish(channel, data)
executes the channels subscribers callbacks with a new set of data but
does execute the sub-channels which is how it differs from deliver which is
focused on a single channel
|
<inner> <static> |
HS.Controller.PubSub.subscribe(channel, cb)
subscribes to and potentially creates a channel while doing so.
|
<inner> <static> |
HS.Controller.PubSub.unsubscribe(channel, id)
subscribes to and potentially creates a channel while doing so.
|
Class Detail
HS.Controller.PubSub()
Global implementation of PubSub methods used to synchronize states and execute the actions based on events.
- Requires:
- HS.Utils.Controller
- Class
- HS.Classes.Channels
Field Detail
{Function}
async
<inner> <static>
HS.Controller.PubSub.channels
An object containing string: object pairs based on channel names and their respective data.
{Object}
channels
<inner> <static>
HS.Controller.PubSub.channelsList
An array containing the names of all the channels create and sub-channel byproducts
{String[]}
channelsList
{Function}
hasSubscribers
Method Detail
<inner> <static>
HS.Controller.PubSub.$statics.async(fn, data)
this function is used to execute a function asynchronously via setTimeout 0
HS.Controller.PubSub.async(function() { console.log('doing stuff here'); });
- Parameters:
- {Function} fn
- Required - the function to be executed by the setTimeout
- {Object} data
- Optional - the data for fn if it is needed
<inner> <static>
HS.Controller.PubSub.$statics.hasSubscribers(channel)
this function is used determine if a pubsub channel has subscribers at this time.
var IsEscapeSubscribed = HS.Controller.PubSub.hasSubscribers("User:Keyboard:Keydown:EscapeKey");
- Parameters:
- {Function} channel
- Required - the name of the channel to get subscriber info from
<inner> <static>
{HS.Controller.PubSub}
HS.Controller.PubSub.createChannel(channel)
creates a new channel as well as any sub-channels
HS.Controller.PubSub.createChannel("User:Event:Hover:Title") .createChannel("User:Event:Click:Plugin")
- Parameters:
- {String} channel
- The name of the channel
- Returns:
- {HS.Controller.PubSub} Returns itself so methods can be chained
- Requires:
- HS.Classes.Channel
<inner> <static>
{HS.Controller.PubSub}
HS.Controller.PubSub.deliver(channel, data)
executes the channels subscribers callbacks with a new set of data but
does not execute the sub-channels
HS.Controller.PubSub.deliver("User:Event:Click", { scores: [6,5,97,32,68,43,58,64,98,86], IsActive: false })
- Parameters:
- {String} channel
- The name of the channel
- {Object} data
- used to execute a callback for this channel
- Returns:
- {HS.Controller.PubSub} Returns itself so methods can be chained
<inner> <static>
{HS.Controller.PubSub}
HS.Controller.PubSub.publish(channel, data)
executes the channels subscribers callbacks with a new set of data but
does execute the sub-channels which is how it differs from deliver which is
focused on a single channel
HS.Controller.PubSub.deliver("User:Event:Click", { scores: [6,5,97,32,68,43,58,64,98,86], IsActive: false })
- Parameters:
- {String} channel
- The name of the channel
- {Object} data
- used to execute a callback for this channel
- Returns:
- {HS.Controller.PubSub} Returns itself so methods can be chained
<inner> <static>
{Number|Null}
HS.Controller.PubSub.subscribe(channel, cb)
subscribes to and potentially creates a channel while doing so. The callback will be executes when
the channel is published or delivered to
HS.Controller.PubSub.subscribe("User:Event:Click", callbackFunction)
- Parameters:
- {String} channel
- The name of the channel
- {Function} cb
- Callback function executed when the channel is published to.
- Returns:
- {Number|Null} Returns the subscription's id so it can be un-subscribed using this number in the future.
- Requires:
- HS.Utils.Controller.asteriskEnd
<inner> <static>
{HS.Controller.PubSub}
HS.Controller.PubSub.unsubscribe(channel, id)
subscribes to and potentially creates a channel while doing so. The callback will be executes when
the channel is published or delivered to
HS.Controller.PubSub.unsubscribe("User:Event:Click", channelId)
- Parameters:
- {String} channel
- The name of the channel
- {Number} id
- The id of the subscribed function to help find it in the subscribers array..
- Returns:
- {HS.Controller.PubSub} Returns itself so methods can be chained