-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Named block syntax #317
Named block syntax #317
Conversation
I personally find this syntax really awkward to parse, and I think the reason is that I expect something to be on the other side of the |
I think you mean It's certainly a possibility to not have the equal sign but it comes with its own problems: Not clear that it has the same semantics as a named argA beginner is more likely to think that this sort of syntax is possible when in it is not: <Table>
<@column>...</@column>
<@column>...</@column>
<@column>...</@column>
</Table> In fact, it is equivalent to <Table @column=... @column=... @column=... /> which is fairly clearly an invalid. Contrast with <Table>
<@column=>...</@column>
<@column=>...</@column>
<@column=>...</@column>
</Table> which carries more of the characteristics of the second snippet. It looks like an angle bracket invocationIn the angle bracket invocation RFC we propose that Consequently, I think it would be very surprising if To be clear, I'm not proposing that we add this syntax, but rather that if we did add that syntax that there is only one real possible thing that it can mean. |
In case it's not clear to anyone what is meant by "named blocks are named args" it may be useful to make an analogy with JavaScript. The Handlebars template <PowerAccordian @items={{blogPosts}}>
<@header= as |item|>
{{item.title}}
</@header>
<@details= as |item|>
<h4>By {{item.author}}</h4>
<p>{{item.text}}</p>
</@details>
</PowerAccordian> is conceptually similar to this JavaScript PowerAccordian(Object.assign({ items: this.blogPosts }, {
header: (item) => {
return item.title;
},
details: (item) => {
return [item.author, item.text];
}
})); |
FYI for IntelliJ (20% of our users according to https://www.emberjs.com/ember-community-survey-2018/) this is entirely broken... 😞 |
@Turbo87 Damn. Part of this RFC should be to address the impact on syntax highlighting in popular editors and how difficult it would be to change them to support this syntax. If it's too difficult to change them we may have to look to another syntax style entirely... |
I think you mentioned it above already, it's not (only) the |
I think making nice syntax highlighters is important, but I don't think that should limit our syntax choices here. We are already far from having a good experience with a generic handlebars syntax highlighter. Having dedicated glimmer template highlighters seems already a pretty strong requirement. Consider for example that |
FWIW this is not just about syntax highlighters. We might be able to make our own (for each editor/IDE...), but e.g. in IntelliJ we would lose all of the builtin refactoring and code analysis functionality around HTML and Handlebars since we most likely can't just extend the builtins that easily... |
I'm curious about why this (and previous) RFCs lean towards special syntax It seems simpler to me so I'd like to know if there is a reason I can't see. |
I'm not sure which part of the syntax you consider special, so I will address both. First, I'll address the <Panel @title="x">
<@body=>
y
</@body>
</Panel> Is just a more expanded/generalized form of <Panel @title="x" @body="y"/> Second, I'll address the For example: it's reasonable to expect that Another example: when you use On the other side (block invocation), we actually do try to make it feel like regular invocation (because it is). |
I can see how the |
Can we have some examples of the rendering side? Like: {{#each @items as |item|}}
{{@header item}}
{{@details item}}
{{/each}} {{#if @header}}
{{@header item}}
{{else}}
No header
{{/if}} {{#@header}}
I assume we error gracefully here.
{{/@header}} Any other different ways to use this I missed? |
@ef4 The result of invoking the named block will still render it inside the component (<Panel ...>) unless the component uses a wormhole internally, won't it? |
Yes, they'll normally be somewhere inside the component, but the specific location and ordering of blocks doesn't match the way they appear in the caller's template: {{! Invocation }}
<Panel>
<@first=>
First
</@first>
<@second=>
Second
</@second> {{! implementation of Panel}}
<div class="panel">
<@second />
<table>
<tbody>
<tr>
<td>
{{#if showFirst}}
<@first />
{{/if}}
</td>
</tr>
</tbody>
</table>
</div> If we treated the block definitions as if you were invoking components, it would be very weird for |
@mmun something that I noticed when looking at other RFCs. It would be helpful to see how this is different from the existing RFC'd syntax. I worry that some comments may be more about named blocks in general rather than the changes being recommended. |
Is there any movement on this, anything blocking from FCP? |
would love to know if anything is blocking this as well. |
@rwjblue confirm |
Rendered