<?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>Forem: Mikhail Potapov</title>
    <description>The latest articles on Forem by Mikhail Potapov (@mpotapov).</description>
    <link>https://forem.com/mpotapov</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%2F1023212%2Fbc779416-c473-431b-b2a4-ee3370d5d4fe.jpeg</url>
      <title>Forem: Mikhail Potapov</title>
      <link>https://forem.com/mpotapov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mpotapov"/>
    <language>en</language>
    <item>
      <title>Optimizing Angular Applications: Removing NgRx DevTools in Production 🚀</title>
      <dc:creator>Mikhail Potapov</dc:creator>
      <pubDate>Tue, 23 May 2023 04:49:03 +0000</pubDate>
      <link>https://forem.com/mpotapov/optimizing-angular-applications-removing-ngrx-devtools-in-production-3i23</link>
      <guid>https://forem.com/mpotapov/optimizing-angular-applications-removing-ngrx-devtools-in-production-3i23</guid>
      <description>&lt;p&gt;When developing an Angular application with NgRx, the NgRx DevTools can be incredibly useful for debugging and monitoring state changes. However, when it comes to deploying your application to production, it's a good idea to remove the devtools from your bundle and avoid loading them unnecessarily. This article will guide you through the process of configuring target-specific file replacements to achieve this.&lt;/p&gt;

&lt;p&gt;To begin, you'll need to create two files that handle the NgRx DevTools providers. Let's call them &lt;strong&gt;&lt;code&gt;ngrx-devtools.development.ts&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;ngrx-devtools.ts&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;&lt;code&gt;ngrx-devtools.development.ts&lt;/code&gt;&lt;/strong&gt; file, import the necessary functions from &lt;strong&gt;&lt;code&gt;@ngrx/store-devtools&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;@angular/core&lt;/code&gt;&lt;/strong&gt;. Then, define a constant named &lt;strong&gt;&lt;code&gt;ngrxDevtools&lt;/code&gt;&lt;/strong&gt; that provides the NgRx DevTools configuration.&lt;/p&gt;

&lt;p&gt;Here's an example of what the &lt;strong&gt;&lt;code&gt;ngrx-devtools.development.ts&lt;/code&gt;&lt;/strong&gt; file may look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;provideStoreDevtools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@ngrx/store-devtools&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDevMode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ngrxDevtools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;provideStoreDevtools&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;maxAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;logOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isDevMode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, in the &lt;strong&gt;&lt;code&gt;ngrx-devtools.ts&lt;/code&gt;&lt;/strong&gt; file, define a constant named &lt;strong&gt;&lt;code&gt;ngrxDevtools&lt;/code&gt;&lt;/strong&gt; as an array of &lt;strong&gt;&lt;code&gt;EnvironmentProviders&lt;/code&gt;&lt;/strong&gt;. This step ensures that when file replacement is applied in production, an empty array is used instead of the actual devtools configuration.&lt;/p&gt;

&lt;p&gt;Here's an example of what the &lt;strong&gt;&lt;code&gt;ngrx-devtools.ts&lt;/code&gt;&lt;/strong&gt; file may look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;EnvironmentProviders&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ngrxDevtools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;EnvironmentProviders&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can provide the NgRx DevTools configuration in your application's bootstrap file, such as &lt;strong&gt;&lt;code&gt;main.ts&lt;/code&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;code&gt;app.module.ts&lt;/code&gt;&lt;/strong&gt;. Import the &lt;strong&gt;&lt;code&gt;ngrxDevtools&lt;/code&gt;&lt;/strong&gt; constant from the &lt;strong&gt;&lt;code&gt;ngrx-devtools.ts&lt;/code&gt;&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Here's an example of how you can provide the NgRx DevTools configuration in your bootstrap file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ngrxDevtools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./devtools/ngrx-devtools&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;bootstrapApplication&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[...,&lt;/span&gt; &lt;span class="nx"&gt;ngrxDevtools&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, don't forget to add the configuration to the angular.json file for file replacements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;projects&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app-name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;architect&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;configurations&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fileReplacements&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
              &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;replace&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/devtools/ngrx-devtools.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;with&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/devtools/ngrx-devtools.development.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
              &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During development, when you are in the development mode, the NgRx DevTools will be included and function as expected. However, when you switch to production mode, the file replacement configuration takes effect. The appropriate file is replaced, and the NgRx DevTools are not included in your production code, resulting in smaller bundle sizes and potentially saving a couple of kilobytes.&lt;/p&gt;

