EventBus
EventBus copied to clipboard
Allow registration of classes without any subscriptions
For automatic registration in base classes where some defined children might not have any subscriptions. This could be a configuration value on the bus or a registerOptional
method.
:+1:
Why not move the register call to an overridable method that you overwrite empty in the child classes that should not register to EventBus? Would make it much more clear which classes register and which not and void the performance overhead of searching for subscriber methods.
Something like:
public abstract class BaseClass {
protected void registerEventBus() {
EventBus.getDefault().register(this);
}
}
public class ChildClass extends BaseClass {
@Override
protected void registerEventBus() {
// do not register to EventBus
};
}
-ut
Because I'm honestly just not interested in keeping track of which child class is registering on the bus and which is not. I want to add a subscription to any activity/fragment at any time and have it just work. Whatever tiny performance overhead this adds is worth the developer comfort.
If anyone else is looking for this, my current workaround is to add a subscription on a dummy class inside the base class.