Introduction To Svelte Runes (Every Svelte Rune Explained)

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ส.ค. 2024
  • 🎓 Join my learning platform for module based courses, learning exercises, and more: coderprep.com/
    📩 Join CodeLetter by Cooper Codes, the 3 minute tech newsletter: thecodeletter.com
    In this Svelte Runes tutorial I discuss the recently announced Svelte Runes functionality for Svelte 5. It is important to note that Svelte 5 has not been fully released yet, but the Svelte team is planning to move to rune functionality in the near future! Svelte 5 Runes are great to know for Svelte and SvelteKit developers, as they will likely change some of the core development patterns for both types of devs. During this video I show off how to use Svelte Runes in a variety of different examples and components, so feel free to stick around for that section. If you're interested in learning more about Svelte or Svelte Runes, make sure to subscribe for more content like this.
    Code with runes here: svelte-5-preview.vercel.app/
    Some cool Svelte runes resources to check out:
    component-party.dev/?f=svelte... (Comparing Svelte 4 to Svelte 5)
    svelte.dev/blog/runes (The announcement blog)
    0:00 Introduction to Svelte Runes
    4:08 Live coding with Svelte Runes
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 32

  • @TheRealJuggaloJoel
    @TheRealJuggaloJoel 9 วันที่ผ่านมา

    this is so dope. Great delivery and description 5stars

  • @BRODZELi
    @BRODZELi 9 หลายเดือนก่อน

    I'd love to see more video tutorials on Svelte, especially in anticipation of the upcoming Svelte 5 release. That would be truly awesome! 🚀👍

  • @paulclarke4099
    @paulclarke4099 10 หลายเดือนก่อน +4

    Best video I've watched covering this topic. Love your Svelte/SvelteKit coverage, thank you so much 😃👍

    • @marvinmonge3006
      @marvinmonge3006 10 หลายเดือนก่อน

      +1
      Great explanation! 🙌

    • @CooperCodes
      @CooperCodes  10 หลายเดือนก่อน

      Thanks so much for the support Paul :) it is greatly appreciated, glad you found my videos helpful

  • @Huntabyte
    @Huntabyte 10 หลายเดือนก่อน +5

    Nicely explained!

    • @CooperCodes
      @CooperCodes  10 หลายเดือนก่อน +1

      Beast! Hope you're doing well :)

  • @jameskim7565
    @jameskim7565 10 หลายเดือนก่อน

    Great video. And a quick note at 2:46, it seems like you have a typo at the bottom part with the tag, having "doubled" instead of "double"

  • @nickstaresinic4031
    @nickstaresinic4031 9 หลายเดือนก่อน

    Good, concise explanation, Coop...I mean *Cooper*.

  • @riigel
    @riigel 10 หลายเดือนก่อน +1

    thanks 👍👍 this is so clear!

    • @CooperCodes
      @CooperCodes  10 หลายเดือนก่อน +1

      You're welcome! Thanks for your support and commenting so fast :)

  • @paulthomas1052
    @paulthomas1052 10 หลายเดือนก่อน +1

    Hi, thanks for the update.

    • @CooperCodes
      @CooperCodes  10 หลายเดือนก่อน

      You are very much welcome, thank you for watching !

  • @jingle1161
    @jingle1161 10 หลายเดือนก่อน +2

    So basically $derived is a calculation and $effect is a watcher?
    Btw, that is golden. First example on TH-cam that clearly shows the concept of runes. I wasn't very excited with the syntax I saw till now.
    And that $props thing is fascinating. That's gonna ease a lot of parent/child communication

    • @CooperCodes
      @CooperCodes  10 หลายเดือนก่อน +1

      The way I understand it is that $derived helps us keep values up to date in a simple way. If we have
      const testValue = $derived( variable1 + variable2 + variable3);
      Then if any of the variables inside of $derived change, testValue will get recalculated. I believe (I could be wrong) that in the old versions of Svelte, if you just said "testValue = variable1 + variable2 + variable3" the client would not update to the up to date value in certain cases. So the reason for the different syntax is to ensure the value will always be up to date.
      $effect can be understood as a way to introduce functionality 1. On initial component load and 2. When variables within the $effect change. It differs from $derived because within the effect we can create any functionality we want (whereas $derived is just a recalculation), although my was simple, you can create any functionality specific to the effect which is really interesting.
      Hopefully this helps! I'm also just learning the new syntax along you all but have done enough working around to create an intro video on it, glad the video was helpful for you :)

    • @gadgetboyplaysmc
      @gadgetboyplaysmc 9 หลายเดือนก่อน

      $derived is very similar to useMemo in React. I primarily use it for derived states. A more real-world example would be if you want a Select Option to change based on the currently selected state (like filtering them)
      let selectedColor = $state("red")
      const colorOptions = ["red", "green", "yellow"]
      const allFoodOptions= [{ color: "red", value: "apple" }, { color: "red", value: "tomato" }, { color: "green", value: "spinach" }, { color: "yellow", value: "banana" }]
      let foodOptions = $derived( allOptions.filter((option) => option.color === selectedColor ) )
      ---

  • @brandonlu2237
    @brandonlu2237 10 หลายเดือนก่อน

    when did we just devolve into sorcery 😂😂

    • @CooperCodes
      @CooperCodes  10 หลายเดือนก่อน

      🧙✨ 💀

  • @jengstrm2
    @jengstrm2 10 หลายเดือนก่อน

    I wonder how it looks to subscribe and unsubscribe to observables using effects

    • @lian1238
      @lian1238 10 หลายเดือนก่อน +1

      Isn’t that just writable stores?

  • @moussaibrahem9
    @moussaibrahem9 10 หลายเดือนก่อน +1

    Simply it is hooks in react

    • @nickstaresinic4031
      @nickstaresinic4031 10 หลายเดือนก่อน

      Without having played with it yet, that's what the syntax looks like.

    • @DEVDerr
      @DEVDerr 10 หลายเดือนก่อน +2

      Not exactly. It's just made way better. You will not run into many pitfalls like in the React (f.e. all of the weird implicit useEffect() behaviors)
      But it will actually make codebase simpler, because now Svelte scripts will be JS in 100%. They will not change the semantics like with export let (which defined a prop instead of exporting a module).
      So f.e. you can write some logic, put into into Svelte file and it will behave exactly the same way like in normal JS.
      And you can also do it the other way around - you can now also use Svelte features outside of Svelte files f.e. use $state() and $derived() in some external JS files

    • @nickstaresinic4031
      @nickstaresinic4031 10 หลายเดือนก่อน

      @@DEVDerr "...use $state() and $derived() in some external JS files" That indeed would be very useful.
      When I've run into that problem, I've used lihautan's work-around(s), found on TH-cam under "How to use Svelte store in .js file?"

    • @DEVDerr
      @DEVDerr 10 หลายเดือนก่อน

      @@nickstaresinic4031 It was not a workaround really. The only way to use Svete's reactivity outside of Svelte files was actually using a Svelte's built-in store. Which wasn't that big of a problem really, it was actually nice that you could update/retrieve data in some JS/TS files and I love that (especially while creating games). But now it will be even better, because $state and $derived behave more like primitives. You can compose them together and create reusable stateful logic (like with Hooks in React) but with all of the Svelte's performance and DX benefits

  • @dot_method
    @dot_method 10 หลายเดือนก่อน +1

    That looks like vue but with extra steps 😅

    • @jhonyortiz5
      @jhonyortiz5 10 หลายเดือนก่อน

      Can you give one or more examples? I'm curious about Vue and I keep seeing people comparing svelte 5 to Vue.

    • @dot_method
      @dot_method 10 หลายเดือนก่อน

      @@jhonyortiz5
      svelte --> vue
      $props --> defineProps
      $state --> ref
      $derived --> computed
      $effect --> watch

    • @dot_method
      @dot_method 10 หลายเดือนก่อน

      And just to be clear, I like both svelte and vue alike, but it's a bit funny to see the convergence

    • @nuttbaked
      @nuttbaked 9 หลายเดือนก่อน +1

      trying so hard to not look biased towards vue lol

  • @amrita368
    @amrita368 9 หลายเดือนก่อน

    How to upload image using nodejs mongoose and graphql ?? Plz upload a video

  • @iojourny
    @iojourny 10 หลายเดือนก่อน +3

    So basically they realized Vue was right all along 😂