Created
May 14, 2013 08:41
-
-
Save kavanagh/5574552 to your computer and use it in GitHub Desktop.
Very simple topic subscription.
This file contains 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 a = topic(); | |
a.add(function(){ | |
console.log('a', arguments); | |
}); | |
a.fire('message for a'); // should be "a", ["message for a"] | |
// named topic | |
var b = topic('b'); | |
b.add(function(){ | |
console.log('b', arguments); | |
}); | |
b.fire('message for b'); // should be "b", ["message for b"] | |
var c = topic('b'); | |
console.log('b and c are the same', b === c); | |
c.fire('message for c'); // should be "b", ["message for c"] |
This file contains 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 topic = (function($){ | |
var t = {}; | |
return function(name) { | |
return t[name] = t[name] || $.Callbacks(); | |
} | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment