Home    >    Downloads    >    Publish/subscribe

Publish/subscribe

Publish/subscribe is a jQuery plugin that is used as an event aggregator, effectively enabling developer to write out JavaScript code with low coupling.

Publish-subscribe Downloads & Files: Source Code, Try out a demonstration,

Options

eventName

The name of event

.subscribe("HelloWorld",function(){});

eventHandler

The event handler of the specific event name.

.subscribe("HelloWorld", function(data) {alert("Hello World!");});
			        

constArgs

The argurments of event handler

        $('select').subscribe("HelloWorld",function(data){
	        alert(data + " Hello World!");
        },["Nova"]);
			        

Usage

.subscribe(eventName,eventHandler,constArgs);

Subscribes an object to particular eventName with a handler. When the topic is published, this handler will be executed.

$('select').subscribe(eventName,eventHandler,eventHandlerArgs);

.unsubscribe(eventName,eventHandler);

Unsubscribes the particular event's handler.

$('select').unsubscribe(eventName,eventHandler);
        $('select').unsubscribe("HelloWorld",function(data){
	        alert(data + " Hello World!");
        });
			        

$.publish(eventName,[args]);

publish event

        $.publish£¨"HelloWorld",["Nova"]);
			        

$("selector").publishOnEvent(event,eventName,eventHandler);

publish event when the object event is fired

        $('select').publishOnEvent("click","HelloWorld",function(data){
	        alert(data + " Hello World!");
        });