Skip to content

Instantly share code, notes, and snippets.

@latentflip
Created October 2, 2013 10:35
Show Gist options
  • Save latentflip/6791789 to your computer and use it in GitHub Desktop.
Save latentflip/6791789 to your computer and use it in GitHub Desktop.
var Emitter = require('wildemitter')
var Hub = function() {
this.channels = {};
}
Hub.prototype.channel = function(channel) {
if (!this.channels[channel])
this.channels[channel] = new Emitter;
return this.channels[channel];
}
module.exports = Hub;
//Test
hub = new Hub();
hub.channel('Channel A').on('foo', function() { console.log('foo on a') });
hub.channel('Channel B').on('foo', function() { console.log('foo on b') });
hub.channel('Channel A').emit('foo') //=> foo on a
hub.channel('Channel B').emit('foo') //=> foo on a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment