News for hackers. Stuff that matters.
Re:Rich Harris joins Vercel to work on Svelte full time by benmccann on Thursday November 11, 2021 @04:18PM (#29193309)
But React isn't just JSX. It's also the entire runtime library, hooks, event handling, forms, state handling, etc. The example you shared is a bit too simple to understand where Svelte shines because it doesn't introduce any of those concerns.

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.

Re:Rich Harris joins Vercel to work on Svelte full time by noir_lord on Thursday November 11, 2021 @05:14PM (#29193915)
Not to mention it takes reactivity to new heights while adding amazingly little actual syntax.

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>
Re:Rich Harris joins Vercel to work on Svelte full time by Aeolun on Thursday November 11, 2021 @07:59PM (#29195190)
But what does ‘#await someFetch’ actually do? The thing I like most about react is that it’s just executing plain Javascript most of the time.
Re:Rich Harris joins Vercel to work on Svelte full time by dmitriid on Friday November 12, 2021 @02:49AM (#29197180)
> The thing I like most about react is that it’s just executing plain Javascript most of the time.

Then explain what hooks do ;)

Hooks are decidedly not Javascript (even if they look like Javascript), and are a much more weird construct than {#await promise}

Re:Rich Harris joins Vercel to work on Svelte full time by _hzrk on Friday November 12, 2021 @09:49AM (#29199752)
No, they are JavaScript, it is array based programming wrapped in a reactive functional-declarative approach. Simply array of objects cascading with state. {#await promise} is more cryptic than any useHook function implementation.
Re:Rich Harris joins Vercel to work on Svelte full time by dmitriid on Friday November 12, 2021 @04:16PM (#29204631)
> No, they are JavaScript, it is array based programming wrapped

Javascript has no support for array-based programming.

So, hooks are not Javascript: they look like regular function calls, but:

- they can only be declared and called before rendering

- they can't be called out of order

- they cannot be called conditionally

- they have to be called a specific name to be handled correctly by React runtime

- some (but not all of them) require dependency lists that determine how they are invoked

> {#await promise} is more cryptic than any useHook function implementation.

usEffect documentation is something like 20 pages long. The use of {#await promise} is immediately understandable from the code example, and its entire documentation fits on a page and a half

Re:Rich Harris joins Vercel to work on Svelte full time by Aeolun on Saturday November 13, 2021 @03:14AM (#29208285)
They are definitely javascript. I can click to definition of the useEffect function and see exactly what it is doing.

I completely agree that learning them is a bit crazy, but ultimately every hook comes down to being a function execution.

Re:Rich Harris joins Vercel to work on Svelte full time by dmitriid on Saturday November 13, 2021 @02:35PM (#29212539)
> They are definitely javascript.

How come they break Javascript semantics and execution flow?

> but ultimately every hook comes down to being a function execution.

That's really beside the point when it comes to understand what something is and using them.

{#await promise} is immediately understandable from its use.

Hooks are... well, I already said above.

Re:Rich Harris joins Vercel to work on Svelte full time by merb on Sunday November 14, 2021 @03:45PM (#29220490)
> How come they break Javascript semantics and execution flow?

wait what? since when do they break execution flow and javascript semantics?!

useEffect(function () { }); when exactly do you think the function will be called? - correct only the "framework" defines that, but that's completly normal javascript execution and semantic.

Re:Rich Harris joins Vercel to work on Svelte full time by noir_lord on Friday November 12, 2021 @02:01AM (#29196968)
Re:Rich Harris joins Vercel to work on Svelte full time by hunterb123 on Friday November 12, 2021 @11:21AM (#29200939)
His point is you don't have to read some project's documentation to know how some "await blocks" work.

With JSX you can use native JS features instead, you only need to know the language.

For example, instead of looking up how to loop in the template syntax, you use an iterator.

Re:Rich Harris joins Vercel to work on Svelte full time by noahtallen on Friday November 12, 2021 @12:03AM (#29196447)
Not just most of the time — all of the time! JSX is converted to plain JS (react.createElement) before it gets to the browser.
Re:Rich Harris joins Vercel to work on Svelte full time by tuukkah on Friday November 12, 2021 @01:08AM (#29196733)
Isn't it actually the opposite? Svelte code is compiled to plain JS whereas React has a large runtime.
Re:Rich Harris joins Vercel to work on Svelte full time by Aeolun on Friday November 12, 2021 @11:12PM (#29207292)
Nah, JSX also gets converted to Javascript. The difference is in that the React runtime re-renders whole components every time something changes, and Svelte is more granular about it even during the compilation step.
Re:Rich Harris joins Vercel to work on Svelte full time by wruza on Thursday November 11, 2021 @11:56PM (#29196421)
I’m neither of (react, vue, svelte) guy, but isn’t that snippet equivalent to some:

  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