-
-
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
Spread Operator In Templates #184
Comments
I've been hoping we would see a spread or splat operator for a long time. There is actually an open PR in the handlebars repo handlebars-lang/handlebars.js#1149. In theory it should be compatible with the A really huge use case is being able to use the component helper in a much more dynamic way. We lost this ability when {{#each dynamicComponents as |compInfo|}}
{{component compInfo.class ...compInfo.args}}
{{/each}} |
Another solution is to make this work: export default Ember.Helper.helper(function(params, hash) {
let queryParams = Ember.assign({}, params[0], hash);
// ...
}); Of course this only addresses the query params problem and not other uses cases... |
@workmanw I'll keep an eye on that PR, we might just have to wait until that lands in handlebars. I agree that it would be great to be able dynamically insert components too! |
@Panman8201 For my use case modifying the |
My use case is: {{yield
(hash foo=(component "foo") ...this.moreThings)
}} |
@amk221 You could use @tchak's {{yield
(merge this.moreThings foo=(component "foo"))
}} One issue with above helper (AFAICT) is that it does not track changes on import { helper } from '@ember/component/helper';
import { assign } from '@ember/polyfills';
export default helper(function(hashes, hash) {
// return assign(Object.create(null), ...hashes, hash);
return assign({}, ...hashes, hash);
}); |
The reason I created |
My use case would be: {{#each components as |component|}}
{{component component.name ...component.params}}
{{/each}} |
Another plus side for being able to splat arguments and similar is that it makes one variant of higher-order components quite nice: you can just wrap an existing component, make some template-layer tweaks/wrapping and forward all the inbound arguments to it. |
I have the same use case as @workmanw @amk221 and @basz and I totally agree with @chriskrycho : a spread operator would be the best friend of the |
@chriskrycho Sorry to bother you about this old one, but do you know what is the status of this ? I mean, I've searched a bit, but I can't find if today we can splat arguments, passing them to the |
This seems like a good idea, but we need an RFC to move it forward. Is there anything I can do to help facilitate? |
Problem
Currently there is no way to pass dynamic parameters to certain Template Helpers. I'll call out the
query-params
helper in this case as an example.Typically we'd use it in the following way:
Which would give us a link to
/route?sort=asc&status=complete
This works well, but there is no way to pass a set of dynamic values to the helper. If we have the following in a component:
You can't destructure the parameters in the template:
Solution
We should add support for a spread operator (similar to the one in javascript) for use in templates.
I would see something like this looking like:
Which would end up being the same as:
But would allow us to change
params
and have it reflect in the helper.The text was updated successfully, but these errors were encountered: