Open DanCardin opened 1 week ago
Do you mean displayName ? displayName : name
? I have not seen the other syntax
It seems to be that only when your first value exists "true" is returned. So this definitely is a bug/weird behaviour. Imo it should just return v instead of true
const op1Val = evalQueryExpression(
op1,
obj,
variables,
functionMap,
);
if (op1Val instanceof Promise) {
return op1Val.then((v) =>
v ||
evalQueryExpression(val[2], obj, variables, functionMap)
);
} else if (op1Val) {
return true;
} else {
return evalQueryExpression(val[2], obj, variables, functionMap);
}
Don't forget about the '??' (nullish coalescing) operator as defined here and discussed here.
I'd have to check on its implementation insofar as SB templating goes later when not on mobile but, just thought it worth a mention in this thread.
Usecase:
displayName
is frequentlyundefined
, so where it is undefined, i'd like to fall back toname
.As far as I can tell, the easiest way to achieve this today is
displayName: displayName : name
(if there's something else, let me know, and perhaps this is just an expression-language-page update). This mainly just an unfortunate pattern because it repeatsdisplayName
twice each timeWhat might be nice as an alternative is:
displayName or name
which i'm calling "truthy or". Today, this just returns"true"
, but what i'm suggesting is essentially python/javascript style evalutation of anor
by eagerly returning the first truthy value.coalesce(displayName, name)
(or some syntax, like|
) as a more explicit way of coalescing than the former option.EDIT: yes i meant
displayName ? displayName : name
above