<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dimitar Gaydardzhiev</title>
    <description>The latest articles on DEV Community by Dimitar Gaydardzhiev (@dimitar_gaydardzhiev).</description>
    <link>https://dev.to/dimitar_gaydardzhiev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3806043%2Ff2f2ad2f-ae5f-423d-bd27-36a9e4bdd679.png</url>
      <title>DEV Community: Dimitar Gaydardzhiev</title>
      <link>https://dev.to/dimitar_gaydardzhiev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dimitar_gaydardzhiev"/>
    <language>en</language>
    <item>
      <title>Cold vs Hot Observables in RxJS Explained</title>
      <dc:creator>Dimitar Gaydardzhiev</dc:creator>
      <pubDate>Wed, 04 Mar 2026 15:53:00 +0000</pubDate>
      <link>https://dev.to/dimitar_gaydardzhiev/cold-vs-hot-observables-in-rxjs-explained-1ea8</link>
      <guid>https://dev.to/dimitar_gaydardzhiev/cold-vs-hot-observables-in-rxjs-explained-1ea8</guid>
      <description>&lt;p&gt;Understanding the difference between cold and hot observables is essential when working with RxJS. Depending on how values are produced, observables fall into two categories &lt;strong&gt;Cold&lt;/strong&gt; and &lt;strong&gt;Hot&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cold Observables
&lt;/h2&gt;

&lt;p&gt;A cold observable produces values internally and &lt;strong&gt;only starts producing them when someone subscribes&lt;/strong&gt;. This means that each time an Observer subscribes, the Observable starts a new execution and produces a fresh set of values for that specific Observer.&lt;/p&gt;

&lt;p&gt;A classic example of a cold observable is an HTTP request. In RxJS, the &lt;code&gt;ajax()&lt;/code&gt; operator creates a cold observable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const coldObservable$ = of('Movie 1', 'Movie 2', 'Movie 3');

coldObservable$.subscribe(value =&amp;gt; console.log('Observer 1:', value));
coldObservable$.subscribe(value =&amp;gt; console.log('Observer 2:', value));

// Output:
// Observer 1: Movie 1
// Observer 1: Movie 2
// Observer 1: Movie 3
// Observer 2: Movie 1
// Observer 2: Movie 2
// Observer 2: Movie 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case Observer 1 triggers an HTTP request, Observer 2 triggers another HTTP request. Each subscription causes the observable to run again. Both observers may receive the same values, but the executions are completely independent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hot Observables
&lt;/h2&gt;

&lt;p&gt;Hot observables behave differently. Instead of generating values internally, hot observables receive values from external sources. These values are produced regardless of whether there are subscribers or not.&lt;/p&gt;

&lt;p&gt;Examples of external sources include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;user input events&lt;/li&gt;
&lt;li&gt;WebSocket messages&lt;/li&gt;
&lt;li&gt;DOM events&lt;/li&gt;
&lt;li&gt;timers&lt;/li&gt;
&lt;li&gt;real-time data streams&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hot observables broadcast the same values to all subscribers. A simple example of a hot observable is a button click event. They are produced outside the Observable, and multiple Observers can receive the same events simultaneously:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const button = document.querySelector('button');
const hotObservable$ = fromEvent(button, 'click');

hotObservable$.subscribe(() =&amp;gt; console.log('Observer 1: Button clicked'));
hotObservable$.subscribe(() =&amp;gt; console.log('Observer 2: Button clicked'));

// Output:
// Observer 1: Button clicked
// Observer 2: Button clicked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why This Difference Matters
&lt;/h2&gt;

&lt;p&gt;Understanding the difference between **cold **and **hot **observables is important when designing reactive systems.&lt;/p&gt;

&lt;p&gt;Cold observables are useful when each subscriber should get fresh data&lt;br&gt;
and/or operations must run independently. On the other hand, hot observables are ideal when multiple consumers need the same data stream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to Go Deeper?
&lt;/h2&gt;

&lt;p&gt;If you want to explore the topic further, I cover RxJS in much greater depth in my book &lt;a href="https://mybook.to/OmKvO" rel="noopener noreferrer"&gt;Mastering RxJS from Scratch: A Step-by-Step Guide to Understanding RxJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The book is designed as a practical, step-by-step guide that helps developers understand RxJS from the ground up, explains the most important operators, and demonstrates how to apply reactive programming in real-world applications.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why RxJS Makes Asynchronous JavaScript Easier</title>
      <dc:creator>Dimitar Gaydardzhiev</dc:creator>
      <pubDate>Wed, 04 Mar 2026 15:33:44 +0000</pubDate>
      <link>https://dev.to/dimitar_gaydardzhiev/why-rxjs-makes-asynchronous-javascript-easier-a9f</link>
      <guid>https://dev.to/dimitar_gaydardzhiev/why-rxjs-makes-asynchronous-javascript-easier-a9f</guid>
      <description>&lt;p&gt;Handling asynchronous code in JavaScript can become messy quickly. Nested callbacks, chained promises, and complex async workflows often make code difficult to maintain.&lt;/p&gt;

