-
-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to clear all subscribers for a topic by changing uid to a number #60
Comments
If I understand correctly, you would like a way to remove all subscriptions for a topic. A dedicated method would probably be better than further overloading the How would that affect hierarchical topics? var func = function NOOP(){};
PubSub.subscribe('a', func);
PubSub.subscribe('a.b', func);
PubSub.subscribe('a.b.c', func);
PubSub.clearSubscriptions('a.b');
PubSub.publish('a.b.c', { hello : 'world' });
// Would func still be notified of `a.b.c` topic? |
To be frank I had not considered hierarchical topics. But I suppose it would work the same way because, why not. If you unsubscribe a parent, like |
I think that I am unlikely to use such a method myself, as I prefer to design parts of systems to not have too much knowledge about other parts of systems (so, in one part, I might not know if it would be safe to remove all subscriptions). However, I think that with the right level of documentation, such a method could be useful in some scenarios. |
The use case could be cleanup of an app, removing all global-level listeners when they are no longer needed because the app served it's purpose. |
This has been implemented with #62, and is included in |
I wanted to do
PubSub.unsubscribe('topic')
but can't. Instead to unsubscribe an event I either have to maintain the returned ids or I have to maintain a reference to the handler function.If the unique id returned by
subscribe
were to just bevar token = ++lastUid
, you could overload theunsubscribe
method by checking for a number to do the same as strings do right now. Then you could use the string case to drop all handlers for a certain topic.The only impact I see right now is to users who rely on the
subscribe
return value being a string. I'm not sure why anyone would though since for them it's just a token.The fixes are trivial but I don't know whether you're open to such a change.
The text was updated successfully, but these errors were encountered: