This if statment has me confused
-
Can someone break this down into an if else statement so I know what's going on here?
color: control.enabled ? control.down ? themeManager.currentTheme.palette.highlightColor : control.flat? "transparent" : control.isPrimary ? control.style.primaryColor : control.style.fillColor: "grey"I just recently started using these alternate forms of the if/else statement and I am not that familiar with how they work when they become more complex. Here is my attempt but I am just guessing:
if(control.enabled || control.down) { themeManager.currentTheme.palette.highlightColor } else { if(control.flat) { "transparent" } else { if(control.isPrimary) { control.style.primaryColor } else { control.style.fillColor } ... here is where I am lost } } -
What a monster line! This code is in bad need of refactoring :-)
(something)?always meansif (something)and:always meanselse. So:color: { if (control.enabled) { if (control.down) { return themeManager.currentTheme.palette.highlightColor; } else { if (control.flat) { return "transparent"; } else { if (control.isPrimary) { return control.style.primaryColor; } else { return control.style.fillColor; } } } } else { return "grey"; } }It can be also expressed in other ways, of course (nested if is more or less the same as
&&etc.). -
What a monster line! This code is in bad need of refactoring :-)
(something)?always meansif (something)and:always meanselse. So:color: { if (control.enabled) { if (control.down) { return themeManager.currentTheme.palette.highlightColor; } else { if (control.flat) { return "transparent"; } else { if (control.isPrimary) { return control.style.primaryColor; } else { return control.style.fillColor; } } } } else { return "grey"; } }It can be also expressed in other ways, of course (nested if is more or less the same as
&&etc.). -
Hi,
One other to analyse this line is to break it in more "logical unit":
control.enabled ? control.down ? themeManager.currentTheme.palette.highlightColor : control.flat ? "transparent" : control.isPrimary ? control.style.primaryColor : control.style.fillColor : "grey"It is still not pretty but more manageable to get around.