Skip to content

Conversation

@imanpalsingh
Copy link

@imanpalsingh imanpalsingh commented Sep 7, 2024

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`
@DavidPetrasek
Copy link

DavidPetrasek commented Sep 9, 2024

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

@imanpalsingh
Copy link
Author

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
Copy link

janko commented Jul 1, 2025

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
Copy link

@marcoroth @brunoprietog thoughts on this one? This would be super helpful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants