Skip to content

PublisherChannel

Hyomoto edited this page Jun 24, 2021 · 18 revisions
Jump To Go Back Methods Variables

PublisherChannel( )

A simple publisher-subscriber framework. Methods are bound to the PublisherChannel, and called with the supplied parameters when a channel is notified they belong to. These methods are called at the scope they are bound, which means they are run as if they were a part of the subscribing instance. Thus any number of instances can subscribe to a single PublisherChannel, or even the same one multiple times if desired.

var _channel	= new PublisherChannel()

_channel.add( function( _message ) {
  show_debug_message( _message );
}
_channel.notify( "Hello World!" );

Methods

Jump To top add remove notify size

add( method )

Returns: method

Throws: InvalidArgumentType

Name Type Purpose
method func The method to add to the list.

Adds the specified method to the list of listeners. If the provided argument was not a method, InvalidArgumentType will be thrown.


remove( method )

Name Type Purpose
method method The method to remove fromt he list.

Removes the specified listener from the channel.


notify( message )

Name Type Purpose
message mixed The message to pass to the subscribers.

Calls each of the subscriber methods with message as an argument.


size( )

Name Type Purpose
None

Returns the number of subscribers in the channel


Variables

Jump To top
Name Type Initial Purpose
__Subscribers undef [] No description.
Clone this wiki locally