Closed alexandernst closed 4 years ago
@mroderick If you don't have the time to implement this on your own, would you be willing to accept a PR implementing this functionality?
@mroderick ping
This doesn't seem like a good idea to me.
Publishers of events trust that the events are delivered to ALL subscribers ... adding this mechanism will allow someone to break that trust, without the publisher or all the other subscribers to the event knowing. That's taking away control and opening up for some really difficult to find bugs.
What is the use case you'd like to support?
I (the developer) am the creator of both the publishers and the subscribers. This mechanism will allow me (the developer) to break that trust, and that isn't a bad thing. It's just another feature that I (the developer) may or may not use, based on my needs.
The feature is not taking away any control. In fact, it's adding more control to the library and to the events propagation. It actually seems quite reasonable for me (the developer) to be able to pause or stop events at my own will, if that is what I want.
My personal use case is a "pause" button, which is supposed to prevent all subscribers to react to events.
I could put some sort of if (window.paused) return;
condition in all my subscribers, but that just feels very hack-y. It would be so much better and cleaner if I could just temporarily "pause" the event propagation.
Publish/subscribe shouldn't concern itself with state, but just with passing messages around.
It seems that the assumption is that there is only one person working on the codebase, and that that person knows the entire codebase.
Most developers I know work in groups and rarely know every single line of the codebases they're working on.
This feature still doesn't look like a good idea for this library, so I'm closing this issue.
In your application, perhaps you could manage state by doing something like PubSub.publish("pause")
and PubSub.publish("resume")
.
Currently there is no way to temporarily stop receiving events. There is a way to
unsubscribe
, which will remove all topic handlers, but there is no way to make PubSub temporarily stop receiving notifications.I propose the following new method:
Example usage: