amp-bind: Support shortened ternary syntax
Right now amp-bind supports the ternary operator
A ? B : C
which returns B if A is truthy and C otherwise. I would like to expand this to support the following:
A ?: B
which returns A if A is truthy and B otherwise.
This is particularly useful for expressions that have fallbacks when a variable isn't defined in a page's amp-state. (undefined variables are always null) So:
<p>You have selected <span [text]="selection ? selection : 'nothing'">nothing</span></p>
could be shortened to
<p>You have selected <span [text]="selection ? : 'nothing'">nothing</span></p>
@choumx
Actually Dima brought this up too (sometimes called the Elvis operator).
|| works the same way and seems more commonly used, though couldn't hurt I suppose.
Looks like ?: isn't natively supported in JS. Do you think it's worth breaking consistency here?
Since || provides the same functionality, I could go either way.