Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to rename outlets #786

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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

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.

2 participants