Generator Functions will make your code cleaner 🧹

Поделиться
HTML-код
  • Опубликовано: 15 июл 2024
  • In this TypeScript tutorial, you will learn how to encapsulate your data-fetching functionality in a generator function. This approach will enhance the reusability of your code, as consuming code can simply use for-await to fetch the data.
    My FREE programming apps:
    - apps.apple.com/app/id659282498
    - play.google.com/store/apps/de...
    My FREE TypeScript Course:
    - typescript.tv/
    Timeline:
    00:00 - Intro
    00:31 - Fetching Data with Async-Await
    05:52 - Turning Functions into Generator Functions
    09:56 - The Benefits of Generator Functions
    11:01 - Bonus: Converting JSON Data into a Zod Schema
    Resources:
    - polygon.io/stocks
    - transform.tools/json-to-zod
    #typescript #javascript #nodejs
  • НаукаНаука

Комментарии • 7

  • @sadhakbj
    @sadhakbj 11 дней назад

    Juat discovered the channel today and instantly fell in love with it. The quality of videos are very high. I love typescript. I myself created one course on node and ts long back. Now i work with go and miss typescript. Your contents help me sharpen my knowledge. Please continue making more and more contents.

    • @TypeScriptTV
      @TypeScriptTV  11 дней назад

      Thank you so much! Where can I see your Node.js & TS tutorial? I am curious! 👀

    • @sadhakbj
      @sadhakbj 11 дней назад

      @@TypeScriptTV i am trying to comment the video link but it seems to be deleted by youtube. I don’t know why.

  • @nathanbrodin2948
    @nathanbrodin2948 Месяц назад +1

    Very clear video, thanks!. This could be a great use case for streaming responses then ?

    • @TypeScriptTV
      @TypeScriptTV  Месяц назад

      Absolutely! Here, you can see a streaming case: typescript.tv/hands-on/all-you-need-to-know-about-iterators-and-generators/#case-2-fetching-remote-content

  • @Cowboy-Ben-Alman
    @Cowboy-Ben-Alman Месяц назад +1

    You could've gone one step further and had the generator yield the individual results so instead of the consuming code iterating over chunks, it would iterate over results.

    • @TypeScriptTV
      @TypeScriptTV  Месяц назад

      Great idea! Thanks for suggesting it. I'll definitely add this approach to my blog. 👍