If-then-else component

How come the dmx.Component("if", ...) in AppConnect 2.0 still doesn’t support an else branch?

We keep repeating our conditions and using dmx-show for the “then” branch & dmx-hide for the “else” branch.

What’s the official way to avoid such repetition?


I would expect the <if> component to have 2 (or more) children and if the condition is true, then it shows the first, (this.$node.appendChild(this._template.cloneNode(!0))) just like now.

if the condition is false, i would show the 2nd (or all-but-the-1st) element(s).

it’s already dealing with deleting multiple elements, if the condition is false (this._shown && (Array.from(this.$node.childNodes).forEach((e=>{..., which surprised me, because it suggests it could have supported an “always” branch too, which could be useful from a CSS-selector perspective.

btw, this.$node.childNodes is already a built-in iterable, returning itself as an iterator, which have a forEach helper method already, hence u can save the Array.from call, which just generates extra garbage for no benefit.

furthermore u can write Array.from(iterable) more compactly as [...iterable], when u really need to spill it into an array.