Svelte 5 New `{let/const}` Declaration Tags
Svelte@5.56,0 Svelte@5.56,0 New href="https://svelte.dev/docs/declaration-tags" target="_blank" rel="nofollow noopener noreferrer">{let/const ...} - a more powerful alternative {@const ...}: 1. You can declare it anywhere {const hello = 'hello'} {hello}
{const hello = 'hi'} {hello}
{hello}
{hello} 2. It can be used with $state and $derived {#if editing} {let name = $state(user.name)} {const greeting = $derived(Hello ${name})}
{greeting} { user.name = name; editing = false; }}>save {/if}
Funny, but very strange, especially with the state. I don’t like to interfere with logic.
The cow!
I am not cursing this reality.
What does not like this?
I don't like to bother tagging with logic
But now the snippets can have their state.
It makes sense, but it still seems to be a bit of a bit and for this it seems like another mechanism has to be invented.
Here is purely my position that the patterns should be as dumb as possible, and everything else is expressed either by logic or composition.
This is uncomfortable.When you do a lot of stuff, it becomes clear very quickly.
When there is just a logic inside the templates and there should not be a lot to divide into components - a straight base to keep the balance of logic in the templates.
No, not the base. It all depends on the situation.
The script is only needed for imports.
Well, no, just sometimes you need some microcomputing, and it’s not convenient to carry them into scripts.
And eventually the old syntax {@const ...} will be deprecated?
Am what is it?
What’s the point of leaving it? it’s confusing.
In the script, you can confuse both reactive and non-reactive variables.
No yes, but that’s something else.
Sorry, you are right.
That would be logical, or it would just be a confusion.
Yes, apparently breaking changes were scared and didn't want 6 apaths because of this.
They seem to go away a little bit.
There is no perfection anywhere except let/const.
There may be a problem with reasoning on this topic.
Yes, it would be interesting to read now the only guess - the departure from breaking changes with the existing @const
Here you need to read https://github.com/sveltejs/sveltejs/issues/16490
By the way, in this regard, in the first case, we have a sequential calculation and everything is OK, and in the second we produce new elements in the reactive chart for each list re-render?
Because it’s just a piece of JS, there’s no special transformation.
In a few years, JSX will be over.
The tsrx model is closer.