&lt;p&gt;Remember to adjust the paths and file names according to your project structure. With this setup, you can enjoy the benefits of NgRx DevTools during development while keeping your production bundles streamlined and efficient.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>ngrx</category>
    </item>
    <item>
      <title>🔥 Naming Interfaces in TypeScript: IUser vs User</title>
      <dc:creator>Mikhail Potapov</dc:creator>
      <pubDate>Wed, 17 May 2023 17:14:42 +0000</pubDate>
      <link>https://forem.com/mpotapov/naming-interfaces-in-typescript-iuser-vs-user-2cpn</link>
      <guid>https://forem.com/mpotapov/naming-interfaces-in-typescript-iuser-vs-user-2cpn</guid>
      <description>&lt;p&gt;In TypeScript, it is common for developers to prefix their interfaces with "I" (e.g., IUser) following the Hungarian notation. However, not all developers adhere to this convention.&lt;/p&gt;

&lt;p&gt;I used to prefer using the "I" prefix for my interfaces as I believed it improved the reliability and clarity of my code. I also extended this convention to types, like TUser.&lt;/p&gt;

&lt;p&gt;However, I encountered an issue when I needed to convert some interfaces into types, specifically when my interface became a union type of other interfaces. This necessitated replacing all the "I" prefixes with "T" throughout the codebase. These changes proved to be cumbersome, unnecessary. This issue has occurred multiple times for me and my colleagues, leading us to abandon the use of the "I" prefix.&lt;/p&gt;

&lt;p&gt;I would like to know your thoughts on this matter. Do you also use prefixes for your interfaces?&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>ChatGPT, Copilot and Programmers: Collaboration or Substitution?</title>
      <dc:creator>Mikhail Potapov</dc:creator>
      <pubDate>Tue, 16 May 2023 17:30:22 +0000</pubDate>
      <link>https://forem.com/mpotapov/chatgpt-copilot-and-programmers-collaboration-or-substitution-47a2</link>
      <guid>https://forem.com/mpotapov/chatgpt-copilot-and-programmers-collaboration-or-substitution-47a2</guid>
      <description>&lt;p&gt;Generative neural networks such as ChatGPT can create text, code, and images based on given queries. ChatGPT, developed by OpenAI, has gained enormous popularity and attracted one million users in just 5 days. It stands out for its ability to understand context and engage in meaningful dialogues.&lt;/p&gt;

&lt;p&gt;The success of ChatGPT led Microsoft to invest $10 billion in OpenAI, recognizing the future potential of generative neural networks. However, while these networks have proven their usefulness in writing code, they are not expected to completely replace programmers. Programmers still play a critical role in formulating tasks, testing code, and ensuring maintainability.&lt;/p&gt;

&lt;p&gt;Programmers must create error-free and readable code because changes may be needed at any time. They must also understand the project's context, including existing code, business logic, code design standards, and interactions with other services and APIs. Training a neural network to fully understand these aspects requires a significant amount of time, specific context, and a lot of data.&lt;/p&gt;

&lt;p&gt;Generative neural networks such as Copilot have the potential to change the programming profession. They force programmers to break down tasks into smaller components for which code can be generated by a neural network, and programmers are responsible for testing and combining those pieces of code. Copilot has already attracted more than a million programmers and improved their efficiency.&lt;/p&gt;

