question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

amp-bind: Multiple args in closure functions e.g. reduce()

See original GitHub issue

What’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:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tbaikcommented, Dec 7, 2017

@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.

0reactions
rizalpascualcommented, Mar 1, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found