Different Ways To Share State In Svelte 5

Different Ways To Share State In Svelte 5

Joy of Code

54 года назад

9,590 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@thedelanyo
@thedelanyo - 21.11.2024 19:49

All these examples are really nice, but are only around `count`, yet no one is using count in production 😊😊😅

Ответить
@mit3y
@mit3y - 21.11.2024 18:09

Great video -- i also really like the theme of your browser, what browser is it? how did you theme it?

Ответить
@EliSpizzichino
@EliSpizzichino - 21.11.2024 09:57

The state management docs should be updated with at least a link to this video

Ответить
@lifeparticles
@lifeparticles - 21.11.2024 04:11

Thanks!

Ответить
@ryansolid
@ryansolid - 18.11.2024 22:49

What's interesting is after that whole video of explanation of all the ways to wrap and share state there was no solution that actually got away from needing to call a function or a `.value` when combined with destructuring. Even with the compiler this problem isn't completely solvable ergonomically. The class trick of not needing to write the getters is nice but doesn't change the consumption side. If this was accepted from the beginning it could have saved everyone a lot of time.

Ответить
@viniciusrvieira
@viniciusrvieira - 18.11.2024 14:59

Valeu!

Ответить
@justingolden21
@justingolden21 - 16.11.2024 10:26

Super well done, both detailed and yet not confusing

Ответить
@mattl7599
@mattl7599 - 15.11.2024 23:24

Classes look so good. I think that’ll be my preferred approach going forward.

Ответить
@joshcollinsworth9471
@joshcollinsworth9471 - 14.11.2024 17:54

This is exactly the primer on Svelte 5 shared state I needed. Thank you!

Ответить
@marlopainter8246
@marlopainter8246 - 14.11.2024 12:05

This was the best video of yours, and the best Runes video I've seen. You completely demystified them AND opened me up to using Classes. Thank you! As a bonus, I love your presentation, delivery, and humor you mix in. Your love of coding and Svelte shine through and is infectious.

Ответить
@adrienetaix
@adrienetaix - 13.11.2024 11:55

That should be a page in the Svelte documentation (or maybe I missed it), it's so clear and with lots of options !

Ответить
@f-Yoda
@f-Yoda - 12.11.2024 09:29

And they told me rxjs observables in angular are overengineered... 🥲

Ответить
@pixsa
@pixsa - 12.11.2024 00:13

Give me that Lualine config, i am struggling

Ответить
@erickmoya1401
@erickmoya1401 - 11.11.2024 22:02

Man. You are making enemies all around. XD

Ответить
@thedelanyo
@thedelanyo - 11.11.2024 21:55

I think with the power of store and $state much boilerplates can be reduced

Ответить
@gorbulevsv
@gorbulevsv - 11.11.2024 17:11

As I understand it, all runes work with signals. I have a desire to replace all the old designs with runes, but then I understand that this is wrong.

Ответить
@gorbulevsv
@gorbulevsv - 11.11.2024 17:08

Thank you very much for the valuable information, we will try it.

Ответить
@anonimoanonimo1750
@anonimoanonimo1750 - 11.11.2024 15:52

every time i see your videos i start crying, cause they are too good!

Ответить
@lungarella-raffaele
@lungarella-raffaele - 11.11.2024 11:05

Gold content as usual 🙏🙏

Ответить
@helsingking281
@helsingking281 - 11.11.2024 08:43

I bet 99% of shared state use cases can just be dealt with proxied state and it should probably be the first thing in the docs.

Ответить
@helsingking281
@helsingking281 - 11.11.2024 08:13

JSX is everything I was thought not to do some 20 years ago. What happened to "never mix business logic with presentation"? It's impossible to read. Because of the praisal of JSX and contantly jumping out of topic and losing the train of thought, i didn't get past 2 minute mark. Thanks for the attempt, i suppose.

Ответить
@EnricoSacchetti
@EnricoSacchetti - 11.11.2024 07:10

Great breakdown!

Ответить
@АртемЗеленов-л1р
@АртемЗеленов-л1р - 10.11.2024 13:50

how cool is this

Ответить
@whydoyouneedmyname_
@whydoyouneedmyname_ - 10.11.2024 12:23

Don't Fear the Runes

Ответить
@TheGargalon
@TheGargalon - 10.11.2024 01:14

$count was 100x better than count.value and I will die on that hill

Ответить
@Александр-ч4п5ъ
@Александр-ч4п5ъ - 10.11.2024 00:56

This should be in svelte tutorial, thanks a lot.
Proxied state is my fav

Ответить
@rogerpence
@rogerpence - 09.11.2024 21:41

This video goes well beyond the obvious and explains runes better than other video available! Even the ones that Rich Harris has made! Great job.

Ответить
@supbra1
@supbra1 - 09.11.2024 21:10

I would love for you to do AppWrite and Svelte 5 integration tutorial! (to login, fetch and set user data, update database, upload files and so on).
Even if it will be a paid course

