Skip to content

Function expressions in :if ? #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
exside opened this issue Apr 17, 2025 · 3 comments
Open

Function expressions in :if ? #60

exside opened this issue Apr 17, 2025 · 3 comments

Comments

@exside
Copy link

exside commented Apr 17, 2025

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!

@dy
Copy link
Owner

dy commented Apr 17, 2025

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
Copy link
Owner

dy commented Apr 17, 2025

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
Copy link
Owner

dy commented Apr 17, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants