DT Tech InfoDT Tech Info

      RxJs for Beginners

      LEARN EASY
      • Home
      • Blog
      • RxJs for Beginners
      • RxJs Tutorial Series: Part 1 – Intro

      RxJs Tutorial Series: Part 1 – Intro

      • Posted by Muthukumar Dharmar
      • Categories RxJs for Beginners
      • Date July 25, 2020

      First of all, I welcome you to this rxjs tutorial series for beginners 🙂 

      I hope this will help you understand the power of RxJs and will increase your curiosity about learning RxJs.

      Actually, before we get into the concepts of RxJs, I just want to share a few solutions using rxjs for some realtime problems, that will help you understand the capability of RxJs.

      Lets Begin
      One of the common use cases in application development are a type ahead/autocomplete lookup search. Typically we handle this by capturing the keyup event and this is not an easy task. Why would I say that? 

      Let’s see this problem in action.

      I hope you understand the problem now.  In order to search the country India, the key up event has been raised 6 times, If the user mistypes and correcting it, then think how many API requests would have gone.

      At least we must handle the below cases, right!

      • Throttle key ups to reduce the number of API requests.
      • Handle race conditions with the HTTP response.

      Let’s solve this with RxJs

      In the above example, we are controlling the keyup event streams and logging to console only if the user stopped typing (or) there is a pause during keystrokes for 300 ms. 

      And this can be done only with 5 lines of code,  that’s the beauty of rxjs.

      Let’s take this to the next level and integrate API request.

      In the above example, we actually make an API request to fetch the countries. You would have noticed, there are a couple of requests that are automatically being canceled.  This the power of an RxJs operator which handles the race condition and cancels the ongoing API request when there is a need for a new one.

      Just to summarize the cases that we have handled, so far.

      • Handled the invocation of API requests only when there is a pause on keystrokes for 300 ms.
      • Avoided the race condition in API response by cancelling the previous request before triggering the new one.
       
      I would love to share more problem solutions in this article. But our goal is to learn, not just to see some samples right!   We will see more complex problems and interesting solutions in the upcoming series.  Of course, using RxJs

      This awesome isn’t it!… Thanks to Rxjs 🙂

      Part 2 – Observer & Observables

      Tag:rxjs, scheduler, task maager, task scheduler

      • Share:
      author avatar
      Muthukumar Dharmar
      Over 17 yrs of experience in the IT industry. Skill Set: Angular, RxJS Reactive Programming, AspNet WebApi, WCF, WPF, Azure, etc.,

      Previous post

      Part 1 - Error Handling Best Practices in Angular
      July 25, 2020

      Next post

      Part 3 - Error Handling Best Practices in Angular
      July 26, 2020

      Leave A Reply Cancel reply

      Your email address will not be published. Required fields are marked *

      Search

      Categories

      • Angular
      • Angular PWA
      • ArchiMate
      • AspNet Core – Razor
      • AspNet Core – WebApi
      • Best Practices
      • Design Patterns
      • EF Core
      • Entity Framework
      • IdentityServer4
      • RxJs for Beginners
      • Tips & Tricks
      • Uncategorized
      • Web Development
      • WPF / WPF Core

      Latest Posts

      Azure: Storage Services
      26Sep2024
      Angular Styles – Tips and Tricks
      23Dec2023
      Typescript – Tips and Tricks
      23Dec2023
      logo-eduma-the-best-lms-wordpress-theme

      webadmin@dt-tech.info

      Organization

      • Contact Us

      Links

      • Blogs
      • Gallery

      Recommend

      • Angular
      • RxJS
      • AspNet Core – Razor
      • AspNet Core – WebApi
      • AspNetCore

      Powered by DT Tech.