Opened 13 years ago

Closed 12 years ago

#2071 closed enhancement (fixed)

Add useful return values to dojo.event.topic.subscribe & unsubscribe

Reported by: Patrick Corcoran <dojo-contributors@…> Owned by: alex
Priority: high Milestone: 0.9
Component: Events Version: 0.4
Keywords: Cc:
Blocked By: Blocking:

Description

dojo.event.topic.subscribe returns undefined. It would be more useful if it returned a reference to the MethodJoinPoint? being created, so that at any time

var topicSub = dojo.event.topic.subscribe(...); topicSub.disconnect();

could be called to disconnect it.

Here's the patch required to make this change:

Index: topic.js =================================================================== --- topic.js (revision 6769) +++ topic.js (working copy) @@ -44,7 +44,7 @@

funcName: the name of the function to being registered as a listener var topic = this.getTopic(topic);

  • topic.subscribe(obj, funcName);

+ return topic.subscribe(obj, funcName);

}

this.unsubscribe = function(/*String*/topic, /*Object*/obj, /*String*/funcName){

@@ -57,7 +57,7 @@

funcName: the name of the function to being unregistered as a listener var topic = this.getTopic(topic);

  • topic.unsubscribe(obj, funcName);

+ return topic.unsubscribe(obj, funcName);

}

this.destroy = function(/*String*/topic){

Change History (4)

comment:1 Changed 13 years ago by guest

Actually, this patch is better, because it has the proper documentation comments:

Index: topic.js =================================================================== --- topic.js (revision 6769) +++ topic.js (working copy) @@ -44,7 +44,7 @@ dojo.event.topic = new function(){

funcName: the name of the function to being registered as a listener var topic = this.getTopic(topic);

  • topic.subscribe(obj, funcName);

+ return topic.subscribe(obj, funcName); dojo.event.MethodJoinPoint?

}

this.unsubscribe = function(/*String*/topic, /*Object*/obj, /*String*/funcName){

@@ -57,7 +57,7 @@ dojo.event.topic = new function(){

funcName: the name of the function to being unregistered as a listener var topic = this.getTopic(topic);

  • topic.unsubscribe(obj, funcName);

+ return topic.unsubscribe(obj, funcName); dojo.event.MethodJoinPoint?

}

this.destroy = function(/*String*/topic){

comment:2 Changed 13 years ago by guest

Bah! Once more, with formatting:

Index: topic.js
===================================================================
--- topic.js    (revision 6769)
+++ topic.js    (working copy)
@@ -44,7 +44,7 @@ dojo.event.topic = new function(){
                // funcName:
                //              the name of the function to being registered as a listener
                var topic = this.getTopic(topic);
-               topic.subscribe(obj, funcName);
+               return topic.subscribe(obj, funcName); // dojo.event.MethodJoinPoint
        }
 
        this.unsubscribe = function(/*String*/topic, /*Object*/obj, /*String*/funcName){
@@ -57,7 +57,7 @@ dojo.event.topic = new function(){
                // funcName:
                //              the name of the function to being unregistered as a listener
                var topic = this.getTopic(topic);
-               topic.unsubscribe(obj, funcName);
+               return topic.unsubscribe(obj, funcName); // dojo.event.MethodJoinPoint
        }
 
        this.destroy = function(/*String*/topic){

comment:3 Changed 13 years ago by dylan

Milestone: 0.9

comment:4 Changed 12 years ago by Adam Peller

Resolution: fixed
Status: newclosed

looks like this happened in 0.9

Note: See TracTickets for help on using tickets.