(Just so everyone else knows, Comet Desktop on Google code is v1, and this version (v2) is on github.)
http://github.com/xantus/comet-desktop/blob/master/public/desktop/lib/Sprocket/PubSub.js
Observable is augmented to include the publish and subscribe methods, so anything that is a subclass of observable can pubsub.
For instance:
win = new Ext.Window({
....
});
win.subscribe( '/foo/bar', function( ev, channel ) {
....
}, win );
win.publish( '/foo/bar', { test: 'hello world' } );
Channels are / separated, and should not include a trailing slash.
If there are two subscribers, one on /foo and the other on /foo/bar. When an event is published to /foo/bar, it is delivered to the /foo/bar listener, then the /foo listener.
The 2nd param will always contain the actual channel published to (/foo/bar)
Now, this pubsub is client side only, but it does allow you to tie it
to a server side pubsub by just republishing events received via ajax.
// a more complex example might queue the events, and use a delayed task
var app = new Ext.util.Observable();
app.subscribe( '/server', function( ev, channel ) {
Ext.Ajax.request( ... );
});
I will have a more complex example using xmpp pubsub when I release the jabber/xmpp client.