10:45 wait I'm a little confused. What makes the $effect or "get current()" rerun when this.#version changes? I thought it had to be inside the effect for it to trigger.
I sort of understand it now. Every time this.#version or anything reactive inside a "get ...()" changes, the get will rerun. I just don't understand why. Maybe it's a Svelte thing, maybe not.
A signal tracks who read it and reruns the code when it updates: ``` let a = $state(0) let b = $state(0) function sum() { return a + b } setInterval(() => { a += 1 b += 1 }, 1000) {sum()} ``` When you read the value inside a tracking context, it creates an effect in the compiled output and reruns when you update the value: ``` let a = state(0) let b = state(0) function sum() { return get(a) + get(b) } setInterval(() => { set(a, get(a) + 1) set(b, get(b) + 1) }, 1000) template_effect(() => set_text(text(), sum())) ``` I have a video on signals if you want to understand how they work: th-cam.com/video/1TSLEzNzGQM/w-d-xo.html
I think what's confusing for me is why does something like subscribers or even position at the end in the mouse subscriber does not need to be state sometimes. I guess at that point svelte would track it so you would need to wrap it in untrack likely so we don't run the effect when it changes but for some reason my brain is struggling with it lol. Need to remember state is only for stuff you want svelte and it's api's specifically to react to, but I don't know why I struggle with the fact that subscribers value is being changed behind the scenes
It doesn't need to use `$state` because you're just updating a regular value, and then you rerun `this.current` on change using `update`. The `MediaQuery` example makes more sense because `this.#query` is already a `MediaQueryList` that is updated, so you only have to rerun `this.current` to get the latest value from `this.#query.matches`.
They can't be referenced inside of Proxies either, which is a problem. If there is a possibility of someone needing to wrap your class instances in a Proxy I would recommend sticking with underscores.
I think now svelte have more chaos just bcs of runes plus writable,set and $ much more reactivity in chaos manner, i think its better to have clear method of getting things done in different ways
Another awesome video 👍
10:45 wait I'm a little confused. What makes the $effect or "get current()" rerun when this.#version changes? I thought it had to be inside the effect for it to trigger.
I sort of understand it now. Every time this.#version or anything reactive inside a "get ...()" changes, the get will rerun. I just don't understand why. Maybe it's a Svelte thing, maybe not.
A signal tracks who read it and reruns the code when it updates:
```
let a = $state(0)
let b = $state(0)
function sum() {
return a + b
}
setInterval(() => {
a += 1
b += 1
}, 1000)
{sum()}
```
When you read the value inside a tracking context, it creates an effect in the compiled output and reruns when you update the value:
```
let a = state(0)
let b = state(0)
function sum() {
return get(a) + get(b)
}
setInterval(() => {
set(a, get(a) + 1)
set(b, get(b) + 1)
}, 1000)
template_effect(() => set_text(text(), sum()))
```
I have a video on signals if you want to understand how they work: th-cam.com/video/1TSLEzNzGQM/w-d-xo.html
@@JoyofCodeDev Ahhh I see, that makes more sense. Will definitely check out the video right now. Thank you!
A great video would be to combine the context api and createSubscriber
1:35 The Svelte
your intro sound is like when you connect an USB like i feel that i connect with the video ready to receive your sacred bits of information :$
11 seconds ago is wild
I think what's confusing for me is why does something like subscribers or even position at the end in the mouse subscriber does not need to be state sometimes. I guess at that point svelte would track it so you would need to wrap it in untrack likely so we don't run the effect when it changes but for some reason my brain is struggling with it lol. Need to remember state is only for stuff you want svelte and it's api's specifically to react to, but I don't know why I struggle with the fact that subscribers value is being changed behind the scenes
It doesn't need to use `$state` because you're just updating a regular value, and then you rerun `this.current` on change using `update`.
The `MediaQuery` example makes more sense because `this.#query` is already a `MediaQueryList` that is updated, so you only have to rerun `this.current` to get the latest value from `this.#query.matches`.
This is game changing!!!
Oh boy, I've been away from svelte and this channel for a while and now everything are classes. I guess is time to rollback a dozen videos.
why do use #
it makes it private so it can't be referenced outside the class
They can't be referenced inside of Proxies either, which is a problem. If there is a possibility of someone needing to wrap your class instances in a Proxy I would recommend sticking with underscores.
my brain is not braining 🧠
Do you plan on attending Svelte summit 2025?
I think now svelte have more chaos just bcs of runes plus writable,set and $ much more reactivity in chaos manner, i think its better to have clear method of getting things done in different ways
you don't use them both unless you have older code that needs to be updated
@@JoyofCodeDev I think there is a lot to improve in runes and a lot to do with it, I am big fan of svelte and thank u for ur support
Actually, there is FromStore and ToStore function. To handle multiple version of svelte.
runes are the replacement of writables
This is just for backward compatibility, rich harris have said before this will be changed gradually so users have time migrate
$effect.tracking example, especially for Scott Tolinski. 😅
the docs need some love