<?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: Rubin Elezi</title>
    <description>The latest articles on Forem by Rubin Elezi (@rubinelezi).</description>
    <link>https://forem.com/rubinelezi</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%2F517509%2Ff644ba61-55bf-4249-a843-ac2d61f501ba.jpg</url>
      <title>Forem: Rubin Elezi</title>
      <link>https://forem.com/rubinelezi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rubinelezi"/>
    <language>en</language>
    <item>
      <title>Break the problem</title>
      <dc:creator>Rubin Elezi</dc:creator>
      <pubDate>Tue, 16 Aug 2022 13:18:16 +0000</pubDate>
      <link>https://forem.com/rubinelezi/break-the-problem-4obg</link>
      <guid>https://forem.com/rubinelezi/break-the-problem-4obg</guid>
      <description>&lt;p&gt;When I was starting with programming, every time I wanted to build something I got scared. I started overthinking the problem and the complexity, saying how much work is to be done. &lt;/p&gt;

&lt;p&gt;And I didn’t just say it because I was lazy or something, but it really felt overwhelming at the time. Even if it was a small thing to be built. And I believe that also happened to everyone when starting out. &lt;/p&gt;

&lt;p&gt;That's why today I want to share with you how to break the “problem” and walk you through my process of work. &lt;/p&gt;

&lt;p&gt;NOTE: Through this article, when I say “problem”, it can also be a feature, an app, a website, or anything that you build/code.&lt;/p&gt;

&lt;p&gt;First things first, coding is the last thing you should do, yes, and also probably the easiest. It will make sense in a moment, as you go through the process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Understand the problem and do the research&lt;br&gt;
This seems obvious, but depending on the complexity of the problem, take your time to analyse it, and don’t be afraid to ask questions. If it is a feature, take some time and look for solutions online (DO NOT COPY PASTE 😂), purpose is to take inspiration and ideas. If possible review multiple solutions and follow the best approach you can find. &lt;br&gt;
By doing this step you will start to feel less “scared” because you will see that it can be done and the blur starts to come off.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Solve it in your mind&lt;br&gt;
Then you should think of the solution from your app viewpoint, think of how your app is structured, and how you can start applying the solution based on this. What will be the components, and how will the data flow? Usually, it is best if you use a piece of paper or something to write on.&lt;br&gt;
You should not write the code on paper, only the idea, for example:&lt;br&gt;
You have to create a button that deletes items from an array. In this step, you think about where this button component will be placed, how it will get the data from the main component, etc &lt;strong&gt;You don’t have to write the actual code that deletes the data from the array&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code it&lt;br&gt;
And this part is straightforward and usually the easiest, but it requires work. By now you understand the problem, you have the solution on mind/paper, and now you implement it. (Here you write the function to delete the item from the array 😅)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Stop touching the DOM, damn it!</title>
      <dc:creator>Rubin Elezi</dc:creator>
      <pubDate>Sat, 06 Feb 2021 12:21:23 +0000</pubDate>
      <link>https://forem.com/rubinelezi/stop-touching-the-dom-damn-it-41lo</link>
      <guid>https://forem.com/rubinelezi/stop-touching-the-dom-damn-it-41lo</guid>
      <description>&lt;h1&gt;
  
  
  DOM operations are expensive.
&lt;/h1&gt;

&lt;p&gt;Leaving the DOM alone is a big topic in JavaScript optimization. The classic example is appending an array of list items: if you append each of these to the DOM individually, it is considerably slower than appending them all at once.&lt;/p&gt;

&lt;h1&gt;
  
  
  Reflow
&lt;/h1&gt;

&lt;p&gt;DOM operations are resource-heavy because of reflow. Reflow is basically the process by which the browser re-renders the DOM elements on the screen. For instance, if you change the width of a div with JavaScript, the browser has to refresh the rendered page to account for this change. Meaning every time you change something on the DOM with javascript the whole page will be rerendered, and you can avoid this by using, documentFragment.&lt;/p&gt;

&lt;h1&gt;
  
  
  documentFragment
&lt;/h1&gt;

&lt;p&gt;You can view this as a container holding all the node elements that you want to add to the DOM. You store them on this "container" and after you have finished all the changes that you want, you append that container to the DOM. Imagine if you wanted to add 100 div tags if you append them directly the browser would have to rerender the page 100 times, expensive, but if you use documentFragment the browser would need to render only once.&lt;br&gt;&lt;br&gt;
Do you go to the store 100 times to buy 100 things, or do you buy them all at once?&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Before

var trash &lt;span class="o"&gt;=&lt;/span&gt; document.getElementById&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"trash"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
// ... Modify trash
document.getElementById&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"target"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;.appendChild&lt;span class="o"&gt;(&lt;/span&gt;trash&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
After

var trash &lt;span class="o"&gt;=&lt;/span&gt; document.getElementById&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"trash"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
var frag &lt;span class="o"&gt;=&lt;/span&gt; document.createDocumentFragment&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
frag.appendChild&lt;span class="o"&gt;(&lt;/span&gt;trash&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
// ... Modify trash
document.getElementById&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"target"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;.appendChild&lt;span class="o"&gt;(&lt;/span&gt;frag.cloneNode&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;true&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The speed improvements might not be so obvious on browsers, as modern computers are so powerful, but javascript does not run only on modern and powerful devices. I develop applications for smartTV-s at my current job, using HTML, CSS, JS, the performance impact it had on the old model of TV-s is subsectional. I had to make changes to a library we were using to implement this behavior, the results were good for me and I thought to share it with others.&lt;/p&gt;

&lt;p&gt;Thank You!&lt;/p&gt;

&lt;p&gt;PS: this is my first blog post :P&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>dom</category>
      <category>performance</category>
      <category>html</category>
    </item>
  </channel>
</rss>
