Live data from Hacker News

Svelte is a language

gist.github.com

81–90 of 95 posts

Re: Svelte is a language

#81

Earlier quoted context omitted.

Infrastructure adapters are becoming table stakes for frontend frameworks.

Which other frameworks have them out of interest? Sounds like a great feature. AFAIK Next doesn’t and it’ll be interesting to see if it gets them given it’s from Vercel. When I tried Remix you had to choose your deployment when initialising a project and it didn’t look trivial to change it, but that was a while ago.

Solid & Astro.

Re: Svelte is a language

#82
post #52

Earlier quoted context omitted.

Angular template syntax is correct HTML syntax. It's nothing like the examples abovd.

https://angular.io/guide/binding-overview Haven't looked at angular since 2015 to be honest, but it still seems like they do weird html stuff to me, such as: {{customer.name}} or Type something: {{customerInput.value}}

Angular will soon be migrating to the Svelte style of conditional flow control. https://github.com/angular/angular/discussions/50719

Re: Svelte is a language

#83
post #56
post #51

Earlier quoted context omitted.

You're telling me on:click={toggle} is nothing like (click)="toggle()"?

it's not. `toggle` is a pointer to a function name and "toggle()" appears to be an expression which is parsed and then executed (scary). you can on on:click={() => toggle()} in svelte which is more similar, but it isn't parsed and executed, it is a pointer to an anonymous function which is directly executed. on:click={toggle()} in svelte would run the function immediately (probably not what you want) and return the r…

Not a pointer to a function. In JS, functions are first class objects. You might as well say toggle() is an invocation of a pointer to a function.

has existed since the dawn of JavaScript in Netscape Navigator 2.0 Beta Gold. Your complaint about the syntax is in fact baked into the foundations of the web.

Re: Svelte is a language

#84
post #15

The really exciting thing about svelte is getting rid of the virtual Dom. Having everything just be explicit JavaScript code that modifies the Dom manually makes for really readable code. If you have not tried it, got to the svelte tutorial and look at the output code. It's awesome.

First we were excited for the virtual DOM which is good for batching updates, flexibility, efficiency, etc. But now the cool thing is to get rid of it?

Browsers are not the same as they were ten years ago.

Re: Svelte is a language

#85
post #30

Earlier quoted context omitted.

> Having everything just be explicit JavaScript code This is funny because it's exactly the reason I prefer react

Agreed, I want markup in my logic — not logic in my markup

CSS and HTML in JS was always a bad idea. HTML can live on its own. JS is a dependent technology, on the same level as CSS. The HTML was always the foundational technology.

Centering JS has always been like putting the cart before the horse.

Re: Svelte is a language

#86
post #46

Earlier quoted context omitted.

I disagree. But I am someone who deals with frontend tech sporadically as opposed to spending all/most of my time working on UI. I was excited about svelte, but have found that coming back to my svelte project after a month or two of not using it was arduous because of all the myriad language level things. There are just too many little svelte specific things to keep track of in head. In contrast coming back to a rea…

You can create a shared store and mutate it from any component, not sure what’s missing there.

Or use a module context depending on your scoping needs. Agreed, not sure what the GP is talking about.

Re: Svelte is a language

#87
post #76

Svelte is a major improvement on vuejs. It is a pleasure to work with. I can’t stand react / JSX. Highly recommend anyone who preferred vue over react to give svelte a try.

I preferred Vue over Angular. I certainly feel attracted to Svelte. I'm currently finally doing a big React project, and boy, the complexity is spiraling a bit out of control. It's certainly not DRY.

Big ball of mud. The muddiness is always exacerbated when increasing the number of developers, especially when they disagree on Hooks.

Re: Svelte is a language

#88
post #5

Earlier quoted context omitted.

Or maybe one day people will realize render functions explicitly listening to event emitters is actually a better pattern than implicit reactivity.

I think it is a shame that the Observable proposal [1] still seems somewhat stuck in Stage 1. It's a better idea than just raw event emitters because of composability (if no other reason). Making Observables "first class" could go a long way to unifying a lot of reactivity patterns in various frameworks, in theory at least. To be fair, Observables and especially Observable composition has a rough learning curve and m…

Svelte Stores: observables without all the boilerplate. If you want to do manual subscribing and unsubscribing, you can of course. Stores really are quite flexible if you really want to dive deep into them.

Re: Svelte is a language

#89
post #46

Earlier quoted context omitted.

I disagree. But I am someone who deals with frontend tech sporadically as opposed to spending all/most of my time working on UI. I was excited about svelte, but have found that coming back to my svelte project after a month or two of not using it was arduous because of all the myriad language level things. There are just too many little svelte specific things to keep track of in head. In contrast coming back to a rea…

You can create a shared store and mutate it from any component, not sure what’s missing there.

I was primarily saying that I find the DX of vue's reactivity to be more intuitive in the context of my application. I didn't intend to say there was something that was possible with vue which wasn't with svelte.

Last I checked (and things may have changed since) is that svelte didn't support transparent reactivity for deeply nested objects. So something like `$myStore.foo.bar = "baz"` wouldn't trigger a component update, you need to remember to use .set, .update etc. You could assign to local reactive variables but you couldn't assign to stores.

I am sure the library authors made these trade offs thoughtfully, I was just disagreeing with the blanket statement that Svelte is generally a major improvement over Vuejs.

Re: Svelte is a language

#90
post #79
post #65

Earlier quoted context omitted.

While this is all technically true, I don't think it's all that helpful a thought process to have when approaching Svelte. Yes, Svelte files are syntactically valid HTML, Javascript, etc, but they have very different semantics. Take the ability to reference functions in HTML - this is simply not possible in normal HTML, where inline event handlers instead are passed Javascript expressions to evaluate. It's definitely…

Click me 100% valid HTML and within "the normal realm of HTML". The event is passed as a parameter to the function. Has been available since the introduction of JavaScript. Predates addEventListener(…) and its ilk by a few years. Yes, "$:" as a labeled break exists outside JavaScript proper. That said, given the rare cases where anyone uses a labeled break and how unlikely that labeled break would be named "$", it se…

> 100% valid HTML and within "the normal realm of HTML". The event is passed as a parameter to the function. Has been available since the introduction of JavaScript. Predates addEventListener(…) and its ilk by a few years.

Like I said, it's valid HTML, but it doesn't do what you're describing (and you can try it out fairly easily in your browser). The "onclick" handler executes the code string that it's given, working essentially the same way as `eval` or the `new Function("...")` syntax. It does not take a function pointer.

So in this case, the only thing it executes is a variable pointing to a function, which doesn't do anything because the function isn't being executed. You would need to add the function brackets to get any sort of effect.

This is the crux of the issue: Svelte is an additional language that happens to use the same syntax as HTML and JS, just with different (in some cases very different) meanings. You are not just writing "explicit Javascript code", you're writing Svelte code (which in most cases is probably very easy to pick up if you know Javascript, but it's still a different language).

Compare and contrast with, say, Typescript, which is syntactically different from Javascript, but semantically identical - just remove the types, and you have normal Javascript. (In fairness, with old decorators and enums, this isn't quite true, but it holds in general.)

To be clear, I don't think that's saying that one thing is better than the other, or that Svelte is bad because it's a new language or something. I think reactive primitives in Javascript are important, and adding them directly into the syntax of the language is a really clever way of solving a lot of problems in this space. I'm not sure if it's the solution I like the best (I've really enjoyed working with SolidJS signals recently, which provide some of the same ideas with a more typically Javascript-like API), but it's good to see experimentation here.

Post reply on HN