-
Notifications
You must be signed in to change notification settings - Fork 443
Description
Outlets require that the target controller name corresponds to the outlet name, e.g. if I write data-source-target-outlet then my target element must have data-controller="target".
This makes sense as a technical requirement, e.g. if there are multiple controllers registered on the target then the source must be able to discriminate between them to choose the controller to receive messages.
The technical constraint appears to us to be preventing object oriented polymorphism, i.e. we must statically know the name of the controller in order to send it messages, and it gets baked into the code for the source controller.
An example of where polymorphism would be useful is a generic "trigger" controller, ala aria-controls that triggers a change in state for a modal/menu controller.
Source:
class TriggerController extends Controller {
static outlets = ["controlled"]
toggle() {
this.controlledOutlet.toggle();
}
}
Targets:
// menu, or modal, or accordion, etc
class MenuController extends Controller {
toggle() {
...
}
}
We might use the source for a sliding menu, a modal+scrim, a menu, etc – anywhere that aria-controls might be appropriate.
We have previously solved this problem using events, but there's quite a bit of boilerplate to this approach and were hoping that outlets could simplify this approach.