Feature request: <dom-if-else>
Very often I encounter that I need not only if, but also else, while combination of two ifs is quite ugly and violates DRY principle.
I suggest to add <dom-if-else> for such cases.
Namely, instead of:
<template is="dom-if" if="{{condition}}">
<p>P1</p>
</template>
<template is="dom-if" if="{{!condition}}">
<p>P2</p>
</template>
I'd like to have:
<template is="dom-if-else" if="{{condition}}">
<p>P1</p>
<p>P2</p>
</template>
More complex cases can be handled in such way:
<template is="dom-if-else" if="{{condition}}">
<template>
<p>P1</p>
<p>sub-P1</p>
</template>
<template>
<p>P2</p>
<p>sub-P2</p>
</template>
</template>
<template> or any other element can be used to wrap more than one element, rule is simple:
[is=dom-if-else] > :nth-child(1):ifbranch[is=dom-if-else] > :nth-child(2):elsebranch
+1
See: https://github.com/Trakkasure/dom-else
@Trakkasure, I remember it, probably, from Slack channel, but it doesn't have as compact syntax as described here. It does allow to avoid condition duplication, but still very verbose in simple cases.
Ok. You asked for it.. so here it is: https://github.com/Trakkasure/dom-if-else
@Trakkasure Thanks!
Just tried to use it today. Doesn't work well in Polymer 1.0 at least.
I integrated a bunch of tests from dom-if.... Let me know what is going wrong so I can test better.
Leave issues on the dom-if-else repo: https://github.com/Trakkasure/dom-if-else/issues
Tests added to it.
:+1:
+1
What about this kind of syntax where "else if" could be introduced:
<template is="dom-if" if="{{condition1}}">
<p>P1</p>
</template>
<template is="dom-else-if" else-if="{{condition2}}">
<p>P2</p>
</template>
<template is="dom-else">
<p>P3</p>
</template>
this is no different than negating the original condition with another dom-if template.
On Thu, Nov 12, 2015 at 8:31 AM, Pascal Gula [email protected] wrote:
What about this kind of syntax where "else if" could be introduced:
P1
P2
P3
— Reply to this email directly or view it on GitHub https://github.com/Polymer/polymer/issues/2165#issuecomment-156116396.
+1
+1 On Dec 29, 2015 10:28 PM, "kunhimohamed" [email protected] wrote:
+1
— Reply to this email directly or view it on GitHub https://github.com/Polymer/polymer/issues/2165#issuecomment-167944904.
[image: CHI Logo]Cultural Homestay International (CHI)Toll Free: 1-800-432-4643Website: chinet.orgCHI Blog https://chinet.org/blog/ | Facebook https://www.facebook.com/CulturalHomestayInternational | YouTube https://www.youtube.com/user/chinetorg | Twitter https://twitter.com/CHI_News
+1
+1
+1
+1
+1