Is there a simpler wikitext implementation of the following code?
\define results(candidacy)
<$text text={{{ [<__candidacy__>!has[won]then[ ]] }}} />
<$text text={{{ [<__candidacy__>get[won]match[yes]then[✅]] }}} />
<$text text={{{ [<__candidacy__>get[won]match[no]then[❌]] }}} />
<$text text={{{ [<__candidacy__>get[won]match[pending]then[◎]] }}} />
\end
This is working code, but it seems far too redundant. In JS, I would probably do something like
const results = (c, {won = ''} = c ) =>
won == 'yes' ? '✅' : won == 'no' ? '❌' : won == 'pending' ? '◎' : ' '
but it could easily be done with a switch
statement or a sequence of if-else
statements.
Are there cleaner TW techniques for this?
I’m assuming this could be done with a data-tiddler equivalent of the following code, but that also feels more heavy than I would like for this simple function:
const results = (c) =>
({yes: '✅', no: '❌', pending: '◎', '': ' '})[c?.won ?? '']
Is there a simple technique I’m missing?
(I do recognize that these are not precise equivalents to the first version above, with very slightly different behaviors if there is a won
property that differs from the three values I define. These JS ones are actually the preferred behavior, but the difference won’t matter in my wiki.)