Imagine Alice creates a module for fetching calendar data from a Microsoft Exchange Web Service API. However, she's not very good at UI, and let's the module be used as a library, rather than bind it to UI components.

Along comes Bob. He's an expert in creating traditionally laid out calendar UI's, but thinks Ajax, web-API's and authentication is difficult to work with. He just wants to subscribe to live events from the calendar to keep the UI up to date.

If Alice and Bob add the option to communicate through NanoQueue, they will be able to communicate with eachother's modules, even though they have never talked or met. This means that you can use both of their modules on your page, with minimal setup, and have them communicate messages.

Let's see some code:

// Include on the page in the header, before any modules
	<script src="nanoqueue.js"></script>
	<script src="moduleA.js"></script>
	<script src="moduleB.js"></script>

A module could use it like this:

var ModuleA = function(){
	// Subscribe to the specified topic, supplying the callback
	_Q.subscribeTo("calendar.data.new", this.updateUI);
	// message handler function
	var updateUI = function(data){
		// do some important UI stuff
		document.querySelector("#result").innerText(JSON.stringify(data, null,'\t'));


var ModuleB = function(){
	var doStuff = function(someInput){

		// Do some useful stuff to the input and build an object to share
		// lets pretend we have gotten som data from a calendar service
		var message = {
			data : {
				"bookings": [ someInput ],
			"created" : new Date().toISOString()

		// Publish to the specified topic, supplying the data
		_Q.publishTo("calendar.data.new", message);	

ModuleB.doStuff("Write some code");