Ответить
@skowne
@skowne - 09.11.2024 13:09

Good video!

You can do this when destrucuring:
let {count, increment} = $derived(counter)
then you don't have to do count.value

Ответить
@AmxCsifier
@AmxCsifier - 09.11.2024 11:57

I love your content, very well made and I learn a lot from it

Random advise: drop the "right", no offense meant 😄🫣

Ответить
@paololucchesi2827
@paololucchesi2827 - 09.11.2024 11:33

TLDR: Imported unwrapped states cannot be reactive

Ответить
@StephenFosterUK
@StephenFosterUK - 09.11.2024 11:32

The timing of your content is always perfect, I'm exhausted with people banging on about it being like XYZ or ABC.. if you use them you will see its nothing more than surface.

On the complains about needing to box things its always a trivial example like a single number counter.. in the real world you would want some methods to go with that state and so you are naturally going to end up with a wrapped object from a functionlike or class.

You also get extra points for the casual use of "willy nilly" 10/10 😂

Ответить
@ransomecode
@ransomecode - 09.11.2024 11:13

why did the svelte team not consider boxing the primitives at compile time
```
// myfile.svelte.ts
export let count = $state(0)

// mycomponent.svelte
import {count} from 'myfile.svelte.ts'
<button onclick={() => count++}>{count}</button>
```

```
// myfile.compiled.ts
export let count = $.state(((value) => ({valueOf: () => value}))(0))

// mycomponent.compiled.svelte
import {count} from 'myfile.svelte.ts'
<button onclick={() => count.set(x => (+x)+1)}>{count.get(x => +x)}</button>
```

Ответить
@simpingsyndrome
@simpingsyndrome - 09.11.2024 09:04

Can we have type safety in .svelte?

Ответить
@akza0729
@akza0729 - 09.11.2024 08:38

Can you make a video about how we can do API multiple middleware per routes in SvelteKit such that the API can be used by other Frontends apps too and not be dependent on +layout or hooks.

Ответить
@radhy9173
@radhy9173 - 09.11.2024 08:30

Using Class is very cool in Svelte as it will automatically write setters and getters for you in the compiler. However one thing that I found the weakness of doing this is the typing because you can't set the initial value for $state in the constructor. Let's say for example:

class Monster {
stats = $state<Stats>()
constructor(data:Stats){
this.stats = data
}
}

typescript would scream that .stats could be an undefined so you would have to access it with something like monster?.stats every time. You could pass an initial value to form the shape but then again you would need to worry about side effects in case you're using $effect with it since the constructor would assign the state for the second time. In this case it would just be better to use something like a function wrapper although by doing it you would need to define the setters and getters yourself.

Ответить
@bene0817
@bene0817 - 09.11.2024 08:30

Well if svelte used a compiler that is not module scoped, they would be able to turn: export let count = $state(0); into a signal under the hood. So that import count would become import count, setCount

Ответить
@saiphaneeshk.h.5482
@saiphaneeshk.h.5482 - 09.11.2024 07:23

Cool, from svelte 5 are everything signals? And if so, how does it differ in perf or build size from solid?

Ответить
@dei8bit
@dei8bit - 09.11.2024 05:24

hahaha how I love you bro!! !!, your videos are really a joy, very enriching by the way.

Ответить
@Lemmy4555
@Lemmy4555 - 09.11.2024 04:45

Do a video about integrate svelte runes with React to replace Redux xD

Ответить
@bradyfractal6653
@bradyfractal6653 - 09.11.2024 03:58

Thanks for making this! 🙏

One thing I don't understand — why is typing a word like ".value" or typing two parens like "()" to call a function such a big deal? I don't mind typing words or parens (or hitting tab and autocompleting them), to me it's such a minor thing it's not even worth thinking about... let alone being so consequential that my "Developer Experience" is noticeably impacted. I personally like Vue's approach here — you never have to waste brain cycles thinking about it when it's "always .value" instead of "maybe .value, maybe nothing"... but just like the alleged "DX" stuff, it's not really that big of a deal.

Ответить
@Lapatate-s1l
@Lapatate-s1l - 09.11.2024 03:31

Best video of svelte out there . ❤

Ответить
@devgauravjatt
@devgauravjatt - 09.11.2024 02:37

My memory is out 😂, super sir 🙏

Ответить
@prestongovender5715
@prestongovender5715 - 09.11.2024 01:36

When are you doing a full project using svelte? 🙂

Ответить
@stanislavdunajcan2703
@stanislavdunajcan2703 - 09.11.2024 00:53

Amazing explanation!!! Thank you.

Ответить
@fottymutunda6320
@fottymutunda6320 - 09.11.2024 00:09

how do you navigate so fast?

Ответить
@StephanHoyer
@StephanHoyer - 09.11.2024 00:08

Again solving problems that you should not have in the first place

Ответить