Skip to content
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

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

Closed
tbaik opened this issue Dec 7, 2017 · 5 comments
Closed

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

tbaik opened this issue Dec 7, 2017 · 5 comments

Comments

@tbaik
Copy link
Contributor

tbaik commented Dec 7, 2017

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

@dreamofabear
Copy link

Agree that would be better. For prioritization: are there cases where a workaround doesn't exist?

@tbaik
Copy link
Contributor Author

tbaik commented 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.

@x0bandeira
Copy link

Hi there, I believe this along with operands limit on expressions, make it impossible or very hard to reduce into another array which is useful for state management of state/arrays.

@dreamofabear
Copy link

@COMMAND3R Do you have an example you can share?

@rizalpascual
Copy link

@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)">

Is there a workaround to avoid the validation issue. Our use case needs the array to be empty initally.

Thanks.

@dreamofabear dreamofabear changed the title Array.reduce function in amp-bind expression to support more than one parameter amp-bind: Multiple args in closure functions e.g. reduce() Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants