<?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: Leonardo Maria Miliacca</title>
    <description>The latest articles on DEV Community by Leonardo Maria Miliacca (@e4r).</description>
    <link>https://dev.to/e4r</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%2F167924%2Fbbd3dc2a-896f-4d50-8793-bbe121ba4946.jpg</url>
      <title>DEV Community: Leonardo Maria Miliacca</title>
      <link>https://dev.to/e4r</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/e4r"/>
    <language>en</language>
    <item>
      <title>The RxJS concatenation strategies, pt 4/4</title>
      <dc:creator>Leonardo Maria Miliacca</dc:creator>
      <pubDate>Wed, 01 Apr 2020 12:41:43 +0000</pubDate>
      <link>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-4-4-28eo</link>
      <guid>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-4-4-28eo</guid>
      <description>&lt;p&gt;Welcome to the last part of this small journey regarding the RxJS concatenation strategies.&lt;/p&gt;

&lt;p&gt;Before getting further into reading, ensure to have read the previous articles, to have a better understanding of the context.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-1-4-394g"&gt;Part 1 concatMap strategy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-2-4-37de"&gt;Part 2 mergeMap strategy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-3-4-25b0"&gt;Part 3 switchMap strategy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today we’ll cover the last one, the &lt;strong&gt;exhaustMap&lt;/strong&gt; strategy. Have a glance to its marble table:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pj-8_gkR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AHMR6XMGlq8gWj8qlaCvfsg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pj-8_gkR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AHMR6XMGlq8gWj8qlaCvfsg.png" alt="exhaustMap marble table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have our “usual” streams of events, we assume that the first one above is a stream of events emitted by an imaginary user, which types in a as much imaginary text input the values “1” , “3”, and “5”, each value separated by a certain amount of time, let’s say that the value “3” is typed one second and a half later than “1”, and the value “5” is typed just one second later than “3”.&lt;/p&gt;

&lt;p&gt;Then, at each value typed, our RxJS operator exhaustMap creates, concatenates and schedules 3 different events one each half a second, which value is the value typed in multiplied by 10, and is finally emitted as a GET request.&lt;/p&gt;

&lt;p&gt;So, if a user types “1”, there will be three HTTP GET request one each half a second:&lt;/p&gt;

&lt;p&gt;[GET] /endpoint/10 at 0s&lt;/p&gt;

&lt;p&gt;[GET] /endpoint/10 at 0.5s&lt;/p&gt;

&lt;p&gt;[GET] /endpoint/10 at 1.0s&lt;/p&gt;

&lt;p&gt;Now, let’s say that the user, after 1.5 seconds, types “3” in our text box: our RxJS operator exhaustMap concatenates the three HTTP calls and schedules them as previously said, but after about a second, the user types “5”.&lt;/p&gt;

&lt;p&gt;Differently from other operators, in this case we’ll have the expected three HTTP calls [GET] /endpoint/50 ignored, since the previous event hasn’t finished yet.&lt;/p&gt;

&lt;p&gt;This could be particularly useful for example in payments forms: we absolutely don’t want that the user clicks multiple times on our payment button and pays again and again (do we? 😛).&lt;/p&gt;

&lt;p&gt;Once the user clicks on the button, the exhaustMap simply ignores all the other events emitted if the ongoing event hasn’t finished yet.&lt;/p&gt;

&lt;p&gt;I hope that this operator is a bit more clearer now :)&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>rxjs</category>
    </item>
    <item>
      <title>The RxJS concatenation strategies, pt 3/4</title>
      <dc:creator>Leonardo Maria Miliacca</dc:creator>
      <pubDate>Wed, 01 Apr 2020 07:52:32 +0000</pubDate>
      <link>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-3-4-25b0</link>
      <guid>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-3-4-25b0</guid>
      <description>&lt;p&gt;Welcome back! In this article I’ll illustrate another concatenation strategy used by the marvelous library RxJS.&lt;br&gt;
First and foremost, if you didn’t checked out my previous articles, I suggest to do that now:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-1-4-394g"&gt;concatMap&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-2-4-37de"&gt;mergeMap&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article I’ll introduce you to the &lt;strong&gt;switchMap&lt;/strong&gt; operator, which basically lets the developer to concatenate different events such that if an event in the events chain hasn’t completed, is erased when a new event is emitted.&lt;/p&gt;

&lt;p&gt;Let’s look at the switchMap marble diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KgmAD5Rx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AQCCdChvnp4aVGA_aUkOimQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KgmAD5Rx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AQCCdChvnp4aVGA_aUkOimQ.png" alt="switchMap marble table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To put that in a living example, let’s say that when a user type a letter (“A”, “B”, “C” in our case), the switchMap operators combines it with 1,2 and 3, and emits these value with an interval of 1 second.&lt;/p&gt;

&lt;p&gt;Now, let’s suppose that the user types “A”, switchMap register the three new values “A1”, “A2”, and “A3” and emits “A1” immediately, then waits for a second before emitting “A2”. In the meantime, after (about) 0.8 seconds, the user types in “B”. The switchMap operator &lt;strong&gt;cancels&lt;/strong&gt; all the scheduled events “A2” and “A3”, and replaces them with a new serie of “B1” (which is emitted immediately), “B2” and “B3”.&lt;/p&gt;

&lt;p&gt;This operator is particularly useful when we have a form which perform a save at each value change. To avoid tenths of HTTP request calls, we’d probably want to use switchMap.&lt;/p&gt;

&lt;p&gt;I hope the mechanism is a bit more clearer :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>rxjs</category>
    </item>
    <item>
      <title>The RxJS concatenation strategies, pt 2/4</title>
      <dc:creator>Leonardo Maria Miliacca</dc:creator>
      <pubDate>Tue, 31 Mar 2020 07:50:58 +0000</pubDate>
      <link>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-2-4-37de</link>
      <guid>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-2-4-37de</guid>
      <description>&lt;p&gt;The &lt;a href="https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-1-4-394g"&gt;previous article&lt;/a&gt; of this mini-serie was about the first concatenation strategy in the amazing RxJS world, which was a direct sequential events concatenation.&lt;/p&gt;

&lt;p&gt;Today, I’ll dig deep into the mergeMap merging strategy.&lt;/p&gt;

&lt;p&gt;Differently enough from the &lt;em&gt;concatMap&lt;/em&gt; , which enqueues all the events by the input events’ order, the mergeMap operator emits events by overlapping the order. Let’s see the marble diagram below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CojRKld---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/875/1%2AnOCnnpYBU2wZQSa48JlfNg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CojRKld---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/875/1%2AnOCnnpYBU2wZQSa48JlfNg.png" alt="mergeMap marble table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here let’s suppose that a user types in &lt;strong&gt;“A”, “B” ** and **“C”&lt;/strong&gt; in a textbox attached to a Subject that emits values.&lt;/p&gt;

&lt;p&gt;Plus, there is another Subject that takes in a stream of values, and emits three new values combining the letter typed by the user and a sequential number (1,2,3) in an interval of a second each. &lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;if a user types “A”&lt;/strong&gt;, the value emitted immediately will be &lt;strong&gt;“A1”&lt;/strong&gt;, then &lt;strong&gt;“A2”&lt;/strong&gt; after a second, and finally &lt;strong&gt;“A3”&lt;/strong&gt; after three seconds.&lt;/p&gt;

&lt;p&gt;Here, there isn’t a proper concatenation, is more like attaining to the word meaning: it’s merging all the emissions consequently, even if the event before hasn’t finished and even if they're overlapping each other. &lt;/p&gt;

&lt;p&gt;This is especially true with HTTP requests. In this case, if we consider A1, A2, A3, B1 and so on as HTTP requests, &lt;strong&gt;they will be started consequently&lt;/strong&gt;, and A2 will be started even if A1 isn’t completed.&lt;/p&gt;

