Description
Hi guys, first time here. This might not be the first time that someone's asking for this, but unfortunately couldn't fiund anything in previous issues.
Going directly to my use case
I have several mixins I use in my app. Their methods are intended to be used as listeners, so when I add them to a class, I need to register those classes in a list.
mixin A {
void listenerFunctionA() { }
}
mixin B {
void listenerFunctionB() { }
}
mixin C {
void listenerFunctionC() { }
}
(... imagine several other mixins)
Then I add them to the classes
class MyClassWithA with Mixin A {
}
class MyClassWithBC with Mixin B, C {
}
final objectA = MyClassWithA()
final objectBC = MyClassWithBC()
I have a list that I use to register them, so later I can broadcast the actions to the corresponding listeners
List myListMixinA = []
List myListMixinB = []
List myListMixinC = []
And then finally comes the step I'd like to avoid, which is to add them to their corresponding list of listeners:
listenersA.add(objectA)
listenersB.add(objectBC)
listenersC.add(objectBC)
I'm trying to find solutions that could automatically register the objects in their listeners just by adding the mixin clause to the class.
Right now the best option I'm aware and is closer to this is to use inheritance and register the listeners in the parent abstract class, but that forces the abstract class to have all the potential mixins, which results in an excessive amount of calls to objects / functions I don't need. For instance, I wouldn't like to be calling objectA with the functions from mixin B,C.
There's an alternatively with inheritance which would be to have an abstract class for each possible mixin combination, but that would be unsustainable.
So in essence I'd like to find a solution that could help me register these objects automatically, like forcing all the these instantiated objects (objectA, objectBC) to pass through a particular function for each of their mixins.
Is this something feasible at the moment?