sprae icon indicating copy to clipboard operation
sprae copied to clipboard

Function expressions in :if ?

Open exside opened this issue 8 months ago • 3 comments

First of all, thank you for sprae, just started playing around with it and I like it a lot!

I was trying to do <pre :if="() => !!(Object.values($selected).filter(x => x).length)"> expecting that when the $selected object does not contain any values in it's props the <pre> element wouldn't show (i tripplechecked, the expression does work and evaluates to either 0 without !! or false when "casting" to bool, I'd expect both to work, e.g. falsy values in :if).

Am I doing something wrong or is not currently not possible to use functions in :if?

thanks for a quick reply and keep the great work up!

exside avatar Apr 17 '25 14:04 exside

Hi @exside! :if takes value directly, it doesn't have to be a function. Just do <pre :if="!!(Object.values($selected).filter(x => x).length)">.

dy avatar Apr 17 '25 16:04 dy

It makes me wonder if it should take functions as value. Do you have a particular example where you need :if to be a function and plain code doesn't suffice?

dy avatar Apr 17 '25 16:04 dy

It's pretty massive change, I'll add function support in sprae v12.

dy avatar Apr 17 '25 21:04 dy

Hm, don't add it if it bloats the core too much, guess it might be powerful but could also be unnecessary...

exside avatar Jul 02 '25 10:07 exside

It's there in branch v12, it is not bloating code significantly, I am stuck with somethings else

dy avatar Jul 02 '25 10:07 dy

Fixed by v12. Please test @exside

dy avatar Oct 10 '25 17:10 dy