&lt;p&gt;The introduction of Copilot and similar tools may raise concerns about job cuts in programming. However, history shows that increases in programmer efficiency caused by advances such as high-level programming languages have not led to massive job losses. The demand for code continues to grow, and there are still many unresolved problems that require human expertise.&lt;/p&gt;

&lt;p&gt;While Copilot can be a useful tool for automating routine tasks in development, its use as a mandatory tool can also make it difficult to get started in the profession. Automating routine tasks reduces their volume, but more complex tasks require greater understanding and expertise.&lt;/p&gt;

&lt;p&gt;In conclusion, the interaction between generative neural networks such as ChatGPT and Copilot and programmers is a collaboration, not a complete replacement. Programmers will continue to play a key role in development because they have the necessary contextual understanding of the project and can provide flexibility and development.&lt;/p&gt;

</description>
      <category>programmers</category>
      <category>discuss</category>
      <category>development</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>Solving the mystery: where are the promises in the Node.js event loop?</title>
      <dc:creator>Mikhail Potapov</dc:creator>
      <pubDate>Tue, 16 May 2023 06:12:10 +0000</pubDate>
      <link>https://forem.com/mpotapov/solving-the-mystery-where-are-the-promises-in-the-nodejs-event-loop-207c</link>
      <guid>https://forem.com/mpotapov/solving-the-mystery-where-are-the-promises-in-the-nodejs-event-loop-207c</guid>
      <description>&lt;p&gt;When I started learning Node.js and became familiar with the event loop, I asked myself the question: In what phase is the promise fulfilled? I could not find an explicit answer to this question in the &lt;a href="https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The event loop in Node.js consists of several phases, each responsible for handling different types of asynchronous operations. Promises, which are a fundamental part of asynchronous programming in JavaScript, are executed in the corresponding phase of the event loop.&lt;/p&gt;

&lt;p&gt;The diagram below shows the phases of the event loop:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftx1i72wm9bl7zxij292s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftx1i72wm9bl7zxij292s.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timers&lt;/strong&gt;: In this phase, callbacks to scheduled timers are executed. These timers can be created with functions like &lt;code&gt;setTimeout()&lt;/code&gt; or &lt;code&gt;setInterval()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pending callbacks&lt;/strong&gt;: This phase performs callbacks for system operations. It includes callbacks for I/O events, network operations, or other asynchronous tasks that have completed but are waiting to be processed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Idle, prepare&lt;/strong&gt;: These phases are used internally by Node.js (libuv in particular) and are not managed directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Poll&lt;/strong&gt;: The polling phase is responsible for timing and processing I/O events. It waits for new I/O events and calls them back. If there are no pending I/O events, it may block and wait for new events to arrive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check&lt;/strong&gt;: This phase handles callbacks scheduled with &lt;code&gt;setImmediate()&lt;/code&gt;. It makes immediate callbacks immediately after the polling phase, regardless of whether the polling phase was active or blocked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Close callbacks&lt;/strong&gt;: In this phase, callbacks associated with "close" events are executed. For example, when a socket or file is closed, the corresponding close event callback is executed in this phase.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, what about promises?
&lt;/h2&gt;

&lt;p&gt;While the main phases were mentioned earlier, it is important to note that there are other tasks that occur between each of these phases. These tasks include &lt;code&gt;process.nextTick()&lt;/code&gt; and the microtask queue (which is where promises appear).&lt;/p&gt;

&lt;p&gt;Our schema now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0zrwie00avi9vmv2n99.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0zrwie00avi9vmv2n99.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The microtask queue is processed as soon as the current phase of the event loop ends, before moving on to the next phase. This ensures that promise callbacks are completed as quickly as possible without waiting for the next iteration of the event loop.&lt;/p&gt;

&lt;p&gt;If you, like me, have been looking for an answer to this question, I hope this article has given you the clarity you were looking for. Understanding when promises are executed in the Node.js event loop is essential to effective asynchronous programming. I hope this explanation was helpful to you, allowing you to use promises confidently in your Node.js applications.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>node</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
