Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a second argument to unsubscribe, keeps backwards compatibility

  • Loading branch information...
commit 791381d109db225155bae24682c3749a19743913 1 parent d063273
@fserb fserb authored
Showing with 11 additions and 4 deletions.
  1. +3 −3 minpubsub.src.js
  2. +8 −1 unit-tests.htm
View
6 minpubsub.src.js
@@ -56,7 +56,7 @@
return [topic, callback]; // Array
};
- d.unsubscribe = function(/* Array */ handle){
+ d.unsubscribe = function(/* Array */ handle, /* Function? */ callback){
// summary:
// Disconnect a subscribed function for a topic.
// handle: Array
@@ -65,8 +65,8 @@
// var handle = subscribe("/some/topic", function(){});
// unsubscribe(handle);
- var subs = cache[handle[0]],
- callback = handle[1],
+ var subs = cache[callback ? handle : handle[0]],
+ callback = callback || handle[1],
len = subs ? subs.length : 0;
while(len--){
View
9 unit-tests.htm
@@ -93,6 +93,13 @@
window.unsubscribe(["/some/topic", this.func]);
Assert.areNotEqual(this.func, c_["/some/topic"][0]);
+ },
+ testRemoveSubTwoArgs : function () {
+ var Assert = Y.Assert;
+
+ window.unsubscribe("/some/topic", this.func);
+
+ Assert.areNotEqual(this.func, c_["/some/topic"][0]);
}
});
@@ -111,4 +118,4 @@
Y.Test.Runner.run();
});
-</script>
+</script>

0 comments on commit 791381d

Please sign in to comment.
Something went wrong with that request. Please try again.