by RoboticWater · 5y ago · 0 comments
And the reason these things change is because that's what needed changing. One of the topline features of Svelte is that is has less boilerplate than React, and it achieves that quite handily. Unless you're criticizing particular constructs in Svelte that are unjustifiably different, I don't think unfamiliarity is that damning a criticism.
Maybe I'm just used to switching up languages on a regular basis, but the idea of having to learn different language constructs for loops and the like doesn't seem that herculean of a task.
<ul>{myItems.map({id, title}) =>
<li key={id}>{title}</li>
}</ul>
vs... svelte <ul>{#each myItems as item}
<li>{item.title}</li>
{/each}</ul>
One is literally just javascript and html the other is an entirely different template language. You might say... JSX is not HTML... well it's very very similar... If you know HTML you JSX is very intuitive.By having it's own templating language, Svelte is able to compile the templates to JavaScript in a way that addresses many of those concerns in a way that I think it easier to deal with as an end user of the framework.
If Svelte were using JSX, I don't know that it'd be possible to do everything else that it does so simply because you can write anything that's valid JavaScript in JSX whereas Svelte has just a couple of basic control structures that its compiler can parse and convert to runnable code.
When property changes, the fetch refires, loading appears until the fetch resolves then it displays whatever array someFetch resolved to.
I came from Vue and that plus the way Svelte does stores (literally nothing special about them) was a breath of fresh air.
<div>
{#await someFetch(property)}
<div>Loading...</div>
{:then data}
{#each data as item, index}
<div>{item}</div>
{/each}
{/await}
</div> div
Await promise={mypromise}
div Loading…
{res => res.map(…)}
div Error: {err => err.message}
(writing in pug-like because I can’t stand closing these tags on the phone)Isn’t it easier in both react and vue to create Await component with children=(ifwaiting, ifresolved, ifrejected) than suffering all over the code?
Edit: I messed data flow up in the error handler, wontfix but you get the idea
That's a poor assumption that appears to be based on your personal preferences and what you're comfortable with. I personally find both require some learning, but prefer the svelte version.
This is evident when comparing conditionals, loops, etc. Instead of learning template syntax you simply use JS syntax, albeit a declarative subset (no branches).
JSX is simply syntactical sugar for nested JS, you can use it without, but it's prettier with.
One could add this syntactical sugar natively to the language spec, in fact E4x (ECMAScript for XML) share some properties w/ JSX and was once proposed to the spec.
edit: instead of downvoting, please voice how you disagree with my assessment
The word 'each' conveys the intent of this code way more explicitly.
Repeating it over and over again does not make it true.
The author is wrong. Most of his statements are about React, not JSX.
It's syntactical sugar for nested function calls, that's all. Brackets are turned into function statements, attributes are turned into object props.
The author conflates React properties with JSX, which is wrong. The author also confused JSX limitations, you cannot do statements because it's a single expression.
Please go read the JSX spec instead of some random blog post.
That should have been the end of this discussion and fight that you picked about your incorrect statement that "JSX is JavaScript". You just unwittingly undermined and terminated your own argument by linking to the JSX spec itself, which clearly and explicitly says you are wrong, in BIG BOLD WORDS.
As JimDabel said, "They wanted to be 100% clear about it." So stop repeating something that the JSX designers so insistent is not true that they put it in bold at the top of their design specification.
You already won this argument, for the "JSX is NOT JavaScript" side. It's over.
> JSX is an XML-like syntax extension to ECMAScript without any defined semantics. It's NOT intended to be implemented by engines or browsers. It's NOT a proposal to incorporate JSX into the ECMAScript spec itself. It's intended to be used by various preprocessors (transpilers) to transform these tokens into standard ECMAScript.
Further down:
> Why not just use that instead of inventing a syntax that's not part of ECMAScript?
It is not JavaScript.
At this point the "is JSX just javascript" discussion has gone on a little to long imho. It feels like "is html a programming language". We all have strong convictions about the answer but it doesn‘t matter, really.
It‘s interesting that fans all of 3 frameworks constantly claim that it’s "just“ or "closer to vanilla" html or js. Should we really care anymore?
const a = <div prop={expression()} />
is a DSL for: const a = factory('div', {prop: expression()})
is only a DSL to create tree structures (React is another story, you can use JSX without React).Keys are a hugely leaking abstraction, but are inevitable when you bridge a declarative immediate mode rendering into a stateful one.
I agree. As long as you understand the basic concepts, it's only a matter of learning the syntax, which is really not as big of a deal as the person you replied to is making it out to be.
We can have a debate on unidirectional data flow vs 2-way binding, how each framework manages state changes, how opinionated each framework is... How mature and vibrant each developer community is... etc. These are all another discussion though. My question is why must we reinvent the wheel again and again.
So you want all of these to be a universal-template-language - (D)HTML ?
You are a programmer, you will need to learn new syntax a few times in your career.
If some of the "biggest" complaints are "oh no I have to learn how to write for-loops again" - I guess svelte is doing the important stuff right.
Wayyyy back in the day(ok not that long ago - 80/90's) when I was learning a new lang (Pascal,C, C++) I used to tell myself If I can get an working example of:
1) "user-input (readline,scanf etc)"
2) "printing input/output"
3) "calling functions/procedures"
4) "Do the loops + conditionals"
5) "file I/O"
6) "Memory schematics"
You basically mastered the "building blocks/mrk(min-req-knowledge)" of the new lang and like maths you only need now practice or a good project.
TL;DR If you are a professional-career-programmer, learning "new syntax (we used to call them keywords)" is a requirement.
This comment had no context...
You don't have to even
import React from 'react';
anymoreuseState is also something svelte eliminates, though I personally prefer to keep that explicit.