&lt;p&gt;Hope that this merging strategy is a bit more clearer now.&lt;br&gt;
The next article will talk about the next concatenation strategy: &lt;em&gt;switching&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>rxjs</category>
    </item>
    <item>
      <title>The RxJS concatenation strategies, pt 1/4</title>
      <dc:creator>Leonardo Maria Miliacca</dc:creator>
      <pubDate>Mon, 30 Mar 2020 09:17:23 +0000</pubDate>
      <link>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-1-4-394g</link>
      <guid>https://dev.to/e4r/the-rxjs-concatenation-strategies-pt-1-4-394g</guid>
      <description>&lt;p&gt;As my journey into the marvelous world of RxJS goes on, I want to share a bit of knowledge I’ve got following courses, blogs and so on regarding the concatenation strategies.&lt;br&gt;
First off, what is a concatenation strategy?&lt;br&gt;
As you may probably know, RxJS is about streams of values, often handled asynchronously, as HTTP calls can be, that’s why it can happen that we have to use some sort of concatenation to keep our code execution in order, let’s see how.&lt;br&gt;
Let’s put that we have a text box where we freely type anything, and that at each input typed by the user, we are sending 3 HTTP requests to a server, combining the letter typed with the numbers 1,2 and 3, and so on with every letter typed. In other words, if the user types “A”, the client will send three requests like:&lt;/p&gt;

&lt;p&gt;[GET] /endpoint/A1&lt;/p&gt;

&lt;p&gt;[GET] /endpoint/A2&lt;/p&gt;

&lt;p&gt;[GET] /endpoint/A3&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FIRST STRATEGY: concatMap&lt;/strong&gt;&lt;br&gt;
Given a stream of value (the user that types n times), the concatMap operator waits for each operation before initializing the next one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--awMliEq7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--PHpqDFAF--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/ulxj23cjhftyguvqdfmq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--awMliEq7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--PHpqDFAF--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/ulxj23cjhftyguvqdfmq.png" alt="RxJS concatMap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given our example above, the marble diagram here shows the first stream of values (A, B and C) which represent the values emitted by the user, and the stream 1,2 and 3 which represent our merge (“A1” , “A2” and so on).&lt;br&gt;
Let’s follow step by step:&lt;br&gt;
The user types A, and the value first merged value is emitted as a [GET]/endpoint/A1 , when the request is resolved then…&lt;/p&gt;

&lt;p&gt;…the client starts [GET]/endpoint/A2 , when resolved then…&lt;/p&gt;

&lt;p&gt;… the client starts [GET]/endpoint/A3, when resolved then…&lt;/p&gt;

&lt;p&gt;…User types B, then…&lt;/p&gt;

&lt;p&gt;[GET]/endpoint/B1 starts, and once resolved…&lt;/p&gt;

&lt;p&gt;…[GET]/endpoint/B2 starts but…&lt;/p&gt;

&lt;p&gt;…In the meantime the user types C, but our concatMap enqueues C1, C2, and C3 after B3 emission, so…&lt;/p&gt;

&lt;p&gt;… [GET]/endpoint/B3 starts, and once resolved…&lt;/p&gt;

&lt;p&gt;… [GET]/endpoint/C1 starts, and once resolved…&lt;/p&gt;

&lt;p&gt;… [GET]/endpoint/C2 starts, and once resolved…&lt;/p&gt;

&lt;p&gt;… [GET]/endpoint/C3 starts&lt;/p&gt;

&lt;p&gt;Now even displacing B much much before the result won’t change, as you can se in this edited marble diagram below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vflp0Og9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/us7qe95d6e4wor2ehuv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vflp0Og9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/us7qe95d6e4wor2ehuv9.png" alt="RxJS marble concatMap 2"&gt;&lt;/a&gt;&lt;br&gt;
And that’s pretty much it!&lt;/p&gt;

&lt;p&gt;I hope that this concatenation strategy is a bit clearer :)&lt;/p&gt;

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