News for hackers. Stuff that matters.
Re:Svelte and TypeScript by nickreese on Tuesday July 21, 2020 @03:41PM (#23910167)
Having talked to a ton of friends about Svelte, Typescript support has always been the biggest push-back for adoption.

Stoked for Svelte to support it.

We've been using Svelte in production and I can't speak highly enough about the developer experience. Absolute game changer for our ssite that use it.

Re:Svelte and TypeScript by rawoke083600 on Wednesday July 22, 2020 @02:57AM (#23914595)
I LOVEE Svelte, if your any sort of dev... try it out. It's a super small API, you can learn in a few hours. I'm not a frontend dev by trade, but compared to Angular(prev fav) it's soo much simpler.
Re:Svelte and TypeScript by G4BB3R on Tuesday July 21, 2020 @05:05PM (#23910997)
Do you use pure svelte or with sapper? how is it compared to react?
Re:Svelte and TypeScript by nickreese on Tuesday July 21, 2020 @05:33PM (#23911236)
We wrote our own SSG for https://elderguide.com. We tried Sapper but our data flow and routing needs were to complex and not a fit.

Svelte is a dream compared to React. That said, I've never felt like React was the right solution for the problem.

I've extensively used Gatsby and for static sites, React is absolutely overkill. For apps it can be nice.

In both cases my go-to these days is Svelte.

Re:Svelte and TypeScript by uxcolumbo on Tuesday July 21, 2020 @05:51PM (#23911379)
Nice site and real snappy.

I haven't used Svelte yet - but am interested.

Can you explain a bit more about what you mean with your data flow and routing needs were too complex for Sapper.

And what makes Svelte a dream compared to React?

Re:Svelte and TypeScript by nickreese on Tuesday July 21, 2020 @07:04PM (#23911874)
Sapper's data flow uses a file based routing system similar to /blog/[id].svelte becomes /blog/:id/. If you are familiar with Next.js then you'll recognize this.

Our primary problem with Sapper is that we wanted our URL structure to be such that you can't tightly route a template/view by just looking at their URL. /senior-living/blog-post/ and /senior-living/nursing-home-name/ need to live side-by-side.

This forced us to build our own custom routing system, what we call an "inverted router" for our SSG.

Also we found it less than elegant to use DB queries with Sapper and had a lot of concerns about what was actually on the client and what wasn't.

As for why we swear by Svelte:

* Bundle size. For SEO focused sites React is overkill.

* Stores compared to Mobx or other state management

* $: reactivity

* No css-in-js hacks required. Css is automatically scoped, but can be easily globally scoped.

* Single file components are just beautiful.

* We've built in the ability to SSR our entire site, but only hydrate the parts that need to be. This is a game changer for page size and not pushing your data twice to the client.

Re:Svelte and TypeScript by nickreese on Tuesday July 21, 2020 @07:31PM (#23912063)
We're working on open sourcing our entire SSG in the next 3-4 months.

As it currently stands the SSG is super opinionated and we did several things quite unconventionally, so we are validating some of our ideas by building out another site besides elderguide.com to make sure these decisions indeed work across a lot of use cases.

Once this second site is out the door we want to add TS support natively to the SSG and then we'll release it.

Re:Svelte and TypeScript by jfengel on Wednesday July 22, 2020 @10:52AM (#23917653)
I just ran through the tutorial, and I really liked the $-for-reactivity part. That's clever and good.

But then they introduced a whole new language for loops and control structures, and I really prefer JSX for that. JSX nails a sweet spot of bog-standard Javascript/Typescript, with enough HTML syntactic sugar to very natural web-pagey parts. As long as TS/JS is already in there, I'd rather use it everywhere.

I don't know it well enough to know if that's a necessary feature, or if the language will evolve to something closer to my sensibilities. I will probably give it a try in the future, especially if I want something more performance focused. (The virtual DOM overhead is real and the separate state mechanism is far less elegant than Svelte's solution.)

Re:Svelte and TypeScript by uxcolumbo on Wednesday July 22, 2020 @01:51PM (#23919663)
Re:Svelte and TypeScript by Kabootit on Thursday July 23, 2020 @01:25PM (#23929771)
> Single file components are just beautiful.

Not only in structure, but how they compose. The typical top-down tree components composition is typical. What is not immediately obvious is how child components can expose functionality upstream. So simple.

Re:Svelte and TypeScript by uxcolumbo on Tuesday July 21, 2020 @07:20PM (#23911975)
Thanks for clarifying.

Is your custom built routing system open source?

I can imagine the Svelte community could benefit from it.

Re:Svelte and TypeScript by danr4 on Tuesday July 21, 2020 @07:33PM (#23912092)
Sounds very interesting. Any plans on open sourcing?
Re:Svelte and TypeScript by The_rationalist on Tuesday July 21, 2020 @04:17PM (#23910528)
What would it bring in ergonomics and expressivity versus Vue ?
Re:Svelte and TypeScript by kjksf on Tuesday July 21, 2020 @05:33PM (#23911238)
Those things really need to be experienced to be understood, so just try Svelte in a toy project. Or go through the interactive tutorial https://svelte.dev/tutorial/basics

I used both React and Vue and am now only using Svelte.

You type less. Significantly less.

The thing you type is simpler. I tend to get lost in Vue's object structure.

What you type is closer to HTML/CSS/JavaScript than what you type in React/Vue. It's therefore easier to understand what gets generated.

The seamless reactivity is awesome.

Scoped CSS support is built-in so you don't need css-in-js hacks.

Built-in support for data (stores) is excellent.

The final bundle is smaller and faster.

There's more but the above are the major points.

The only downside is smaller ecosystem. But I don't care because I'm in the camp of minimizing my dependencies.

Re:Svelte and TypeScript by preommr on Tuesday July 21, 2020 @09:17PM (#23912941)
> Scoped CSS support is built-in so you don't need css-in-js hacks.

vue/react also have scoped css, but built into the building process using loaders rather than being a feature of the frameworks.

Re:Svelte and TypeScript by buzzerbetrayed on Wednesday July 22, 2020 @12:42AM (#23913994)
Less time setting up build processes is another win you git with Svelte, in my experience.
Re:Svelte and TypeScript by nickreese on Tuesday July 21, 2020 @05:41PM (#23911308)
I haven't used Vue extensively since what was probably v1 so I'm likely the wrong person to comment on this.

That said, I find that Svelte aligns more with my/our team's mental model about how the web should work and that is why went with it for our sites.

Just like with Vue you can write your JS/CSS/HTML in a single file, but the reactivity and state management is much easier to reason about than what we've seen elsewhere.

- `$:` is great.

- Stores and derived stores are amazing.

- Data binding / rerendering is really intuitive.

That said, the biggest headache in building our own SSG was getting SSR/Hydration working well, but that was mainly fighting Webpack and got easier when we went with Rollup.

edit: formatting.