-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Switch / Case blocks for templates #5096
Comments
Closing, but referring to this: #530 (comment) I also don't think that having a switch statement really adds huge value, it simply increases the surface area, for no great benefit. Sorry if this isn't the answer you were looking for. FWIW your example doesn't help, do it thusly:
then change component via whatever means you like (switch, etc) |
Let us disagree with you on this. The same reasoning could be done in any language that offers a |
this usecase can be easily done with an own component as wrapper <MySwitchComponent cases={{loading: Loading, error: Error}} case={case} /> |
There's an open RFC about it, discussion should happen there. Also, tagging people won't help get these arguments across. sveltejs/rfcs#49 |
@Kapsonfire-DE I don't think that is helpful really, technically that is true of almost any Svelte Syntax. Anyway there is and RFC about this now, please comment there. |
@dummdidumm too fast for me. |
Thank you for quick answers! Didn't expect that ;) IMO the functionality should be implemented in core Svelte, and not a component; there are a lot of other use cases as well. I did not know about the RFC; will check that right now. And I tagged Rich Harris (not this time ;)) because he had commented on the issue, and seemed to me that he only wanted a cleaner syntax (see also #530). |
I've had a couple times where I've missed a
switch
equivalent for logic in templates. I have been using long if-elseif chains, but this can get ugly. It's mostly useful for when you want to display different components based on an enum. Haven't seen any other issues about this, but switch statements are commonly used for control flow and I was a bit suprised they were absent in Svelte.as opposed to:
EDIT: Just found this is a dupe: #530 - Feel free to close this and re-open the other issue.
The text was updated successfully, but these errors were encountered: