如何检查dojo主题事件是否已订阅

如何检查dojo主题事件是否已订阅,dojo,Dojo,在这里,我只想知道我们如何知道这个类已经订阅了的“some-evt” 我不想设置这个设置为null。_evt.remove()很抱歉,但是dojo/topic实现通常不提供已发布的主题的列表,也不提供谁发布了该主题。Dojo的实现符合这个标准,即没有内置机制来获取主题列表。请注意,dojo/topic只有两个功能,publish和subscribe 你应该实现你自己的想法,比如一个mixin,它有一个订阅topic并记录注册的主题名的功能,这只是一个想法 \u TopicMixin.js

在这里,我只想知道我们如何知道这个类已经订阅了的“some-evt”


我不想设置这个之后将code>设置为null。_evt.remove()

很抱歉,但是
dojo/topic
实现通常不提供已
发布的
主题的列表,也不提供谁
发布了该主题。Dojo的实现符合这个标准,即没有内置机制来获取主题列表。请注意,
dojo/topic
只有两个功能,
publish
subscribe

你应该实现你自己的想法,比如一个
mixin
,它有一个订阅
topic
并记录注册的主题名的功能,这只是一个想法

\u TopicMixin.js

   someMethod : function() {  
        if ( !this._evt ) {
            this._evt = topic.subscribe("some-evt", lang.hitch(this, "_someOtherMethod"));
        } else {
            this._evt.remove();
            //Here this just remove the listener but the object this._evt is not null 
        }
    },
如何使用它

define(["dojo/topic"], function(topic){

    return {
        topicsIndex: {},

        mySubscribe: function(topicName, listener){
            this.topicsIndex[topicName] = topic.subscribe(topicName, listener);
        }

        myUnsubscribe: function(topicName){
            if(this.topicsIndex[topicName]){
                this.topicsIndex[topicName].remove();
                delete this.topicsIndex[topicName];
            }
        }

        amISubscribed: function(topicName){
            return this.topicsIndex[topicName];
        }
    };
});
希望能有帮助

define(["dojo/_base/declare","myApp/_TopicMixin"], function(declare, _TopicMixin){

    return declare([_TopicMixin], {

        someMethod : function(){
            if ( !this.amISubscribed("some-evt") ) {
                this.mySubscribe("some-evt", lang.hitch(this, "_someOtherMethod"));
            } else {
                this.myUnsubscribe();
            }
        }
    });
});