amp-bind: Multiple args in closure functions e.g. reduce()
See original GitHub issueWhat’s the issue?
The Array.reduce
function in an amp-bind expression currently only allows one parameter (the callback function) to be passed in. There should be support for the second parameter (initial value) as well.
One can prepend an initial value to an array before using the reduce function but having the second parameter is more ideal.
How do we reproduce the issue?
[1, 2, 3].reduce((x, y) => x + y)
is OK.
[1, 2, 3].reduce((x, y) => x + y, 0)
is not accepted.
What browsers are affected?
All browsers
Which AMP version is affected?
Latest.
CC: @jmarkoff & @sebastianbenz
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Documentation: <amp-bind> - amp.dev
Allows elements to mutate in response to user actions or data changes via data binding and simple JS-like expressions.
Read more >Chapter 5. Closing in on closures - Secrets of the JavaScript ...
This method is designed to create and return a new anonymous function that calls the original function, using apply() , so that we...
Read more >Bind more arguments of an already bound function in Javascript
You can bind multiple arguments multiple times, exactly as partial application, but the context object only once, you can't override it once you ......
Read more >Automatic Mixed Precision package - torch.amp - PyTorch
See the CUDA Automatic Mixed Precision examples for usage (along with gradient scaling) in more complex scenarios (e.g., gradient penalty, multiple models/ ...
Read more >Closures with multiple parameters - Hacking with Swift
We're going to call that using a trailing closure and shorthand closure parameter names. Because this accepts two parameters, we'll be getting both...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@choumx I have been able to get around this with the mentioned workaround for all of my cases so far! I imagine it works for all other cases as well.
@choumx, Our use case needs this one to be fixed: [1, 2, 3].reduce((x, y) => x + y, 0) is not accepted.
We use that approach to sum/total the items of our array. e.g.
<span [text]=“’ $’ + shoppingCart.items.map((item, index) => item.price).reduce((x, y) => x + y, 0)”></span>
Is there a workaround to avoid the validation issue. Our use case needs the array to be empty initally.
Thanks.