<?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: Cample.js</title>
    <description>The latest articles on DEV Community by Cample.js (@camplejs).</description>
    <link>https://dev.to/camplejs</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%2F984350%2F2805ac7b-6d86-491f-b9b0-b24592ef9f35.png</url>
      <title>DEV Community: Cample.js</title>
      <link>https://dev.to/camplejs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/camplejs"/>
    <language>en</language>
    <item>
      <title>How does a non-keyed implementation differ from keys in javascript frameworks?</title>
      <dc:creator>Cample.js</dc:creator>
      <pubDate>Tue, 19 Sep 2023 07:24:06 +0000</pubDate>
      <link>https://dev.to/camplejs/how-does-a-non-keyed-implementation-differ-from-keys-in-javascript-frameworks-407f</link>
      <guid>https://dev.to/camplejs/how-does-a-non-keyed-implementation-differ-from-keys-in-javascript-frameworks-407f</guid>
      <description>&lt;p&gt;Often, when developing websites using frameworks, little attention is paid to the details that are included in this framework. And this is normal, because the main task of the framework is to make it convenient to create a website and to make it fast and functional. But these details are interesting because, having learned some points, the view of JavaScript development is slightly supplemented.&lt;/p&gt;

&lt;p&gt;One such detail is the keyed implementation. What it is?&lt;/p&gt;

&lt;p&gt;Keyed implementation is first of all creating an association between the data and the DOM node. That is, when the data changes, thanks to this implementation, the DOM nodes themselves change. Non-keyed is thus not entirely related to the DOM node.&lt;/p&gt;

&lt;p&gt;Most frameworks today have a special design that repeats DOM nodes depending on the data. Let’s say in a framework like &lt;a href="https://github.com/Camplejs/Cample.js"&gt;Cample.js&lt;/a&gt; this construct (keyed) is the each:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const tableRows = each(
  "rows-component",
  ({ importedData }) =&amp;gt; importedData.data,
  `&amp;lt;tr key={{index}}&amp;gt;
    &amp;lt;td&amp;gt;{{value}}&amp;lt;/td&amp;gt;
   &amp;lt;/tr&amp;gt;
  `,
  {
    import: {
      value: [],
      exportId: "mainExport",
    },
  }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, there will be such a construction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;input type="text"/&amp;gt;val1&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;input type="text"/&amp;gt;val2&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;input type="text"/&amp;gt;val3&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, what will happen if new data arrives in the non-keyed implementation, where there will be an array, but not with three elements, but with two? And also, if some data is entered into the input, what will happen there when two elements arrive in this loop construction?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;input value="1" type="text"/&amp;gt;val1&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;input value="2" type="text"/&amp;gt;val2&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;input value="3" type="text"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will be something like this if the data looks 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;const data = ["val1", "val3"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTML itself will look like this if you also enter some data into the input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;input value="1" type="text"/&amp;gt;val1&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;input value="2" type="text"/&amp;gt;val3&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is, it is clear that in a non-keyed implementation, information in DOM nodes is not stored in the same way as it would be in a keyed implementation, because there is no association due to the key.&lt;/p&gt;

&lt;p&gt;Thus, two data arrays are compared, where there used to be 3 elements, but now there are 2, which means the data has decreased by 1 unit, and then the last block in the DOM must be deleted, because there is no association with the key. If there was an association, the code would 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;&amp;lt;div&amp;gt;&amp;lt;input value="1" type="text"/&amp;gt;val1&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;input value="3" type="text"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be compared with id when creating a database, when, for example, there would be no id, then rows would be deleted not by id, but by the difference between old data and new data.&lt;/p&gt;

&lt;p&gt;Of course, this is one of the small examples of what features javascript frameworks have, but it’s probably all the more interesting to work with them and create websites thanks to them.&lt;/p&gt;

&lt;p&gt;I hope you found this article interesting. Thank you very much for reading!&lt;/p&gt;

&lt;p&gt;Links:&lt;br&gt;
&lt;a href="https://camplejs.github.io/documentation/each.html"&gt;https://camplejs.github.io/documentation/each.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Camplejs/Cample.js"&gt;https://github.com/Camplejs/Cample.js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>How to render components in javascript?</title>
      <dc:creator>Cample.js</dc:creator>
      <pubDate>Mon, 05 Dec 2022 04:30:51 +0000</pubDate>
      <link>https://dev.to/camplejs/how-to-render-components-in-javascript-18b1</link>
      <guid>https://dev.to/camplejs/how-to-render-components-in-javascript-18b1</guid>
      <description>&lt;p&gt;Hello everyone! Often, when creating components, the question of their rendering arises. This is a rather interesting question, the solution of which can be one of the methods described in this article.&lt;/p&gt;

&lt;p&gt;If the component is made through a class, then a &lt;em&gt;render&lt;/em&gt; function can be created for this component.&lt;br&gt;
&lt;code&gt;class Component{ &lt;br&gt;
 constructor(selector,template,options){&lt;br&gt;
  this.selector=selector;&lt;br&gt;
  this.template=template;&lt;br&gt;
  this.options=options;&lt;br&gt;
}&lt;br&gt;
render(){&lt;br&gt;
 document.querySelectorAll(this.selector).forEach(&lt;br&gt;
 (e) =&amp;gt; {e.insertAdjacentHTML("afterbegin",this.template);}}}&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This function will find the selector of the corresponding tag of this component on the page, and add HTML markup to this selector.&lt;/p&gt;

&lt;p&gt;Having created an instance of the class of this component, it can be passed to the class that calls the given render function on an instance of the component class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class Cample {&lt;br&gt;
 render(options = {component}){&lt;br&gt;
 Object.keys(options)&lt;br&gt;
 .forEach((component) =&amp;gt; {options[component].render();&lt;br&gt;
 });&lt;br&gt;
}}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using this method, components are rendered.&lt;/p&gt;

&lt;p&gt;Thank you very much everyone for reading this article!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Camplejs/Cample.js" rel="noopener noreferrer"&gt;cample.js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
  </channel>
</rss>
