Let's Make A Todo App Using Svelte 5 Runes

Поділитися
Вставка
  • Опубліковано 27 лип 2024
  • Let's explore and make a todo app using Svelte 5 runes to understand how magical they are.
    🔴 Patreon: / joyofcode
    𝕏 Twitter: / joyofcodedev
    💬 Discord: / discord
    🔥 Uses: www.joyofcode.xyz/uses
    🔗 Todo App: www.sveltelab.dev/8au5gkb77nt...
    🔗 Svelte 5 Template: www.sveltelab.dev/?t=five
    🔖 Timestamps
    0:00 Intro
    0:56 Setup
    1:38 Creating Todos
    5:27 Adding Todos
    8:40 Editing Todos
    12:26 Toggle Todo Completion
    13:51 Filtering Todos
    21:23 Remaining Todos
    22:19 Saving Todos To Local Storage
    26:26 Outro
    #joyofcode #sveltekit #svelte #runes

КОМЕНТАРІ • 114

  • @JoyofCodeDev
    @JoyofCodeDev  8 місяців тому +83

    I definitely didn't forget to include how to remove a todo and did it on purpose to give you homework.

    • @jakobsturm2438
      @jakobsturm2438 8 місяців тому

      Thank you!

    • @parkourbee2
      @parkourbee2 8 місяців тому +3

      Lol it's not a bug, it's a (lack of) feature!

    • @sharkw9682
      @sharkw9682 5 місяців тому

      Thanks for this video! I think I've found a subtle bug playing around with the todo app in Sveltelab. If you add several todos, then check off a few of them, then use the active or completed filter, and then try to edit or toggle a todo, the wrong todo will have changed when you go back to the all filter. This is because the index of the filtered todo which is being edited or toggled does not correspond to the index in the unfiltered todo list. There's a few ways to fix this which would be a good exercise as well!

  • @zkoolkyle1
    @zkoolkyle1 8 місяців тому +6

    Hey Joy of Code! Big fan. Keep up the great work and excited to see more Svelte 5 stuff.

  • @Gabriel-ch7sx
    @Gabriel-ch7sx 8 місяців тому +5

    Thank you! Every time I watch one of your videos I learn more than I expected. This time it was switch statements and how to generate UUIDs and also I understood better how to use Svelte class directive. Please continue making these videos, they make the life of newbies like me easier!

  • @SRG-Learn-Code
    @SRG-Learn-Code 8 місяців тому +1

    I love the amount of things I learn from your videos besides the main topic.

  •  8 місяців тому +1

    Amazing work like always, thanks for the quick videos on svelte 5

  • @sistana
    @sistana 7 місяців тому +3

    And how beautiful this is, friend!!!

  • @omercelebi2012
    @omercelebi2012 8 місяців тому

    It was my first Svelte project and very fun!

  • @ronykax
    @ronykax 8 місяців тому

    You’re amazing man keep going!

  • @nomadshiba
    @nomadshiba 8 місяців тому

    i have some issues with ts and css choices in the video
    but it explains svelte runes, so good

  • @flwi
    @flwi 2 місяці тому

    Very nice tutorial, well done!

  • @zolkimariko9433
    @zolkimariko9433 8 місяців тому +1

    Very very cooool svelte 5 with new syntax state. I like it... Thank you

  • @xthesly
    @xthesly 7 місяців тому

    Very nice ! 👍

  • @alexanderleschanz9991
    @alexanderleschanz9991 8 місяців тому

    wow! very impressive!

  • @BhideSvelte
    @BhideSvelte 8 місяців тому

    🎉🎉🎉🎉 i just love it

  • @Jake-bh1hm
    @Jake-bh1hm 3 місяці тому

    wow.. i love svelte.

  • @BRODZELi
    @BRODZELi 8 місяців тому +1

    Thanks for sharing.

  • @jondoe79
    @jondoe79 8 місяців тому +1

    You can use css grid to align items to start, center, end.

  • @tomm5765
    @tomm5765 8 місяців тому

    Beautiful tutorial. Little surprised you didn't demonstrate fine grained reactivity using runes for the todo values. So that values can be updated without reassigning the list. That's the best feature of runes imo.

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому +1

      The reason I didn't runify the todo is because you would have to runify the todos again from local storage which is more advanced and it would sour people on runes because it's not ergonomic until Svelte comes up with a primitive to make it easier.

    • @dave-7117
      @dave-7117 8 місяців тому +1

      Classes

  • @justingolden21
    @justingolden21 8 місяців тому +4

    10:00 I think the reason you like it (and that was my gut reaction too) is that it's cleaner. It's cleaner because it's 1) more consistent and 2) keeps the js logic out of the html and has each thing in their own section

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому +3

      You also can't use TypeScript in the template yet.

  • @h_i_g_s_c_h_videos
    @h_i_g_s_c_h_videos 5 місяців тому

    Thank you for this video! Is it also possible to bind the checked attribute to the done property in your todos array? Like: bind:checked…

  • @daniel-nagy
    @daniel-nagy 8 місяців тому

    Ne znam što se dogodilo s mojim komentarom pa ću pokušati ponovo (c/p).
    Odličan kao i uvijek! 👏
    Pratim tvoj kanal i pogledam skoro svaki video iako uopće ne koristim Svelte u svom radnom okruženju.
    Jedan mali savjet oko stiliziranja inputa odnosno preklapanja elemenata unutar nekog kontejnera za koji si koristio "old school" trik s position: relative/absolute. Za isti efekt možeš iskoristiti display: grid na kontejner elementu te grid-area na elementima unutar njega. Znam da nisam sada apsolutno ništa objasnio no bit će ti jasnije kada pročitaš kratak članak autora Stefan Judis naslova "CSS Grid can be used to stack elements" u kojem možeš naći i odličan video koji vizualno objašnjava korake potrebne za željeni efekt.
    Živio!

  • @wtfenc0reenix
    @wtfenc0reenix 4 місяці тому

    nice video, but when i try to put the function filterTodos like in the video i get a error: cannot acces filterTodos before initialization. is there something what got changed in the last month?

  • @kaidstor_123
    @kaidstor_123 8 місяців тому +2

    how to setup package.json like you, when i start npm i svelte@next, i get only 1 dep

    • @kaidstor_123
      @kaidstor_123 8 місяців тому

      i decide it. npm create svelte@latest . (try beta svelte 5)

    • @johndeighan8890
      @johndeighan8890 3 місяці тому +1

      @@kaidstor_123 Unfortunately, that doesn't get you the latest version. Check the version in your package.json and you'll see. When I followed that, though, with 'npm install svelte@next', it upgraded svelte to "^5.0.0-next.110" (by the time you read this, it might be higher)

  • @sebastianscarano9418
    @sebastianscarano9418 17 днів тому

    do you have a repo for the project? I can't get it to work on sveltelab, and just installing open-props from npm didn't seem to work

  • @federicodifrancesco1248
    @federicodifrancesco1248 8 місяців тому

    Congrats and thanks Matia! Just one stupid question: which color theme do you use in your vscode? 😅

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому

      You can find what I use in the description.

  • @philla20
    @philla20 8 місяців тому

    Nice stuff, as always!
    Can you explain why the first effect block only runs on mount?
    Is it because todos gets assigned and isn't on the right side? First thought was that both effect blocks get run each time todos gets updated.

  • @registro_pedagogico
    @registro_pedagogico 8 місяців тому +3

    Muchas gracias y a seguir adelante mi estimado

  • @chanandlerbong6176
    @chanandlerbong6176 8 місяців тому +2

    Using index for edit todo is a bug after introducing a derived state

    • @vavhust
      @vavhust 8 місяців тому

      Yes, it should be using some sort of ID of todo or it might be index of filteredTodos

  • @JoseDv1
    @JoseDv1 8 місяців тому +4

    How could we refactor this code to separate the component logic to a new file? Are runes available outside svelte components?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому +4

      You can use runes outside Svelte components like stores. For that you're going to have a `.svelte.ts` file, so it can be optimized by the compiler. I don't know if that's working yet.

    • @mwlulud2995
      @mwlulud2995 Місяць тому

      ​@@JoyofCodeDev He not work in my side

  • @xx__xx7199
    @xx__xx7199 8 місяців тому

    🎉🔥🚀

  • @justingolden21
    @justingolden21 8 місяців тому +1

    14:20 getting into runes

  • @parkourbee2
    @parkourbee2 8 місяців тому

    Wow, Svelte just got a lot easier!

  • @ScriptRaccoon
    @ScriptRaccoon 8 місяців тому +1

    I am very confused. I was assuming that frameworks like Svelte and Vue (not React for sure) allowed us to remove the event.target.value boilerplate code from our event handlers, namely by using bindings. Is this feature gone in Svelte 5 or what is the reason the bindings didn't appear in the video?
    Also, what is the advantage of using Svelte 5 in this specific Todo app? The video didn't explain this. I can achieve exactly the same with Svelte 3 and less code.
    In the end, it is claimed that the code is much easier to reason about - why?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому

      You can runify the todo for fine-grained reactivity and use the `bind:` directive.

  • @coder_one
    @coder_one 6 місяців тому

    Are there any reliable leaks on when to expect the Svelte version 5 at the latest?

  • @seunghwanjeong5348
    @seunghwanjeong5348 8 місяців тому

    I really like your videos teaching me good lessons. Thank you for hard working😁
    There is one question I want to ask.
    is there a reason that you don't use getter and setter with todo in todos?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому +2

      I didn't runify the todo because you would have to runify the todos again from local storage and I'd rather wait to see how Svelte solves this problem instead of confusing people.

  • @sebastianscarano9418
    @sebastianscarano9418 8 місяців тому +1

    I thought that signals could track changes to reactive data however they were made, but the fact that we still need to assign a value to trigger reactivity (meaning just a todos.push(...) won't work) makes me think that it's still the compiler the one triggering the reactive update
    am I wrong?

    • @tomm5765
      @tomm5765 8 місяців тому

      Signals wrap a value with a getter and setter, the getter is used to track users of a value, the setter is used to track when to update users. "Reactivity" occurs when the setter is called and all the getters are called with the new value. If an object or array is just mutated and not re-assigned then the setter is never called. Actually, tracking mutations is something the compiler could have improved upon over signals, I am not sure why they haven't, maybe because its hard to track exactly every type of mutation.

  • @markvu7652
    @markvu7652 8 місяців тому

    what font are you using?

  • @MM-24
    @MM-24 8 місяців тому

    Great video, where are the styles coming from?
    I know we are skipping over it, but it def looks nice, is it a framework?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому +1

      I use Open Props and the styles come from `+layout.svelte` if you look at the example in the description.

  • @khawarizmyana
    @khawarizmyana 8 місяців тому +1

    Thanks! but i miss the simplicity of the old svelte 😿

  • @aquapaka
    @aquapaka 4 місяці тому

    Using data-index={i} and filtered produce a bug where checking an item in 'active' or 'completed' filter make it update wrong item.

    • @aquapaka
      @aquapaka 4 місяці тому

      Edit have that bug too. I think using bind is much more simpler, no toggle, edit boilerplate functions and don't produce those bugs.

  • @hamzamuric
    @hamzamuric 8 місяців тому

    What font is this?

  • @metalllus
    @metalllus 7 місяців тому

    something must have changed between next 4 and current next 22 because now the filtering is not working reliably if at least one todo is marked as completed

  • @labdo_
    @labdo_ 8 місяців тому

    21:40 How does the remaining function update each time todos are changed?

    • @tomm5765
      @tomm5765 8 місяців тому +1

      Good question, I had to double check this is in my code.
      `{remaining()} remaining` since the `remaining` function is used in the template then the its re-evaluated when its dependencies changes. Since `remaining` has dependency on `todos` when `todos` is changed then `remaining` is updated.
      I originally thought it was necessary to use a derived. Matia uses a derived `filteredTodos` but he could have also just used the function in the each `{#each filterTodos() as todo, index}`

  • @sylensdrake9706
    @sylensdrake9706 8 місяців тому +1

    why edit function? why not bind: ?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому +1

      That only works if you runify the todo.

  • @vtoscano
    @vtoscano 7 місяців тому

    Bienvenidos a USA, desde Mexico

  • @Edgar-pu1lc
    @Edgar-pu1lc 8 місяців тому

    Hi, I want to switch from react to svelte, do you have courses?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому

      I have a Svelte and SvelteKit playlist.

  • @matthewcole4521
    @matthewcole4521 8 місяців тому

    can we now do () => {} inside of $derived ?

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому

      I thought you could but it seems you have to invoke it.

  • @AbhinavKulshreshtha
    @AbhinavKulshreshtha Місяць тому

    You installed svelte@next, but what was installed was a sveltekit project !! 😕

  • @gebreeze
    @gebreeze 8 місяців тому

    Why no usage of databinding?

  • @Animadroids
    @Animadroids 3 місяці тому

    when i download latest, i still get "svelte": "^4.2.15"

    • @JoyofCodeDev
      @JoyofCodeDev  3 місяці тому

      It's not latest, it's `svelte@next`.

    • @Animadroids
      @Animadroids 3 місяці тому

      @@JoyofCodeDev thanks

    • @Animadroids
      @Animadroids 3 місяці тому

      I am facing an issue implementing routing. I get 404 not found with href and javascript error(Uncaught Error: Invalid status code) when i use redirect. Any suggestions how to tackle this in svelte 5 ?

  • @ukaszzbrozek6470
    @ukaszzbrozek6470 7 місяців тому +1

    It became closer to Vue and React. That isn’t a bad thing.

    • @ozgurNY
      @ozgurNY 11 днів тому

      Svelte 5 syntax gives me heartache. It is so sad they runed Svelte. It was a joy learning Svelte 4.

    • @ukaszzbrozek6470
      @ukaszzbrozek6470 11 днів тому

      ​@@ozgurNYit is necessary. They took all of the complexity on themselfs.

  • @Danielo515
    @Danielo515 8 місяців тому

    Being specific on the function parameters is not pedantic, is common sense

  • @bn5055
    @bn5055 8 місяців тому

    "We still use reassignment in Svelte 5"... isn't the new reactivity system supposed to do away with that? 🤔

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому

      You would have to use something like `setState`.

  • @tobiasparent4806
    @tobiasparent4806 7 місяців тому

    A very small nit, regarding your `remaining()` - this could have also been set as a `$derived()`, thus becoming an observable as well.
    `let remaining = $derived(todos.filter(({data:{done}})=>!done).length);` and, in your markup, `{remaining}`
    Great intro to runes, and really eye-opening. Thank you for this!

    • @JoyofCodeDev
      @JoyofCodeDev  7 місяців тому +1

      Yeah! 😄

    • @tobiasparent4806
      @tobiasparent4806 7 місяців тому

      @@JoyofCodeDev just realized my filter in there is horribly obfuscated, sorry about that lol

  • @JaLikon65
    @JaLikon65 8 місяців тому +1

    Challenge: this guy makes a bad video
    Challenge Level: *literally fucking impossible*

    • @JoyofCodeDev
      @JoyofCodeDev  8 місяців тому

      I do a lot of research. 😂

  • @heugh_jazz
    @heugh_jazz 8 місяців тому +1

    man you're a svelte god but please don't take shortcuts by using stuff like bang as you are sometimes exposing first timers to svelte.
    i know it's not a typescript tutorial but a minute to do something the right way will go a long way.

  • @hansiboy5348
    @hansiboy5348 8 місяців тому +1

    Why even use typescript if we are ignoring it's features by having so much type casting and type assertion? Would JavaScript with jsdocs not be more suitable?

  • @SRG-Learn-Code
    @SRG-Learn-Code 8 місяців тому

    I think people is scared of Rich removing stores or simple reactivity, but in the end is just another tool that you can use when you find yourself against an apparent easy but really hard problem.

    • @AlanDanielx
      @AlanDanielx 8 місяців тому

      Rich, isnt going to delete regular stores, nor we think that

  • @davidjesus8629
    @davidjesus8629 8 місяців тому +1

    I used to be all for Svelte but, since runes were announced, everything seems to have a gotcha, a more verbose way to do stuff that has already been solved elsewhere simpler or something just weird for the sake of "future less headache" so i am not sure anymore

    • @The6DAZ6
      @The6DAZ6 8 місяців тому

      I think exactly the same, Svelte lost it's true killing feature: simplicity

    • @bear458ziif-s
      @bear458ziif-s 8 місяців тому

      @@The6DAZ6 not sure why exactly you think it's not simple. it's easier with runes than it was before.

    • @davidjesus8629
      @davidjesus8629 8 місяців тому

      @@bear458ziif-s So replacing stores makes up for the rest of the "oh well this doesnt quite wok like every other signal implementation, you need to workaround it with x"?. The point of runes was to bring state powers to every scope posible, but we have to use verbose javascript to do so, Rich as great as he is, proposes Classes, this is not a fix, is just that it turns out that classes are LESS verbose than returning a simple function. What even is the appeal of Svelte if i need to keep in mind this lot of gotchas just because they are ALL IN on this mental model. Vue, Qwik, Solid and NOW even Angular already solved signals in a more elegant way, even if with larger scale projects they maybe harder to scale, complicating things with gotchas everywhere is just a headache to begin with. People that dont use React run from it exactly because it has so many framework especific funcionality that they just go crazy, and now, just because maybe when my codebase is that of one BIG app, i may avoid a few lines and more debuggeable at the cost of everything being more verbose? Sorry but no, Svelte is not svelte-like anymore.

    • @tomm5765
      @tomm5765 8 місяців тому

      ​@@davidjesus8629 I look at runes as a reactive primitive that replaces both `let` based reactivity and stores, and its more consistent for those two use cases. Yes there is a big gotcha with runes not leaving scope, so requiring get/set or classes, but that is a single gotcha compared to the many gotchas of `let` reactivity and stores.

    • @tomm5765
      @tomm5765 8 місяців тому

      Runes are more svelte-like that other signals implementation, they act the same way as `let` reactive variables. Imagine the uproar if svelte was changed to use `.value` or function calling to access the signal instead.

  • @user-pr4vj2qo7g
    @user-pr4vj2qo7g 8 місяців тому

    Vue much?

  • @AlanDanielx
    @AlanDanielx 8 місяців тому +1

    I Always Give good rating but This Time My Friend You Focused A Lot On css….👎🏻