Created
October 2, 2013 10:35
-
-
Save latentflip/6791789 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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