Getting Started

Make sure you grab the lastest copy of Radio.js and include it in your project to get started.

Some basic samples to get the idea.

//create topic called changeTabEvent and subscribe myFunction

//publish to the topic changeTabEvent

//unsubscribe myFunction from the topic changeTabEvent

//do all of the above in one line via chaining


Every radio call starts with the radio() method which accepts a string to set the current topic.

//creates and selects the topic to changeTabEvent


Add subscribers to a topic.

//subscribe callback
//subscribe callback with context

You can subscribe multiple callbacks at once.

//subscribe three callbacks at once
radio('changeTabEvent').subscribe(callback, callback2, [callback3.init, callback3]);

//subscribe it via chaining if you want
radio('changeTabEvent').subscribe(callback).subscribe(callback2).subscribe([callback3.init, callback3]);

Callbacks with context

With Radio you can set the context of 'this' when your callback is invoked by adding your callback as an array with context. This is particularly useful if you are namespacing your project under one global object.

radio('changeTabEvent').subscribe([callback, context]);

Example that demonstrates why you may want to do this.

//your global namespaced application object
var myApp = {
	init: function() {
	run: function() {
		//do something

//first subscribe it without setting context
//this will fail because 'this' is set to the window object

//subscribe it with context. 
//this will work because value of 'this' is set to myApp
radio('changeTabEvent').subscribe([myApp.init, myApp]).broadcast();


Publish a message to all subscribers in a selected topic. All parameters get passed to the subscribers.

radio('changeTabEvent').subscribe(function(data1, data2) {
	//do something with data1 and data2
radio('changeTabEvent').broadcast(data1, data2);


Remove subscribers from a topic.

//first subscribe a subscriber
//now unsubscribe it

Remove multiples callback at once.

//unsubscribe multiple callbacks at once
radio('changeTabEvent').unsubscribe(callback1, callback2, callback3);

Ender Integration

Radio support ender and provides an ender bridge. If you are using ender to consume Radio.js, just use the radio object like:

More samples can be found in the integration tests (thank you to rvagg).