-
Notifications
You must be signed in to change notification settings - Fork 82
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
New template syntax #9
Comments
I think Rich is more interested in pushing for a HTMLx community spec than completely changing the way Single File Components work in Svelte. This would push Svelte even further away from what other frameworks are doing with SFCs which is probably the opposite of what we really want. It really just looks like JSX to me but in a I also think there are probably some technical issues here that would make static analysis more difficult. Executing arbitrary javascript wherever you want in the |
I don't understand what you mean. Most frameworks use a different way of writing templates. What is the difference between... {#if foo}
<p>Hello</p>
{/if} ... and... if (foo) {
<p>Hello</p>
} ...for you? Did you look at Vue? They use the
I think the opposite is happening. Look at the big three (React, Vue, Angular), they all have their own way of writing templates and unfortunately HTMLx won't change that. Why they have not adopted Mustache already? Because they want to come up with their own that fits better. But what all frameworks have in common is to write JS and this could convince users of React but also newcomers that know JS. I think it's a great idea to use a unified template (HTMLx ) but also HTML will change (maybe with control flow, event handling, ... (1)) over the years and the standard may look different compared to HTMLx. Then where is the place for HTMLx (is theoretically I know)?
Why not HTML + JS = HTMLx?
Have you ever worked with a big complex Vue or Angular template? Find something like this between hundreds of tags if the syntax highlighting doesn't fit... JS with HTML tags are great landmarks compared to custom tag attributes and even a cleaner version of Svelte's current landmarks.
Yep, that could be challenging. But I think React will heading in that direction (if they can make it possible - why should they still using the (1) The Angular team chose their tag attributes (e.g. |
Yes, they do but none of them allow arbitrary javascript anywhere in the template it is finely controlled. This deviates from that, in fact that is it's defining feature.
Yes, and I disagree with their design choice regarding control flow. I think using directives to augment elements and components as well as dealing with control flow is a mistake. Having separate control flow syntax is clearer. I did say that my comments regarding having distinct syntax for control flow was personal opinion.
And you should look into how they hope to achieve that. It is a complex process and will take a long time to come to fruition. Facebook have lots of resources and even they have said that prepack will be a multi-year project. I don't think this discussion will lead anywhere. |
Thanks for the suggestions @akaufmann! We did have a fairly wide-ranging discussion about template syntax ahead of v2 — sveltejs/svelte#1318. In that thread we discussed a number of ideas, including have a leaner block declaration not completely unlike the The static analysis considerations make things like Given how substantial the changes already are going from v2 to v3, I don't think it's wise to introduce additional changes to the template syntax without good reason, so I'll close this issue. |
Many thanks @Rich-Harris & @pngwn for clarifying the current situation. I developed the idea because the HTMLx control flow in combination with HTML tags feels a bit inappropriate and (of course) JS doesn't make it any better, but because they are standards and JS control flows comes very close to the HTMLx control flows. A syntax that goes even further towards Svelte's ideas (using standards) and what I hadn't suggested because it is different to the current syntax, would be HTML custom tags. And with VS Code v1.30 support for HTML custom tags and better tooling for that (https://code.visualstudio.com/updates/v1_30#_html-custom-tags-attributes-support), this would take Svelte a step further in that direction. <svelte:if cond="currentUser">
<div>Hello {currentUser.name}</p>
</svelte:if>
<!-- or -->
<template if="currentUser">
<div>Hello {currentUser.name}</p>
</template>
<!-- or -->
<if cond="currentUser">
<div>Hello {currentUser.name}</p>
</if>
<!-- It doesn't have to be like this, but you're getting the idea :) --> But no matter if something like this ever comes to Svelte, I would like to thank you @Rich-Harris for your great work on Svelte/Sapper. It's just fun to work with and with Svelte v3 it gets even better. |
@akaufmann that feels a lot like directives in Marko: https://markojs.com/docs/syntax/#directives. While Marko did bring some interesting ideas to the table, I find Svelte's approach to be more concise and easier to reason about. |
@maxmilton thank you for bringing Marko to my attention. We did a POC and it looks really promising, especially the performance of the SSR and the features available for it. We are looking forward to what Marko 5 has to offer compared to Svelte/Sapper. |
Since Svelte v3 is on its way and questions the status quo in the UI framework world again, I just wanted to come up with an idea how to make the template more compatible with JS. Maybe it was already in discussion for v2 or v3, so please forgive me if that was answered.
Pro:
Cons:
What do you think? Is this something that would be possible? What disadvantage/advantage do you see?
The text was updated successfully, but these errors were encountered: