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
Splat operator #1050
Comments
I like this. It would be useful for Ember components. I prefer |
Being a bum on vacation right now but quick comment: Allowing this for hash and not array parameters feels weird and I suspect that people are going to ask for array as well. The only thing that I can think of to support that would be having a separate syntax for one vs. the other:
|
Some more context for the discussion: https://github.com/sebmarkbage/ecmascript-rest-spread tl;dr: The JS syntax |
That doesn't help us since {} vs () is unambiguous but our parameter constructs aren't. We need to have an explicit way for hash rest to be defined vs array params rest since we can't trust runtime type of or similar (I.e. What do we do with an iteratable? Is that a hash rest or an array rest? At what point will this surprise the hell out of users or limit optimization?) |
I agree it doesn't help (it hurts). Just mentioning. |
Some of this is probably bike shedding. If someone were to implement this changing the exact tokens used is pretty trivial. Concept is great, we just need to sort out the "ui" and make sure the performance isn't negative (which i don't expect since this seems like it should be isolated to users of the feature) |
This feels like a decent feature but we have relatively little room for new syntax at this point without falling off the complexity cliff, so I agree with @kpdecker. Let's tread carefully. |
Seb's rest spread is an interesting idea, though not quite certain to become reality afaik. In JS, we have the context of usage to differentiate array from property spread. Handlebars has no equivalent context. Given My suggestion is to reserve Happy to take any next steps that seem appropriate. |
@mixonic the more direct precedent from Python and Ruby is * for params and ** for hash 😄 |
👍 Functionally speaking, I believe this concept is need to fully replace More details also in this discourse discussion: programmatically-rendering-ember-components |
My vote is ** for hash, * for params. They should be allowable anywhere inside the respective hash/params. Basically
and
|
I have warmed to |
The only thing left to figure out is where splats can appear. Since they aren't ambiguous, I think they should be allowable anywhere where they make sense (as described in the grammar in my last comment). |
I think there are a few questions that need to be answered:
|
Is any news on this? I see it went to Backlog. Will it be implemented soon? I would gladly help. |
I personally don't have time to implement this. If you want to take a crack at it, I'd be glad to help if there are questions. |
+1 this would be a great feature |
There's been some recent discussion in Emberland about whether it would be preferable to leverage ES2015 Here is one Simple example:
More complex
/cc @wycats |
Perhaps
Note that with this syntax, the |
I like |
if we are going for the ES2015 splat syntax, are there reasons why the same |
I think |
I doubt I suspect |
After talking over with @mmun last night (he summarized a lot of what we discussed above), I'm leaning in favor of |
@machty sorry for the vagueness: i was trying to suggest using the same ES2015 |
@waynedpj You're right, but it doesn't work here. In ES2015 What would you have So we need to come up with a static solution that disambiguates the two cases. @matchy's proposal is for |
@mmun thanks for taking the time to clarify this. i had been missing the i think the additional |
One possible drawback with |
Feels like the clearest to me given all of the constraints that we have, which I think this discussion has covered well. @machty Someone would have to actually implement this but I don't think it will be an issue from the parser standpoint. right now |
@kpdecker Do we want to support splatting |
@machty Good point, I did not think of that case. For I think that we should allow for spaces between the I think with the hash case, it's clear enough as the (Edit: I even had the wrong number of |
I have begun work on a followup PR to #1128 based on the latest feedback in this thread. |
@machty thank you and everyone else! |
@machty Are you branching off of #1128 or starting fresh? Can you work in the open so we can contribute? @BenjaminHorn Would you be willing to grant access to your fork to people? Haven't seen you since magically showing up with a PR on 11/2. :) |
@nathanhammond I would gladly add you (or anyone who ready to add those modifications) as collaborator. Just let me know. |
@BenjaminHorn Add me and @machty, pretty please. :) Just trying to update #1128 to bring it inline with current discussion. |
@nathanhammond done ;) |
@nathanhammond I just branched off of his PR, rebased onto master, and I'm partly through the work to get it done. There's not much to show right now (half the tests aren't passing), so there's not much as far as WIP to share, but I should have a PR in this weekend that I'll ping you on. |
@nathanhammond et al please check out #1149 which has most of the work done; the only thing remaining are positional param splats and subexpression splats. |
Closing in favor of #1149 |
Previously, the `{{t}}` helper, like the `i18n.t` utility, accepted a translation key and a context hash. This worked when the Handlebars template had the individual keys and values (or value bindings) for the context, but didn't when there was a pre-built object that represented the context. Now it accepts a second ordered (non-hash) argument that represents the context as an object. Hash context properties override those from the context object. ```hbs {{t 'some.key' someObject prop=value}} ``` is approximately the same as ```js i18n.t('some.key', Object.assign({}, someObject, { prop: value })) ``` This is a workaround for the fact that Handlebars does not yet have a syntax for splatting an object into hash arguments. See handlebars-lang/handlebars.js#1050 See handlebars-lang/handlebars.js#1128 See handlebars-lang/handlebars.js#1149 Closes #423
I've been fielding several requests for a splat operator in Ember templates. Specifically, when using Ember components. For example given:
It would de-sugar to:
This proposal is limited in scope.
Grammer proposal
Visually, it makes sense to put the splat before any hash arguments. This would aid in the understanding that hash arguments should take precedence. For example given:
The hash would be
{ keyA: 'val', keyB: 'I take the crown!' }
. This is actually runtime behavior, and could vary according to implementation, but seems a good justification for the above ordering.It is also suggested that subexpressions would also accept a splat. For example:
Alternatives
It has been suggested by @wycats that we consider
...myHash
, as it aligns more closely with JavaScript splatting. This seems reasonable, I'd like some more thoughts./cc @kpdecker @mmun @krisselden @wycats @chrislopresto
The text was updated successfully, but these errors were encountered: