Skip to content

Commit 0198fb9

Browse files
committed
fixes mroderick#106 by looking for descendant topics of specified unsubscibe parameter
in cases where only child topics have been registered
1 parent cbd62c7 commit 0198fb9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/pubsub.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,18 @@ https://github.com/mroderick/PubSubJS
207207
* PubSub.unsubscribe('mytopic');
208208
*/
209209
PubSub.unsubscribe = function(value){
210-
var isTopic = typeof value === 'string' && messages.hasOwnProperty(value),
210+
var descendantTopicExists = function(topic) {
211+
var m;
212+
for ( m in messages ){
213+
if ( messages.hasOwnProperty(m) && m.indexOf(topic) === 0 ){
214+
// a descendant of the topic exists:
215+
return true;
216+
}
217+
}
218+
219+
return false;
220+
},
221+
isTopic = typeof value === 'string' && ( messages.hasOwnProperty(value) || descendantTopicExists(value) ),
211222
isToken = !isTopic && typeof value === 'string',
212223
isFunction = typeof value === 'function',
213224
result = false,

0 commit comments

Comments
 (0)