Add ability to rename outlets by imanpalsingh · Pull Request #786 · hotwired/stimulus

@imanpalsingh

This PR adds ability to rename outlets with the following api

// chat_controller.js

export default class extends Controller {
  static outlets = [ "user-status", { time: "features--read-recipients--time" }]

  connect () {
    this.userStatusOutlet // Existing outlet
    this.timeOutlet // Renamed from this.featuresReadRecioientsTimeOutlet.
  }
}

Let me know if this would be useful as a feature.

Thank you!

Currently outlets are accept via an array of string `[a,b,c]`. This commit adds the ability to also accept a rename object withing this array that will determine how will the outlet be accessed.

For example

```
static outlets = ['alpha', {'outlet--with--very--long--name': short}]
```
now instead of `this.outletWithVeryLongNameOutlet` you can use `this.shortOutlet`

@imanpalsingh

@DavidPetrasek

Why access both the original and renamed outlet? That's confusing. Here's I believe a better solution #717

@imanpalsingh

Why access both the original and renamed outlet? That's confusing. Here's I believe a better solution #717

Thank you for checking it but It does not create outlet with original name.
this.userStatusOutlet is a normal outlet which is not renamed. I suggest you to have a look at https://stimulus.hotwired.dev/reference/outlets

@janko

Would love to have this merged 🤞🏻 Without this functionality, outlet names are tied controller names, which is very limiting.

I currently have a select controller for <select> boxes, and a geofence controller that contains a select box for radius. The inability to change the outlet name forces me use generic selectOutlet name instead of the desired radiusSelectOutlet. Additionally, I can't have different outlets for different elements that activate the same controller.

@MatheusRich