&lt;p&gt;Whether you're dealing with API calls, user events, or real-time data streams, managing asynchronous data efficiently is critical.&lt;/p&gt;

&lt;p&gt;In plain JavaScript, asynchronous logic is typically handled using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;callbacks&lt;/li&gt;
&lt;li&gt;promises&lt;/li&gt;
&lt;li&gt;async/await&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While these approaches work well for many situations, they have limitations, especially when working with multiple values over time. This is where RxJS and observables provide a powerful alternative.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Callbacks
&lt;/h2&gt;

&lt;p&gt;Callbacks were one of the earliest ways to handle asynchronous operations in JavaScript. A typical example might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiCall(function (response) {
    processResponse(response, function (processedData) {
        writeFile(processedData, function () {
            console.log('File written successfully');
        });
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we first make an API call, process the returned data with a callback, and then write it to a file using another callback. While this works, the code can quickly become difficult to read, especially as more nested logic is introduced. This is often referred to as &lt;em&gt;&lt;strong&gt;callback hell&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Promises
&lt;/h2&gt;

&lt;p&gt;Promises improved asynchronous code significantly by providing a more readable interface compared to callbacks. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiCall()
    .then(response =&amp;gt; processResponse(response))
    .then(processedData =&amp;gt; writeFile(processedData))
    .then(() =&amp;gt; console.log('File written successfully'))
    .catch(error =&amp;gt; console.error('Error occurred:', error))
    .finally(() =&amp;gt; console.log('Operation complete'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With promises, we can chain the &lt;code&gt;then()&lt;/code&gt;, &lt;code&gt;catch()&lt;/code&gt;, and &lt;code&gt;finally()&lt;/code&gt; methods to handle the API response and subsequent actions. This is easier to read than nested callbacks, but it’s important to note that &lt;strong&gt;promises only handle a single value&lt;/strong&gt;. Once the promise is resolved and the value is passed through the chain, the operation is done. This makes promises less suitable for scenarios where &lt;strong&gt;multiple values are produced over time&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Async/Await
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;async/await&lt;/code&gt; syntax makes asynchronous code look very similar to synchronous code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function handleData() {
    try {
        const response = await apiCall();
        const processedData = await processResponse(response);
        await writeFile(processedData);
        console.log('File written successfully');
    } catch (error) {
        console.error('Error occurred:', error);
    } finally {
        console.log('Operation complete');
    }
}

handleData();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, under the hood, async/await still relies on promises, which means it shares the same limitation - it works with a &lt;strong&gt;single resolved value&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using RxJS and Observables
&lt;/h2&gt;

&lt;p&gt;RxJS introduces the concept of observables, which allow us to work with &lt;strong&gt;streams of values&lt;/strong&gt; over time rather than a single result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const observable = apiCall$();

const observer = {
  next: (value: any) =&amp;gt; console.log('Received value:', value),
  error: (error: Error) =&amp;gt; console.error('Error occurred:', error),
  complete: () =&amp;gt; console.log('All values processed'),
};

observable.subscribe(observer);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we call a function that returns an observable. We then subscribe to this observable by passing an observer with three methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;next()&lt;/code&gt; - called whenever a new value is produced&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;error()&lt;/code&gt; - called if there’s an error during the data flow&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;complete()&lt;/code&gt; - called when there are no more values to process&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key advantage of using RxJS is that an observable can emit multiple values over time, calling the next() method each time a new value is available. This makes it ideal for working with streams of data, such as user input events or real-time server responses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Callbacks, promises, and async/await are all useful tools in JavaScript. However, when dealing with multiple asynchronous values over time, observables provide a far more flexible and powerful model. They allow developers to think in terms of data streams instead of individual events, which leads to cleaner and more maintainable asynchronous code.&lt;/p&gt;

&lt;p&gt;If you want to explore the topic further, I cover RxJS in much greater depth in my book &lt;a href="https://mybook.to/OmKvO" rel="noopener noreferrer"&gt;Mastering RxJS from Scratch: A Step-by-Step Guide to Understanding RxJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The book is designed as a practical, step-by-step guide that helps developers understand RxJS from the ground up, explains the most important operators, and demonstrates how to apply reactive programming in real-world applications.&lt;/p&gt;

</description>
      <category>rxjs</category>
      <category>angular</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
