Uh oh!
There was an error while loading. Please reload this page.
Multiple yields - #43
Conversation
There was a problem hiding this comment.
when composing multiple components, naming collisions become quite possible.
There was a problem hiding this comment.
In terms of multiple layers of components?
I see no reason why these wouldn't be localized to the current context they are in. Can you give an example of when this would be a problem?
mmun
commented
Apr 2, 2015
What happens if two components supply content to the same name? Is the content replaced? or appended to? What happens if one of those components is then removed? I'm also kind of dubious about the name |
jamiebuilds
commented
Apr 2, 2015
@mmun providing |
mmun
commented
Apr 2, 2015
@thejameskyle So the content-for must be supplied immediately in the component's block? That seems troublesome. e.g. In this case I want to yield back content to foo-component with data from bar-component. |
mmun
commented
Apr 2, 2015
This problem was one of the initial motivations for block params. You could imagine yielding a helper on a block param that was scoped to a component, like |
jamiebuilds
commented
Apr 2, 2015
What would be the use case for that? Also could that be solved as: |
mmun
commented
Apr 2, 2015
The use case I'm interested in is Routable components, e.g. the index component nested inside the application component. Essentially a template based API around the |
mmun
commented
Apr 2, 2015
These use cases are obviously a bit different, but I bring it up because they are fighting for the same I think your RFC would be better implemented as a Handlebars language feature. Basically you are naming a block and passing it into the component. It is better to have the named block accessed statically instead of as a side effect of running I'm thinking something like The main point is that the named blocks are known statically. The actual syntax for defining the blocks is open for bike shedding. |
mmun
commented
Apr 2, 2015
Paging señor @wycats. |
balinterdi
commented
Apr 2, 2015
This is definitely something I have come across and would like to see implemented in Ember one way or another. Even just moderately complex components have some markup that is inherent for the component then something that should be customized in each case, then again some common markup, then customizable again, etc. An example in our project is an image uploader that shows the currently uploaded image, an upload link/button, a progress bar, an icon to remove the current image. Some of these are only present in some cases. Here is one instance where we use said component: Not being able to yield multiple times is something I can get around but being able to do it would make code more DRY and intuitive and components' code more intuitive/readable. |
jamiebuilds
commented
Apr 2, 2015
@mmun I'd be totally fine with that change or any implementation detail. I don't care so much about syntax or naming, but rather that there is a solid way of writing templates like this. |
workmanw
commented
Apr 2, 2015
❤️ the concept. I definitely have a need for this. I'm a little hung up on the Either way: 👍 |
tim-evans
commented
Apr 3, 2015
mmun
commented
Apr 4, 2015
@tim-evans We need to work out some kinks. The primary concern is that a helper call like |
tim-evans
commented
Apr 4, 2015
Agreed, @mmun That makes a lot of sense. |
MiguelMadero
commented
May 10, 2015
Today we're doing something similar by using nested and related components. Borrowing from the provided example: We would have something like:
Rewriting the original example: importMyComponentfrom'tyrion/components/my-component';exportdefaultEmber.Component.extend({onInit: function(){varmyComponent=this.nearestOfType(MyComponent);Ember.assert('my-component-footer can only be used inside a my-component',myComponent);myComponent.set('_footer',this);}.on('init'),render: function(){// intentionally left as no-op so we don't render anything}}); |
rwjblue
commented
Jun 7, 2015
We have been discussing this use-case in depth at the Ember core team face to face, and we would like to move towards using static slots as opposed to dynamic slots. We'll be submitting an RFC for the static slot concept and would love your feedback on where that falls down for your use case. |
machty
commented
Jul 30, 2017
FYI this has been superseded by the now-merged Named Blocks RFC. |
/cc @wycats & @stefanpenner