←back to thread

Svelte 5 Released

(www.npmjs.com)
390 points begoon | 3 comments | | HN request time: 0.61s | source
Show context
notpushkin ◴[] No.41890141[source]
Good work! I’m not really sold on the runes stuff though (tldr: https://svelte.dev/blog/runes)

The old way is a bit “magical” in a sense that it does some stuff under the hood to implement the intention behind your code, but it reads really straightforward:

  let counter = 0;
  // ...
  <div>{counter}</div>
`let` in a .svelte compoment makes a variable reactive. If your state is outside a component, you use stores.

With the `$store` rune, the way you make reactive stores inside and outside components is the same, but it only works in .svelte.js/ts. The unification is great – but why not just use `let` in .svelte.js, too?

  // counter.svelte.js
  export function createCounter() {
    let count = 0;
    return {
      get count() { return count },
      increment: () => count += 1
    };
  }

  // App.svelte
  <script>
    import { createCounter } from './counter.svelte.js';
    const counter = createCounter();
  </script>

  <button on:click={counter.increment}>
    clicks: {counter.count}
  </button>
I understand it can be really tricky – e.g. you might want to use let for things that are not modified in runtime and do not need reactivity, but it should be possible to determine in compile time. (Actually after writing this all up I think I know why Svelte went with runes instead, haha!)

But again – really good work and I hope to try it out on my next project!

replies(2): >>41890504 #>>41891025 #
papichulo2023 ◴[] No.41890504[source]
My only problem with this is because now is more verbose, why I should use Svelte over Vue? Arguably a more stablish framework.

No shadow dom and a better template directives? Maybe, not sure.

replies(1): >>41890627 #
1. notpushkin ◴[] No.41890627[source]
I don’t have a definite answer as I haven’t worked with Vue that much. Still, I like Svelte syntax a bit better (e.g. {#each x in xs} vs. v-for), and yeah, all the compile time reactivity stuff works out pretty well in terms of performance.

The runes are still optional, I think, and you can still use the old syntax. Not sure if that will be true in Svelte 6 though!

replies(1): >>41891763 #
2. benmccann ◴[] No.41891763[source]
The old syntax is considered legacy and it is recommended to upgrade. There is a migration tool to do most of it automatically for you.
replies(1): >>41893909 #
3. notpushkin ◴[] No.41893909[source]
Is there a timeline for the deprecation already? Can I still enjoy it for just a bit longer? ;-;