-
Notifications
You must be signed in to change notification settings - Fork 425
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
Documentation for Outlets API #604
Conversation
|
||
## Attributes and Names | ||
|
||
The `data-search-result-outlet` attribute is called an _outlet attribute_, and its value is a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) which you can use to refer to other controller elements which should be available as outlets on the _host controller_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host controller designation may be introduced a bit sooner to help understanding this. Maybe on line 8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the terminology may already be decided upon but could we call this source
controller instead of host
controller?
So it's source/outlet not host/outlet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah agreed. I wasn't too happy with the term "host controller". It's not decided yet, that's just what I had in there as a placeholder. Happy to change it whatever makes to most sense. source
seems better fitting to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general comments below but what happens if you have an outlet that has two or more Controllers on it?
Maybe I missed something but does the name of the outlet have to match the name of the expected outlet controller?
|
||
## Attributes and Names | ||
|
||
The `data-search-result-outlet` attribute is called an _outlet attribute_, and its value is a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) which you can use to refer to other controller elements which should be available as outlets on the _host controller_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the terminology may already be decided upon but could we call this source
controller instead of host
controller?
So it's source/outlet not host/outlet?
|
||
Outlet callbacks are specially named functions called by Stimulus to let you respond to whenever an outlet is added or removed from the page. | ||
|
||
To observe outlet changes, define a function named `[name]OutletConnected()` or `[name]OutletDisconnected()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To observe outlet changes, define a function named `[name]OutletConnected()` or `[name]OutletDisconnected()`. | |
To observe outlet changes, define a class method named `[name]OutletConnected()` or `[name]OutletDisconnected()`. |
Not sure if needed but it may be clearer if we say that this is a class method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, in the targets
section they are also called "methods" 👍🏼
docs/reference/outlets.md
Outdated
|
||
### Referencing non-controller elements | ||
|
||
Stimulus will throw an exception if you try to declare an element as an outlet which doesn't have the corresponding `data-controller` and identifier on it: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will this error be thrown?
Once the controller is instantiated? Or when you attempt to access the outlet?
Might be good to be clear here - for some cases the data controller attribute could be added later maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's throwing the error when you attempt to access the outlet, similar to how targets handle this. I'll try to make this clearer, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Co-authored-by: LB (Ben Johnston) <[email protected]>
Thanks for the review!
An element with two controllers attached to it also has two different controllers instances. You'll get the controller instance for the controller identifier you referenced as the outlet.
Yes, the outlet name has to match the controller identifier. This is what's used to get right controller instance for a given element. |
Thanks @marcoroth it makes sense that the outlet name must match the controller identifier. I must have missed that or maybe we can make it clearer. |
|
||
## Definitions | ||
|
||
Define controller identifiers in your controller class using the `static outlets` array. This array declares which other controller identifiers can be used as outlets on this controller: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define controller identifiers in your controller class using the `static outlets` array. This array declares which other controller identifiers can be used as outlets on this controller: | |
Define controller identifiers in your controller class using the `static outlets` array. This array declares which other Controller identifiers can be used as outlets on this controller: |
I see we say identifiers here. Just another nitpicky fix for proper noun usage of Controller
This Pull request adds documentation for the Outlets API which was introduced in #576.
It also updates the
order
for the other sections in the reference.Feedback very welcome, especially on the used examples.