Permalink
Browse files

Only trigger topic if there are subscribers to it

Fix so that publishing a topic that has no subscribers won't cause error
  • Loading branch information...
1 parent 2e48d3e commit ca8006ca79ea7ee0d7556fa51cfbed1fb2c48586 @phobia phobia committed Feb 13, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 pubsub.js
View
@@ -28,9 +28,11 @@
// with a function signature like: function(a,b,c){ ... }
//
// | $.publish("/some/topic", ["a","b","c"]);
- cache[topic].forEach(function(property){
- property.apply($, args || []);
- });
+ if(typeof cache[topic] === 'object') {
+ cache[topic].forEach(function(property){
+ property.apply($, args || []);
+ });
+ }
};
$.subscribe = function(/* String */topic, /* Function */callback){

0 comments on commit ca8006c

Please sign in to comment.