<?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: Muhammed Erdinç</title>
    <description>The latest articles on DEV Community by Muhammed Erdinç (@muhammederdinc).</description>
    <link>https://dev.to/muhammederdinc</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%2F1033066%2Fbdc60c27-8802-4259-a6c8-584b49a234fa.jpeg</url>
      <title>DEV Community: Muhammed Erdinç</title>
      <link>https://dev.to/muhammederdinc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhammederdinc"/>
    <language>en</language>
    <item>
      <title>JavaScript Closures: Understanding the Power of Functions</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 31 May 2023 13:06:42 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/javascript-closures-understanding-the-power-of-functions-2aa5</link>
      <guid>https://dev.to/muhammederdinc/javascript-closures-understanding-the-power-of-functions-2aa5</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i8ZGECn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2576/1%2AePsvzjKHRlVWwfd-tLmAqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i8ZGECn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2576/1%2AePsvzjKHRlVWwfd-tLmAqw.png" alt="" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript closures are constructs that allow nested functions to be written, allowing the inner function to access the outer function’s variables. In this way, data sharing between different functions is facilitated and changes in one function are reflected in other functions. Also, closures help make code more modular and scalable. In this article, we’ll take an in-depth look at JavaScript closures and learn about their use, advantages, and examples.&lt;/p&gt;

&lt;p&gt;Before we deal with the subject in detail, we need to touch on Lexical scoping. In this way, it will be much easier to understand the subject.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lexical Scoping
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BhoY1zG4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A066phSvwoUUftIhiRF5hlA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BhoY1zG4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A066phSvwoUUftIhiRF5hlA.png" alt="" width="735" height="698"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, Lexical scoping is used when determining the scope of a function. This means that a variable is scoped based on where it is defined. That is, a variable defined inside a function is valid inside that function and within the scope of functions defined within it. However, it cannot access the scope of outside functions. For example, let’s examine the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  let outerVariable = 'I am outside!';

  function innerFunction() {
    let innerVariable = 'I am inside!';
    console.log(innerVariable); // Output: "I am inside!"
    console.log(outerVariable); // Output: "I am outside!"
  }

  innerFunction();
}

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

&lt;/div&gt;

&lt;p&gt;In this code, innerFunction function is defined inside outerFunction function. So the scope of innerFunction also includes the scope of outerFunction. Therefore, the variables innerFunction, innerVariable, and outerVariable are accessible. However, it is not possible to access these variables from outside the outerFunction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scoping in JavaScript: Let &amp;amp; Const
&lt;/h3&gt;

&lt;p&gt;In JavaScript, var, let, and const keywords are used to declare variables.&lt;/p&gt;

&lt;p&gt;Variables defined with var can be defined in function scope or global scope. However, they do not provide block coverage. That is, a var variable can be accessed outside the block in which it is defined. This can make the code less reliable and cause errors.&lt;/p&gt;

&lt;p&gt;let and const are new keywords that come with ES6. Variables defined with let and const are defined at block scope. That is, a let or const variable cannot be accessed outside of the block in which it is defined. This makes the code more reliable.&lt;/p&gt;

&lt;p&gt;The difference between let and const is whether the variable’s value is mutable or not. The values ​​of variables defined with let can be changed, while the values ​​of variables defined with const are fixed and cannot be changed later.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sayHello() {
  var name = "John";

  if (true) {
    var name = "Jane";
    console.log(name); // "Jane"
  }

  console.log(name); // "Jane"
}

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

&lt;/div&gt;

&lt;p&gt;In the example above, a var variable named name is defined inside the sayHello function with an initial value of “John”. Later, another var variable named name is defined inside the if block with an initial value of “Jane”. However, the important point to note is that the name variable inside the if block changes the value of the name variable outside the function.&lt;/p&gt;

&lt;p&gt;Let’s now examine the same example for let.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sayHello() {
  let name = "John";

  if (true) {
    let name = "Jane";
    console.log(name); // "Jane"
  }

  console.log(name); // "John"
}

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

&lt;/div&gt;

&lt;p&gt;In the above example, the inner let variable name provides block scoping and is only valid within that block. The outer let name variable is valid within the function’s main scope. Thus, the first console.log statement returns the result “Jane”, while the second console.log statement returns the result “John”.&lt;/p&gt;

&lt;p&gt;The topic of closures is closely related to lexical scoping. When closures are used, variables and functions defined within a function remain within the scope of that function and cannot be used elsewhere. This is one of the fundamental principles of lexical scoping. Now that we have briefly touched on the subject of lexical scoping, we can return to our main topic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closure
&lt;/h2&gt;

&lt;p&gt;In JavaScript, functions can be assigned to variables like other data types, can be returned as the result of a function, and can be used inside other functions.&lt;/p&gt;

&lt;p&gt;A variable defined inside a function is valid only within its scope. That is, code outside the function cannot access this variable.&lt;/p&gt;

&lt;p&gt;Closure refers to the situation where the inner function can access the scope of the outer function and the variables defined in it can be used in this scope.&lt;/p&gt;

&lt;p&gt;Also, after a closure is created, the values ​​of these variables are retained until the end of the runtime of the functions called from outside to access the variables inside. In this way, variables defined within a function remain accessible even after the function has finished running.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function counter() {
  let count = 0;

  function incrementCount() {
    count++;
    console.log(count);
  }

  return incrementCount;
}

const myFunc = counter(); // Closure is created

myFunc(); // output: 1
myFunc(); // output: 2
myFunc(); // output: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the example above, the counter() function returns a closure. This closure is the incrementCount() function that accesses the count variable defined in it. The counter() function we assign to the myFunc variable returns the incrementCount() function, creating a closure.&lt;/p&gt;

&lt;p&gt;When myFunc()is called afterwards, the value of the count variable inside the closure is incremented and printed to the console. Since this function works in conjunction with the closure returned by the counter()function, it retains the final value of the count variable. This means that as long as myFunc()is called, the value of the count variable will be maintained and incremented.&lt;/p&gt;

&lt;p&gt;Let’s continue with another example now.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFunc(x) {
  return function(y) {
    return x + y;
  }
}

const sum = myFunc(4)(5);
console.log(sum); // output: 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this code, a function named myFunc is defined that takes in one argument x. This function returns another function that takes in an argument y and returns the sum of x and y.&lt;/p&gt;

&lt;p&gt;In the next line, the myFunc function is called with the argument 4, which returns a new function that adds 4 to any value passed in as y. Then, this newly returned function is immediately called with the argument 5, resulting in the sum of 4 and 5, which is 9.&lt;/p&gt;

&lt;p&gt;Finally, the value of sum (which is 9) is logged to the console using console.log().&lt;/p&gt;

&lt;p&gt;This way, myFunc function creates a closure by returning an inner function that can access the outer function's variables. Thus, the returned function can be called with different parameters and each function call will create its own closure with its own set of parameters.&lt;/p&gt;

&lt;p&gt;The following example is similar to the closure example in the previous one. When the outerFunc function is called, the value of xis stored within the function’s scope, and innerFunc1 function is returned. Then, when the innerFunc1 function is called with the y value, the value of y is also stored in the closure, and innerFunc2 function is returned. Finally, when the innerFunc2 function is called with the z value, x, y and z values are added together and the result is returned.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunc(x) {
  function innerFunc1(y) {
    function innerFunc2(z) {
      return x + y + z;
    }
    return innerFunc2;
  }
  return innerFunc1;
}

const sum = outerFunc(4)(5)(2);
console.log(sum); // output: 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Lifetime and Memory Usage of Functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pTkvAxDS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AMOP78931ZfdcTnPMnRVbPQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pTkvAxDS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AMOP78931ZfdcTnPMnRVbPQ.png" alt="" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a closure is created, the variables and functions inside the closure occupy a memory space just like other objects in memory.&lt;/p&gt;

&lt;p&gt;For example, in the following code block, an innerFunction is defined inside the outerFunction, and this inner function uses a variable called innerVariable.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  var innerVariable = 10;

  function innerFunction() {
    console.log(innerVariable);
  }

  return innerFunction;
}

var myClosure = outerFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A closure is created by assigning the outerFunction function to the variable named myClosure. In this case, innerVariable and innerFunction are retained in memory and are referenced by the myClosure variable.&lt;/p&gt;

&lt;p&gt;However, the innerVariable variable and the innerFunction function use memory unnecessarily because they are referenced by the myClosure variable. This can result in large memory usage when many shutdowns are used in the program.&lt;/p&gt;

&lt;p&gt;For instance, in the code block below, the outerFunction is called 1000 times, and each call creates a closure. Each closure occupies a memory space, and this increases the memory usage.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  var innerVariable = 10;

  function innerFunction() {
    console.log(innerVariable);
  }

  return innerFunction;
}

for (var i = 0; i &amp;lt; 1000; i++) {
  var myClosure = outerFunction();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Therefore, caution should be exercised when using closures and not creating too many closures unnecessarily.&lt;/p&gt;

&lt;h3&gt;
  
  
  References and Garbage Collection
&lt;/h3&gt;

&lt;p&gt;Closures held in memory are deleted when they are out of reference or cleared by the garbage collector. If a closure references a local variable inside a function and that reference still exists after the function has finished running, the closure remains in memory and remains accessible. However, the closure is cleared from memory when there is no reference left or it is cleared by the garbage collector.&lt;/p&gt;

&lt;p&gt;For example, if you assign a closure to a variable and then assign that variable to null or some other value, the reference to the closure is lost and the closure is cleared from memory.&lt;/p&gt;

&lt;p&gt;The following example shows how the reference of a closure is destroyed:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  var outerVariable = 'Hello';

  return function() {
    console.log(outerVariable);
  }
}

var myClosure = outerFunction();
myClosure(); // "Hello"

myClosure = null; // Closure is destroyed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, myClosure represents a closure and is a function returned from outerFunction. The myClosure function references a local variable named outerVariable. However, when myClosure’s reference is set to null, the closure is no longer referenced and is cleared from memory by the garbage collector.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closure Performance: How Can We Get Better Performance?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GvFxrZKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AkICjJuxEz_TDb-ca6Hxxkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GvFxrZKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AkICjJuxEz_TDb-ca6Hxxkg.png" alt="" width="700" height="609"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Closures are frequently used in many different use cases in JavaScript and are an essential tool for code readability and flexibility. However, they can cause performance issues if not used properly.&lt;/p&gt;

&lt;p&gt;Closures can run slower than other functions because they create a new scope with each call. Also, having a closure in memory can cause unnecessary memory usage and slowdown.&lt;/p&gt;

&lt;p&gt;However, there are some techniques to avoid performance issues with closures. The first is to use closures as little as possible. Especially when you are in a loop that requires frequent access to variables inside a closure, it is better to use local variables that can be used as loop variables rather than creating a new closure each time.&lt;/p&gt;

&lt;p&gt;It is also important to keep closures as small as possible so that they do not cause unnecessary memory usage. That is, it should not unnecessarily contain too many variables or have unnecessary features.&lt;/p&gt;

&lt;p&gt;Finally, to avoid unnecessary memory usage of a closure, it is recommended to delete its reference or set it to null when the closure is finished using it. This helps the JavaScript engine avoid unnecessary memory usage.&lt;/p&gt;

&lt;p&gt;In summary, when used correctly, closures can be a very useful feature in JavaScript. However, they can cause performance issues if misused. Keeping Closures as small and optimized as possible and their references managed properly can help avoid performance issues.&lt;/p&gt;

&lt;p&gt;In this article, we explained what closures are, how they work, how they affect memory usage, and when they are cleared from memory.&lt;/p&gt;

&lt;p&gt;I created the code samples and explanations in this article using chatgpt. I wrote the article by just proceeding with chatgpt without any preliminary research on the subject from any source (books, websites, etc.). Chatgpt can give wrong information in some cases, but in these cases, I was able to proceed easily by guiding chatgpt correctly. I hope we were able to convey the subject in a nice and detailed way with chatgpt :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>closures</category>
      <category>programming</category>
    </item>
    <item>
      <title>Creating Reusable Components with the Composition API &amp; Composables</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 29 Mar 2023 10:06:59 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/creating-reusable-components-with-the-composition-api-composables-hbh</link>
      <guid>https://dev.to/muhammederdinc/creating-reusable-components-with-the-composition-api-composables-hbh</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kb4aVP0C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ajyxbg9ccuqmzm531cf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kb4aVP0C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ajyxbg9ccuqmzm531cf.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello, I would like to share with you the article of the presentation on “Creating Reusable Components with the Composition API &amp;amp; Composables” that I explained at Teknasyon Tech 26. Online Meetup. In this article, I wanted to touch on all the topics I explained in the presentation and create a resource for those who like to read more than watch videos. Also, since the presentation is in Turkish, I wanted to explain this subject by writing an article in English.&lt;/p&gt;

&lt;p&gt;In this article, we will explore how to write reusable components with the Composition API &amp;amp; Composables that came into our lives with Vue 3, and also why we should use the Composition API and how we can use it correctly.&lt;/p&gt;

&lt;p&gt;First of all, let’s look at the problems we encountered while developing with the options API before Vue 3 and why we need Vue 3. Then, let’s try to understand how these problems are solved with Vue 3. At the end of the presentation, we will look at how we can write our composables better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don’t Repeat Yourself (DRY)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nMvqiaPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2mj83f17lzodqoklw2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nMvqiaPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2mj83f17lzodqoklw2w.png" alt="Image description" width="880" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most important principles of software development is to avoid repetitive work. Keeping our code reusable and portable is very important. In this way, we can reduce the development cost and produce products faster as a team.&lt;/p&gt;

&lt;p&gt;In this article, our aim is to see how to stay away from repetitive tasks in Vue projects and how we can do this more easily with Vue 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single-File Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iVYqsdP2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olrrzjjwpto2rl8f8ocy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iVYqsdP2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olrrzjjwpto2rl8f8ocy.png" alt="Image description" width="880" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Vue projects, files with the .vue extension are called Single-File Components(SFC). Vue SFCs allow us to encapsulate template, logic, and styling in a single file. So we can keep Html, Css and JavaScript codes in a single file. In this article, we will focus on the script part and see how we can write our Js code sustainably and how we can organize our business logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before Compisition API
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c7_VZ_UQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9ph9ns4j20ekavri13v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c7_VZ_UQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9ph9ns4j20ekavri13v.png" alt="Image description" width="880" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before the Composition API, we developed our Vue projects with the Options API. With the Options API, we thought our code was clearer and more understandable. The reason for this is that the code we will write has its own place and we knew what to add where (data, computed, methods etc).&lt;/p&gt;

&lt;p&gt;When we look at the sample code block above, we can say that our code looks very organized and easy to read and understand. So is it really so? Although it seems like a good solution for small projects, we can say that this is valid when the developed application is small and simple.&lt;/p&gt;

&lt;p&gt;As the application or components grow, things start to get complicated, especially when we start to include more than one logic in a component. Let’s say we hold more than one logic in a component. In this case, since the codes of these logics will always be written in the same blocks, it will be very troublesome to update our code, add or remove a feature. It will be very difficult to understand which method belongs to which logic or which data belongs to which logic at once.&lt;/p&gt;

&lt;p&gt;Since we cannot read our code in a certain order, it will be difficult to understand and develop the code. This will appear as a situation that negatively affects the readability of the code.&lt;/p&gt;

&lt;p&gt;If we could instead group our code by logic, it would be much easier to read and understand our code. This is exactly where the Composition API comes in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v2fukOv1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ks5hmpddqexp0b54z9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v2fukOv1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ks5hmpddqexp0b54z9e.png" alt="Image description" width="880" height="1070"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above, you can see how complex the code developed with the Options API is compared to the code developed with the Composition API. In the code example below, you can see how a code written with the Options API can be written with the Composition API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ozc_mtyg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ta1jyozo9mewq7y9kjdd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ozc_mtyg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ta1jyozo9mewq7y9kjdd.png" alt="Image description" width="880" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In summary, the Composition API enables grouping of logics. In this way, we only see the codes related to that logic while performing operations on a logic. Also it will be much easier to separate a logic from a component or add a new logic. For example, when the user logic written with the Composition API in the code above is wanted to be moved to another place, it will be much easier to remove the relevant code from the component since the logic is already grouped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Repetitive Work with Options API
&lt;/h2&gt;

&lt;p&gt;As you can imagine, the advantages of the Composition API are not limited to these. There was a topic we mentioned at the beginning of the article. One of the most important principles of software development is to avoid repetitive work. The languages ​​and tools we use provide solutions to help us avoid repetitive work, and these solutions evolve and change throughout the process.&lt;/p&gt;

&lt;p&gt;Now, let’s take a look at what solutions we use to avoid repetitive works while developing with the Options API, and why these solutions are insufficient, with examples.&lt;/p&gt;

&lt;p&gt;For example, when we want to use a function or code block that we use in a Component throughout the project, let’s look at how we do this with the Options API and what problems we encounter. Next, let’s look at how to solve these problems with the Composition API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Utility Functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OXtqEif6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmd79chycsgb5d7tg2j0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OXtqEif6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmd79chycsgb5d7tg2j0.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first of these solutions is Utility Functions. In summary, Utility Functions are structures that can take parameters from outside and allow us to encapsulate small code blocks that we expect to return a value as a result. But their use is limited because we cannot define and use vue specific properties (reactive variables, mounted, created etc) inside these functions.&lt;/p&gt;

&lt;p&gt;When we examine the image above, you can see that the increment function is defined, but the count reactive variable cannot be defined in the function, so it is defined in the component. Here, utility functions are insufficient when we want to encapsulate the count variable or use other vue-specific properties.&lt;/p&gt;

&lt;h2&gt;
  
  
  Renderless Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jaNTocbX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njmps1drq1meapc1tabf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jaNTocbX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njmps1drq1meapc1tabf.png" alt="Image description" width="880" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Renderless Components is a feature that doesn’t render any html and we can use vue specific properties. When we look at the example in the image above, we see an example of a code that shows the x and y coordinates of the mouse instantly, with a renderless component. Here we can see that we can use vue specific features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mixins
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-DWoYfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw91hgf6hfmgf67l21oq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-DWoYfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw91hgf6hfmgf67l21oq.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another method we can use to encapsulate complex code blocks is Mixins. We can say that it was an official way to share code between components, especially when developing with the Options API. Thanks to Mixins, we can encapsulate our business logics and use them in more than one place in our project.&lt;/p&gt;

&lt;p&gt;We can learn about the use of mixins by looking at the code example in the image above. Looking at the example, we can see that we can use vue specific features inside mixins.&lt;/p&gt;

&lt;p&gt;Although Mixins seem like a very good solution, they can have serious disadvantages. Due to these disadvantages, the use of mixins is not recommended today. Let’s look at these disadvantages together.&lt;/p&gt;

&lt;p&gt;One of these disadvantages is that when we use more than one mixin in a component, we cannot understand at first glance which feature comes from which mixin.&lt;/p&gt;

&lt;p&gt;Another disadvantage is that there are reactive variables or methods with the same name in different mixins. When we use mixins with the same reactive variables or methods in the same component, conflicts will occur and the code will work incorrectly.&lt;/p&gt;

&lt;p&gt;Mixins can be used with Vue 3 but are not recommended. There is now a much better way to encapsulate a code block that contains Vue features. Now let’s examine it together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composables
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9mCl4UQW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb7o8nuzi56t76ug3b9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9mCl4UQW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb7o8nuzi56t76ug3b9i.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most important feature of the Composition API is the Composables. With Composables, we can turn code blocks that contain reactivity into reusable modules. In this way, we can easily use a code in more than one place. However, it is not only for creating global code blocks, but also for separating multiple logic in a component and making the code more readable. Let’s go through the examples and examine the composables.&lt;/p&gt;

&lt;p&gt;For example, let’s say we want to write a code that gives the instant coordinate information of the mouse. We have seen how we can do this with renderless components, now we can understand how we can do this with the Composition API by looking at the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C_YdWRcZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikn1yo6wly51462f9w48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C_YdWRcZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikn1yo6wly51462f9w48.png" alt="Image description" width="880" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s imagine that we want to use the code developed with the Composition API above in more than one place in the project. The method we can use here is composables.&lt;/p&gt;

&lt;p&gt;When we turn the above code into a composable function, our code will be as follows. When we look at the example below, we can see that we can convert our code into a composable function by copy-pasting directly. One of the biggest advantages of the Composition API is that we can easily move our code to another location with almost no changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ITjtukSn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vqxuqiozo83u1lmezvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ITjtukSn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vqxuqiozo83u1lmezvy.png" alt="Image description" width="880" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is quite simple to use the useMouse composable function that we wrote above in any component. All we have to do is import and start using. In the image below, you can see how easily a composable function can be used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GyZ2U7Jn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ls5gtvawdsc4jcxpvs72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GyZ2U7Jn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ls5gtvawdsc4jcxpvs72.png" alt="Image description" width="880" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Composables vs Mixins
&lt;/h2&gt;

&lt;p&gt;When we look at the examples of Composable functions, we can see that the disadvantages we experience with mixins are not experienced.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For example, when we use more than one mixin, it was difficult to understand which feature came from which mixin at first glance, but when we use the refs + destructure model, we can easily understand which feature comes from which Composable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Another disadvantage of Mixins is Namespace collisions. We can avoid namespace collisions by renaming with destructure in Composables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Another advantage is that the values ​​returned from Composable can be passed as arguments to one another, just like regular functions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can nest Composables. In this way, we can combine small logics to form larger ones. This is similar to how we use components while developing a web application. When developing a web application, we create larger components by combining small components. In this way, we can develop large web applications without repeating ourselves. We can do the same for our logics. This will allow us to avoid repetitive tasks and save time.&lt;/p&gt;

&lt;p&gt;Looking at the example below, we can see how we can nest composables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lF-xtMn2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qbg65d2hnhoswkgutmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lF-xtMn2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qbg65d2hnhoswkgutmd.png" alt="Image description" width="880" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7XQbqyzf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seove523zk1tzmdli3jz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7XQbqyzf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seove523zk1tzmdli3jz.png" alt="Image description" width="880" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking at the example, we can see that we have created a separate composable for the event listener and can use it in another composable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KnoNY9fX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9txf6v0ldpbwb5823k1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KnoNY9fX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9txf6v0ldpbwb5823k1b.png" alt="Image description" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While developing with the Composition API, we mentioned that we can separate our codes according to logics. For example, let’s say we want to write a composable function. The fact that this function we will write has a certain order in itself will increase the readability of the code. When we look at the example above, you can see that the variables are defined as a block in the code and the functions are written as a separate block. Writing Vue-specific (computed, wathers, etc.) features in separate blocks in a certain order will increase the readability of the code. As in the code example at the bottom of the image above, we can separate these blocks with comment lines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding Better Composables
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6JyE3-tK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxp4fmtuaowqi5f1ncsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6JyE3-tK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxp4fmtuaowqi5f1ncsd.png" alt="Image description" width="880" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We looked at code examples related to Composition API and Composables together. We’ve seen that Composables allow us to separate the logic in our code into functions that we can use over and over again. We mentioned that this also makes the code easier to write and read.&lt;/p&gt;

&lt;p&gt;Now let’s see how we can write our composables better together. While I was preparing for this subject, there were many sources that I examined, but among these sources, the article “Coding Better Composables” written by Michael Thiessen especially caught my attention. He summarized the subject very well with his way of handling the subject and simple examples. I would definitely recommend checking out the article series. Since this subject is explained very well in the article I mentioned, I would like to explain the subject with the examples there. Since we will proceed in this article without going into too much detail, I recommend that you review the relevant article for detailed information.&lt;/p&gt;

&lt;p&gt;While giving information about the subject, we will proceed with code examples again. This time we will use the VueUse library for code examples. VueUse library is an open source library with composables. In this library, we will examine how composables are written. In this way, we will understand what we should pay attention to when writing our own composables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Options Object Parameter
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pkIb6dk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mmgw8svpmue3xvjslb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pkIb6dk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mmgw8svpmue3xvjslb5.png" alt="Image description" width="880" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most Composables can have one or more parameters. Instead of passing many parameters to our function, we can pass them all as a single object. We can continue with the object destructure inside the function. It will be advantageous for us to pass parameters other than one or two parameters as objects.&lt;/p&gt;

&lt;p&gt;First, we don’t need to know the order of the parameters. Sorting doesn’t matter as long as we pass parameters as objects. In this way, we can prevent possible errors.&lt;/p&gt;

&lt;p&gt;Secondly, we can understand what the parameters we pass as objects do from the naming of the properties. This will make our code more readable.&lt;/p&gt;

&lt;p&gt;Now let’s look at an example on this subject together. We can see how this is done in the useTitle composable in the VueUse library. The useTitle composable is pretty simple. It allows us to set the title of the page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1G2JAhIL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kecs8a1ihnwdh1pcma76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1G2JAhIL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kecs8a1ihnwdh1pcma76.png" alt="Image description" width="880" height="1109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we look at the example here, other parameters other than the title parameter are taken as options object. We can proceed in this way in the composables we have written.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flexible Arguments
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VgKm8DS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sljhwad5t92e9h47wxrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VgKm8DS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sljhwad5t92e9h47wxrg.png" alt="Image description" width="880" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We mentioned that Composables can take parameters. These parameters can be primitive javascript types (string, number) as well as reactive variables. In some cases we may want the parameter to be a reactive variable no matter what or a primitive type no matter what. Here, instead of specifically asking for a reactive variable or a primitive type as a parameter, we can accept both and then convert this parameter to the type we need.&lt;/p&gt;

&lt;p&gt;When we look at the above example, we can see that this operation can be done very easily with “ref” and “unref”. In this way, regardless of the type of the entered parameter, we can convert it to the type we want (reactive or primitive) and continue. In this way, we can easily avoid possible errors.&lt;/p&gt;

&lt;p&gt;Now let’s see how this can be done by going through the UseTitle example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EUjjGcrI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9igjsjcq2zbuopsgtgrz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EUjjGcrI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9igjsjcq2zbuopsgtgrz.png" alt="Image description" width="880" height="1051"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we look at the code above, we can see that whatever parameter is entered, it is made reactive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Return Values
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pnTXX4j7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eno6ba7d3126yl2axk5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pnTXX4j7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eno6ba7d3126yl2axk5u.png" alt="Image description" width="880" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composables can return a single value or an object containing multiple values. You can see both examples in the example above. useDark returns a single value, while useMouse returns an object. If we want, we can make the composable’s values ​​dynamic. We can return a single value or object according to the parameter entered from outside. We can do this very easily with a simple control. In the above example, when “controls: true” is entered, the object is returned, otherwise a single value is returned.&lt;/p&gt;

&lt;p&gt;This pattern is often a good way to simplify our code. Now let’s see how this is done in the UseNow composable in the VueUse library.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lMlwCOQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnbr1i6mcsmpenax1a5f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lMlwCOQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnbr1i6mcsmpenax1a5f.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we look at the example above, we can see that this operation is done with a simple if check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Organization
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jPNBNJF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2js15y1q05scfm90phd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jPNBNJF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2js15y1q05scfm90phd.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can use Composables not only to create global code blocks, but also for code organization. For example, as the logics increase in a component, it may become more difficult to read and understand the code. For such cases, we can create a separate composable for each logic and divide our code into small pieces. Also, we can pass a variable from one composable to another composable as a parameter. This will provide a significant advantage for code organization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a1QEjGN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1uc0on2i6wapj054o31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a1QEjGN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1uc0on2i6wapj054o31.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, I first told you about the difficulties we had before the Composition API, with examples. With these examples, we have seen why we need the Composition API and how these problems are overcome with the Composition API. Afterwards, we examined how we can write our Composables better with examples from the article “Coding Better Composables” written by Michael Thiessen.&lt;/p&gt;

&lt;p&gt;Hope what is explained will be useful to you :) You can watch my presentation on this topic below (For Turkish readers).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/bfIDcdHbIbI"&gt;https://youtu.be/bfIDcdHbIbI&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Kaynaklar
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#what-is-a-composable"&gt;https://vuejs.org/guide/reusability/composables.html#what-is-a-composable&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/vue-mastery/coding-better-composables-1-5-47c6f17d1cd3"&gt;https://medium.com/vue-mastery/coding-better-composables-1-5-47c6f17d1cd3&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#mouse-tracker-example"&gt;https://vuejs.org/guide/reusability/composables.html#mouse-tracker-example&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#conventions-and-best-practices"&gt;https://vuejs.org/guide/reusability/composables.html#conventions-and-best-practices&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/vue-mastery/coding-better-composables-flexible-arguments-2-5-6eff5983bb1"&gt;https://medium.com/vue-mastery/coding-better-composables-flexible-arguments-2-5-6eff5983bb1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#extracting-composables-for-code-organization"&gt;https://vuejs.org/guide/reusability/composables.html#extracting-composables-for-code-organization&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#comparisons-with-other-techniques"&gt;https://vuejs.org/guide/reusability/composables.html#comparisons-with-other-techniques&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/vue-mastery/coding-better-composables-dynamic-returns-3-5-3542702dd618"&gt;https://medium.com/vue-mastery/coding-better-composables-dynamic-returns-3-5-3542702dd618&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/components/slots.html#scoped-slots"&gt;https://vuejs.org/guide/components/slots.html#scoped-slots&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/the_one/are-you-using-composition-api-the-right-way-4jmm"&gt;https://dev.to/the_one/are-you-using-composition-api-the-right-way-4jmm&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.sitepoint.com/vue-composition-api-reusable-components/"&gt;https://www.sitepoint.com/vue-composition-api-reusable-components/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/scaling-up/sfc.html"&gt;https://vuejs.org/guide/scaling-up/sfc.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>vue</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Composition API ve Composable’lar ile Yeniden Kullanılabilir Component’ler Oluşturmak</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 29 Mar 2023 09:51:35 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/composition-api-ve-composablelar-ile-yeniden-kullanilabilir-componentler-olusturmak-4ph8</link>
      <guid>https://dev.to/muhammederdinc/composition-api-ve-composablelar-ile-yeniden-kullanilabilir-componentler-olusturmak-4ph8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kb4aVP0C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ajyxbg9ccuqmzm531cf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kb4aVP0C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ajyxbg9ccuqmzm531cf.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;br&gt;
Merhabalar, bugün sizlere Teknasyon Tech 26. Online Meetup’da anlatmış olduğum “Creating Reusable Components with the Composition API &amp;amp; Composables” adlı sunumun makalesini paylaşmak istiyorum. Bu yazıda sunumda değindiğim tüm konulara değinmek ve video izlemek yerine okuma yapmayı daha çok sevenler için bir kaynak oluşturmak istedim.&lt;/p&gt;

&lt;p&gt;Bu yazıda Vue 3 ile birlikte hayatımıza giren Composition API &amp;amp; Composable’larla sürdürülebilir component’ler nasıl yazılır ve ayrıca Composition API’yi neden kullanmamız gerektiğini ve bunu nasıl doğru bir şekilde kullanabileceğimizi keşfedeceğiz.&lt;/p&gt;

&lt;p&gt;Öncelikle Vue 3 öncesinde options API ile birlikte geliştirme yaparken ne gibi sorunlarla karşılaştığımıza ve Vue 3'e neden ihtiyaç duyduğumuza bakalım. Sonrasında ise Vue 3 ile birlikte bu sorunların nasıl çözüldüğünü anlamaya çalışalım. Sunumun sonlarında ise composable’larımızı daha iyi nasıl yazabileceğimize bakacağız.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don’t Repeat Yourself (DRY)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nMvqiaPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2mj83f17lzodqoklw2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nMvqiaPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2mj83f17lzodqoklw2w.png" alt="Image description" width="880" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yazılım geliştirmenin en önemli ilkelerinden biri kendimizi tekrar eden işlerden uzak durmaktır. Kodumuzu yeniden kullanılabilir ve taşınabilir tutmak oldukça önemlidir. Bu sayede geliştirme maliyetini düşürüp ekip halinde daha hızlı ürünler ortaya çıkarabiliriz.&lt;/p&gt;

&lt;p&gt;Bu yazıda da amacımız Vue projelerinde kendimizi tekrar eden işlerden nasıl uzak duracağımızı ve bunu Vue 3 ile birlikte daha kolay nasıl yapabileceğimizi göreceğiz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single-File Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iVYqsdP2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olrrzjjwpto2rl8f8ocy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iVYqsdP2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olrrzjjwpto2rl8f8ocy.png" alt="Image description" width="880" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vue projelerinde .vue uzantılı dosyalar Single-File Components(SFC) olarak adlandırılır. Vue SFC’leri template, logic ve styling’i tek bir dosyada kapsüllememize izin verir. Yani Html, Css ve JavaScript kodlarını tek bir dosyada tutabiliriz. Biz bu yazımızda script kısmına odaklanıp Js kodumuzu sürdürülebilir bir şekilde nasıl yazabileceğimizi ve Business logic’lerimizi nasıl düzenleyebileceğimizi göreceğiz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compisition API’den Öncesi
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c7_VZ_UQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9ph9ns4j20ekavri13v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c7_VZ_UQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9ph9ns4j20ekavri13v.png" alt="Image description" width="880" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composition API’den önce Vue projelerinde geliştirmelerimizi Options API ile yapıyorduk. Options API ile birlikte kodlarımızın daha net ve anlaşılır olduğunu düşünüyorduk. Bunun sebebi ise yazacağımız kodun kendi yeri var ve neyi nereye eklememiz gerektiğini biliyorduk(data, computed, methods vb).&lt;/p&gt;

&lt;p&gt;Yukarıdaki örnek kod bloğuna baktığımızda kodumuzun oldukça düzenli, okunması ve anlaşılması kolay göründüğünü söyleyebiliriz. Peki gerçekten öyle mi? Küçük projeler için düşünüldüğünde iyi bir çözüm gibi duruyor olsa da bu durumun geliştirilen uygulama küçük ve basit olduğunda geçerli olduğunu söyleyebiliriz.&lt;/p&gt;

&lt;p&gt;Uygulama veya component’ler büyüdükçe, özellikle bir component içinde birden fazla logic barındırmaya başladığımızda işler karmaşık hale gelmeye başlıyor. Bir component’te birden fazla logic tuttuğumuzu düşünelim. Bu durumda bu logic’lere ait kodlar hep aynı bloklar içinde yazılacağından kodumuzu güncellemek, yeni bi özellik eklemek veya bi özelliği çıkarmak oldukça zahmetli olacaktır. Hangi method’un hangi logic’e veya hangi data’nın hangi logic’e ait olduğunu tek seferde anlamak oldukça zor olacaktır.&lt;/p&gt;

&lt;p&gt;Bu durumda bir logic ile ilgili geliştirme yaparken kodda devamlı yukarı aşağı hareket etmek durumunda kalacak ve kodumuzu belli bi sıraya göre okuyamayacağımızdan kodu anlamak ve geliştirme yapmak zor olacaktır. Bu da kodun okunurluğunu olumsuz etkileyen bir durum olarak karşımıza çıkacaktır.&lt;/p&gt;

&lt;p&gt;Bunun yerine kodlarımızı logic’lere göre gruplayabilseydik, ilgili logic ile ilgili çalışırken sadece o logic ile ilgili kodları göreceğimizden ve kodları da kitap okur gibi belli bi düzende okuyacağımızdan kodu anlamak ve geliştirme yapmak çok daha kolay olacaktı. Composition API’nin devreye girdiği yer işte tam olarak burasıdır.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v2fukOv1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ks5hmpddqexp0b54z9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v2fukOv1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ks5hmpddqexp0b54z9e.png" alt="Image description" width="880" height="1070"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yukarıdaki görselde Options API ile geliştirilen kodun Composition API ile geliştirilen kod ile kıyaslandığında ne kadar karmaşık kaldığını görebilirsiniz. Aşağıdaki kod örneğinde de solda Options API ile yazılan bir kodun Composition API ile nasıl yazılabileceğini görebilirsiniz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ozc_mtyg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ta1jyozo9mewq7y9kjdd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ozc_mtyg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ta1jyozo9mewq7y9kjdd.png" alt="Image description" width="880" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Özetle Composition API, Logic’lerin gruplanmasını ve kodun sırasıyla ele alınmasını sağlar. Bu sayade bir logic ile ilgili işlem yaparken sadece o logic ile ilgili kodları görürüz. Bunlarla beraber bir logic’i component’ten ayırmak veya yeni bir logic eklemek çok daha kolay olacaktır. Örneğin yukarıdaki kodda Composition API ile yazılmış olan user logic’i başka bir yere taşınmak istendiğinde, logic zaten gruplanmış olduğundan ilgili kodu component’ten çıkarmak çok daha kolay olacaktır.&lt;/p&gt;

&lt;h2&gt;
  
  
  Options API İle Birlikte Kendimizi Tekrar Eden İşlerden Uzak Durmak
&lt;/h2&gt;

&lt;p&gt;Tahmin edebileceğiniz üzere Composition API’nin avantajları bunlarla sınırlı değildir. Yazının başında değindiğimiz bir konu vardı. Yazılım geliştirmenin en önemli ilkelerinden biri kendimizi tekrar eden işlerden uzak durmaktır. Kullandığımız diller ve araçlar bizi kendimizi tekrar eden işlerden uzak durmamıza yardımcı olacak çözümler üretirler ve bu çözümler süreç boyunca gelişir ve değişir.&lt;/p&gt;

&lt;p&gt;Şimdi Composition API öncesinde yani Options API ile geliştirme yaparken kendimizi tekrar eden işlerden kaçmak için hangi çözümleri kullandığımıza ve bu çözümlerin neden yetersiz kaldığına örneklerle beraber bakalım.&lt;/p&gt;

&lt;p&gt;Örneğin bir Component’te kullandığımız bir fonksiyon veya kod bloğunu proje genelinde kullanmak istediğimizde bunu Options API ile nasıl yapıyorduk ve ne gibi sorunlarla karşılaşıyorduk bunlara bakalım. Sonrasında da Composition API ile bu sorunlar nasıl çözülmüş bunlara bakalım.&lt;/p&gt;

&lt;h2&gt;
  
  
  Utility Functions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OXtqEif6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmd79chycsgb5d7tg2j0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OXtqEif6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmd79chycsgb5d7tg2j0.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bu çözümlerden ilki Utility Function’lardır. Utility Function’lar özetle dışarıdan parametre alabilen ve sonucunda bir değeri return etmesini beklediğimiz, ufak kod bloklarını kapsüllememize olanak tanıyan bir yapıdır. Fakat kullanımları sınırlıdır çünkü vue’ye özgü özellikleri(Reaktif değişkenler, mounted, created vb) bu fonksiyonların içine tanımlayamıyor ve kullanamıyoruz.&lt;/p&gt;

&lt;p&gt;Yukarıdaki görseli incelediğimizde increment fonksiyonunun tanımlandığını fakat count reaktif değişkeninin fonksiyon içinde tanımlanamadığından component içinde tanımlandığını görebilirsiniz. Burada count değişkenini de kapsüllemek istediğimizde veya vue’ye özgü diğer özellikleri de kullanmak istediğimizde utility function’lar yetersiz kalmaktadırlar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Renderless Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jaNTocbX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njmps1drq1meapc1tabf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jaNTocbX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njmps1drq1meapc1tabf.png" alt="Image description" width="880" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Renderless Componenet’ler herhangi bir html render etmeyen ve vue’ye özgü özellikleri kullanabildiğimiz bir yöntemdir. Burada reaktif değişkenleri veya mounted, unmounted gibi Vue’ye özgü özellikleri kullanabiliriz.&lt;/p&gt;

&lt;p&gt;Yukarıdaki görselde yer alan örneğe baktığımızda mouse’un x ve y koordinatlarını bize anlık gösteren bir kodun renderless component ile yazıldığı örneği görüyoruz. Burada vue’ye özgü özellikleri kullanabildiğimizi görebiliriz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mixins
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-DWoYfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw91hgf6hfmgf67l21oq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-DWoYfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw91hgf6hfmgf67l21oq.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Karmaşık kod bloklarını kapsüllemek için kullanabileceğimiz bir diğer yöntem de mixin’lerdir. Özellikle Options API ile geliştirme yaparken component’ler arası kod paylaşmanın resmi bir yoluydu diyebiliriz. Mixin’ler sayesinde business logic’lerimizi kapsülleyip projemizde birden fazla yerde kullanabiliyoruz.&lt;/p&gt;

&lt;p&gt;Yukarıdaki görselde yer alan kod örneğine bakarak mixin’lerin kullanımı hakkında bilgi sahibi olabiliriz. Örneğe baktığımızda mixin’lerin içinde vue’ye özgü özellikleri kullanabildiğimizi görebiliriz.&lt;/p&gt;

&lt;p&gt;Mixin’ler çok güzel bir çözüm gibi dursalar da çok ciddi dezavantajları olabiliyor. Bu dezavantajlarından dolayı bugün mixin’lerin kullanımı önerilmemektedir. Şimdi beraber bu dezavantajlarına bakalım.&lt;/p&gt;

&lt;p&gt;Bu dezavantajlarından biri, bir component’te birden fazla mixin kullandığımızda hangi özelliğin hangi mixin’den geldiğini ilk bakışta anlayamıyoruz.&lt;/p&gt;

&lt;p&gt;Diğer bir dezavantaj ise farklı mixin’lerde aynı isme sahip reaktif değişkenlerin veya method’ların yer almasıdır. Aynı reaktif değişken veya method’lar barındıran mixin’leri aynı component’te kullandığımızda conflict’ler oluşacak ve kod hatalı çalışacaktır.&lt;/p&gt;

&lt;p&gt;Vue 3 ile birlikte mixin’ler kullanılabilirler fakat kullanılmaları önerilmemektedir. Vue özelliklerini barındıran bir kod bloğunu kapsüllemenin artık çok daha iyi bir yolu var. Şimdi hep beraber bunu inceleyelim.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composables
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9mCl4UQW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb7o8nuzi56t76ug3b9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9mCl4UQW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb7o8nuzi56t76ug3b9i.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composition API’nin en önemli özelliği composable’lardır. Composable’larla birlikte içinde reaktivite barındıran kod bloklarını yeniden kullanılabilir modüller haline getirebiliyoruz. Bu şekilde yazmış olduğumuz bir kodu birden fazla yerde rahatlıkla kullanabiliyoruz. Bununla beraber sadece global kod blokları oluşturmak için değil aynı zamanda bir component’te yer alan birden fazla logic’i ayırmamıza ve kodun daha okunaklı olmasına da yarıyor. Örneklerle beraber ilerleyerek composable’ları inceleyelim.&lt;/p&gt;

&lt;p&gt;Örneğin mouse’un anlık koordinat bilgilerini veren bir kod yazmak istediğimizi düşünelim. Bunu renderless component’ler ile nasıl yapabileceğimizi görmüştük, şimdi de bunu Composition API ile nasıl yapabileceğimizi aşağıdaki görsele bakarak anlayabiliriz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C_YdWRcZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikn1yo6wly51462f9w48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C_YdWRcZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikn1yo6wly51462f9w48.png" alt="Image description" width="880" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yukarıda Composition API ile geliştirilen kodu projede birden çok yerde kullanmak istediğimizi düşünelim. Burada kullanabileceğimiz yöntem composable’lardır. Yukarıdaki kodu composable function haline getirdiğimizde kodumuz aşağıdaki gibi olacaktır. Aşağıdaki örneğe baktığımızda kodumuzu direkt kopyala yapıştır yaparak composable function haline getirebildiğimizi görebiliriz. Composition API’nin en büyük avantajlarından biri de kodumuzu neredeyse hiç değişiklik yapmadan başka bir yere kolaylıkla taşıyabilmemizdir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ITjtukSn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vqxuqiozo83u1lmezvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ITjtukSn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vqxuqiozo83u1lmezvy.png" alt="Image description" width="880" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yukarıda yazmış olduğumuz useMouse composable function’ı herhangi bir component’te kullanmak oldukça basittir. Yapmamız gereken tek şey import etmek ve kullanmaya başlamaktır. Aşağıdaki görselde bir composable function’ın ne kadar kolay bir şekilde kullanılabildiğini görebilirsiniz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GyZ2U7Jn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ls5gtvawdsc4jcxpvs72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GyZ2U7Jn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ls5gtvawdsc4jcxpvs72.png" alt="Image description" width="880" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Composables vs Mixins
&lt;/h2&gt;

&lt;p&gt;Composable function’larla ilgili örneklere baktığımızda mixin’lerde yaşadığımız dezavantajların yaşanmadığını görebiliriz.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Örneğin birden fazla mixin kullandığımızda hangi özelliğin hangi mixin’den geldiğini ilk bakışta anlamak zor oluyordu fakat Composable’larda özellikle refs + destructure modelini kullandığımızda hangi özelliğin hangi composable’dan geldiğini rahatlıkla anlayabiliyoruz.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mixin’lerin diğer bi dezavantajı ise Namespace collisions(aynı isme sahip değişken veya method’ların vb olması) olayıdır. Composable’larda destructure ile yeniden adlandırmayla namespace collision’ların önüne geçebiliriz.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Diğer bir avantaj ise Composable’dan döndürülen değerler, tıpkı normal fonksiyonlar gibi bir diğerine bağımsız değişkenler olarak iletilebilir.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Composable’ları iç içe de kullanabiliriz. Bu şekilde küçük logic’leri birleştirerek daha büyük logic’ler oluşturabiliriz. Bu durum web uygulaması geliştirirken component’leri kullanmamıza benziyor. Bir web uygulaması geliştirirken küçük component’leri birleştirerek daha büyük component’ler oluşturuyoruz. Bu şekilde de büyük web uygulamalarını kendimizi tekrar etmeden geliştirebiliyoruz. Bunun aynısını logic’lerimiz için de yapabiliriz. Bu durum hem kendimizi tekrar eden işlerden uzak durmamıza hem de zamandan tasarruf etmemize olanak tanıyacaktır.&lt;/p&gt;

&lt;p&gt;Aşağıdaki örneğe baktığımızda composable’ları iç içe nasıl kullanabileceğimizi görebiliriz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lF-xtMn2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qbg65d2hnhoswkgutmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lF-xtMn2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qbg65d2hnhoswkgutmd.png" alt="Image description" width="880" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7XQbqyzf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seove523zk1tzmdli3jz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7XQbqyzf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seove523zk1tzmdli3jz.png" alt="Image description" width="880" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Örneğe baktığımızda event listener için ayrı bir composable oluşturduğumuzu ve bunu başka bir composable içinde kullanabildiğimizi görebiliriz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KnoNY9fX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9txf6v0ldpbwb5823k1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KnoNY9fX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9txf6v0ldpbwb5823k1b.png" alt="Image description" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composition API ile geliştirme yaparken kodlarımızı logic’lere göre ayırabildiğimizden bahsetmiştik. Örneğin bir composable function yazmak istediğimizi düşünelim. Yazacağımız bu function’ın da kendi içinde belli bi düzeni olması kodun okunurluğunu arttıracaktır. Üstteki örneğe baktığımızda kodda değişkenlerin bir blok halinde tanımlandığını ve fonksiyonların da ayrı bir blok halinde yazıldığını görebilirsiniz. Vue’ye özgü(computed, wathers vb.) özelliklerin de aynı şekilde ayrı bloklar halinde belli bir sıraya göre yazılması kodun okunurluğu arttıracaktır. Yukarıdaki görselde alt taraftaki kod örneğinde de olduğu gibi bu blokları yorum satırlarıyla ayırabiliriz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Daha İyi Ve Sürdürülebilir Composable’lar Yazmak
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6JyE3-tK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxp4fmtuaowqi5f1ncsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6JyE3-tK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxp4fmtuaowqi5f1ncsd.png" alt="Image description" width="880" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composition API ve Composable’larla ilgili kod örneklerine beraber baktık. Composable’ların kodumuzda yer alan logic’leri tekrar tekrar kullanabileceğimiz fonksiyonlara ayırmamıza izin verdiklerini gördük. Bunun da kodun yazılmasını ve okunmasını kolaylaştırdığından bahsettik.&lt;/p&gt;

&lt;p&gt;Şimdi de beraber composable’larımızı daha iyi nasıl yazabileceğimize bakalım. Bu konuyla ilgili hazırlık yaparken incelediğim birçok kaynak oldu fakat bu kaynaklar arasında özellikle Michael Thiessen’ın yazmış olduğu “Coding Better Composables” yazısı çok ilgimi çekti. Konuyu ele alış biçimi ve yalın örnekleriyle konuyu çok güzel özetlemiş. Yazı dizisini incelemenizi kesinlikle tavsiye ederim. Bahsettiğim yazıda bu konu çok iyi anlatıldığından oradaki örneklerle konuyu anlatmak istiyorum. Bu yazıda çok detaya girmeden ilerleyeceğimizden dolayı detaylı bilgi almak için ilgili yazıyı incelemenizi tekrardan tavsiye ediyorum.&lt;/p&gt;

&lt;p&gt;Konu hakkında bilgi verirken yine kod örnekleriyle ilerleyeceğiz. Bu sefer kod örnekleri için VueUse kütüphanesinden yararlanacağız. VueUse kütüphanesi, içinde hazır composable’lar olan ve open source olan bir kütüphanedir. Bu kütüphanede composable’lar nasıl yazılmış bunlara beraber bakacağız. Bu şekilde de kendi composable’larımızı yazarken nelere dikkat etmemiz gerektiğini de anlamış olacağız.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parametreleri Obje Olarak Geçmek
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pkIb6dk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mmgw8svpmue3xvjslb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pkIb6dk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mmgw8svpmue3xvjslb5.png" alt="Image description" width="880" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composable’ların çoğunda bir veya daha fazla parametre bulunabilir. Fonksiyonumuza fazla sayıda parametre geçmek yerine hepsini tek bir obje olarak geçebiliriz. Fonksiyon içinde de object destructure ile ilerleyerek devam edebiliriz. Bir veya iki parametre dışında kalan parametreleri obje olarak geçmek bizim için avantajlı olacaktır.&lt;/p&gt;

&lt;p&gt;Birincisi parametrelerin sırasını bilmemiz gerekmiyor. Parametleri obje olarak geçtiğimiz sürece sıralamanın bir önemi yoktur. Bu sayede olası hataların önüne geçebiliriz.&lt;/p&gt;

&lt;p&gt;İkincisi ise obje olarak geçtiğimiz parametlerin ne işe yaradığını property’lerin isimlendirmelerinden anlayabiliriz. Bu da kodumuzu daha okunur yapacaktır.&lt;/p&gt;

&lt;p&gt;Şimdi de bu konu ile ilgili bir örneğe beraber bakalım. VueUse kütüphanesinde olan useTitle composable’ında bu işlemin nasıl yapıldığını görebiliriz. useTitle composable’ı oldukça basittir. Sayfanın başlığını ayarlamamızı sağlar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1G2JAhIL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kecs8a1ihnwdh1pcma76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1G2JAhIL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kecs8a1ihnwdh1pcma76.png" alt="Image description" width="880" height="1109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Buradaki örneğe baktığımızda title parametresi dışında kalan diğer parametreler options nesnesi olarak alınmıştır. Bizde yazdığımız composable’larda bu şekilde ilerleyebiliriz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parametrelerin Esnek Olması (Reaktif Veya Primitive Türlerin Otomatik Ayarlanması)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VgKm8DS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sljhwad5t92e9h47wxrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VgKm8DS_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sljhwad5t92e9h47wxrg.png" alt="Image description" width="880" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composable’ların parametre alabileceğinden bahsetmiştik. Bu parametreler ilkel javascript türleri (string, number) olabileceği gibi reaktif değişkenler de olabilir. Bazı durumlarda parametrenin ne olursa olsun reaktif bir değişken olmasını veya ne olursa olsun ilkel bir tip olmasını isteyebiliriz. Burada parametre olarak özellikle reaktif bir değişken veya ilkel bir tür istemek yerine ikisini de kabul edip ardından bu parametreyi ihtiyacımız olan türe dönüştürebiliriz.&lt;/p&gt;

&lt;p&gt;Yukarıdaki örneğe baktığımızda bu işlemin “ref” ve “unref” ile çok kolay bir şekilde yapılabileceğini görebiliriz. Bu sayede girilen parametrenin türü ne olursa olsun onu istediğimiz türe(reaktif veya primitive) dönüştürüp devam edebiliriz. Bu şekilde olası hataların önüne rahatlıkla geçebiliriz.&lt;/p&gt;

&lt;p&gt;Şimdi de bu işlemin yine UseTitle örneğinden ilerleyerek nasıl yapılabileceğini görelim.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EUjjGcrI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9igjsjcq2zbuopsgtgrz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EUjjGcrI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9igjsjcq2zbuopsgtgrz.png" alt="Image description" width="880" height="1051"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yukarıdaki koda baktığımızda girilen parametre ne olursa olsun reaktif hale getirildiğini görebiliriz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dinamik Dönüş Değerleri
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pnTXX4j7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eno6ba7d3126yl2axk5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pnTXX4j7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eno6ba7d3126yl2axk5u.png" alt="Image description" width="880" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composable’lar tek bir değer döndürebileceği gibi içinde birden fazla değer barındıran bir obje de döndürebilir. Yukarıdaki örnekte her iki örneği de görebilirsiniz. useDark tek bir değer dönerken useMouse bir obje dönmektedir. Burada istersek yazacağımız composable’ın değerlerini dinamik yapabiliriz. Dışarıdan girilen parametreye göre tek bir değer veya obje döndürebiliriz. Bu işlemi basit bir kontrol ile çok kolay bir şekilde gerçekleştirebiliriz. Yukarıdaki örnekte “controls: true” girildiğinde obje dönmektedir aksi takdirde tek bir değer dönmektedir.&lt;/p&gt;

&lt;p&gt;Bu kalıp çoğu zaman kodumuzu basitlemştirmek için iyi bir yöntemdir. Şimdi de bu işlemin VueUse kütüphanesinde UseNow composable’ında nasıl yapıldığına bakalım.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lMlwCOQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnbr1i6mcsmpenax1a5f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lMlwCOQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnbr1i6mcsmpenax1a5f.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yukarıdaki örneğe baktığımızda bu işlemin basit bir if kontrolü ile yapıldığını görebiliriz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composable ile Kodun Düzenlenmesi
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jPNBNJF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2js15y1q05scfm90phd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jPNBNJF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2js15y1q05scfm90phd.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Composable’ları sadece global kod blokları oluşturmak için değil aynı zamanda kod organizasyonu için de kullanabiliriz. Örneğin bir component’te logic’ler arttıkça kodu okumak ve anlamak daha zor hale gelebilir. Bu tarz durumlar için her bir logic için ayrı bi composable oluşturup kodumuzu küçük parçalara ayırabiliriz. Ayrıca bir composable’dan aldığımız değişkeni başka bi composable’a parametre olarak geçebiliriz. Bu da kod organizasyonu için önemli bi avantaj sağlayacaktır.&lt;/p&gt;

&lt;h2&gt;
  
  
  Özet Ve Teşekkür
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a1QEjGN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1uc0on2i6wapj054o31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a1QEjGN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1uc0on2i6wapj054o31.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bu yazımda sizlere öncelikle Composition API öncesinde ne gibi zorluklar yaşadığımızdan örneklerle birlikte bahsettim. Bu örneklerle birlikte neden Composition API’ya ihtiyaç duyduğumuzu ve Composition API ile bu sorunların nasıl aşıldığını yine örneklerle beraber görmüş olduk. Sonrasında ise Michael Thiessen’ın yazmış olduğu “Coding Better Composables” yazısından örneklerle giderek Composable’larımızı daha iyi nasıl yazabileceğimizi yine örneklerle beraber inceledik.&lt;/p&gt;

&lt;p&gt;Dilerseniz bu yazının sunumunu aşağıdan izleyebilirsiniz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/bfIDcdHbIbI"&gt;https://youtu.be/bfIDcdHbIbI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Burada anlatılanların işinize yaraması dileğiyle :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Kaynaklar
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#what-is-a-composable"&gt;https://vuejs.org/guide/reusability/composables.html#what-is-a-composable&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/vue-mastery/coding-better-composables-1-5-47c6f17d1cd3"&gt;https://medium.com/vue-mastery/coding-better-composables-1-5-47c6f17d1cd3&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#mouse-tracker-example"&gt;https://vuejs.org/guide/reusability/composables.html#mouse-tracker-example&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#conventions-and-best-practices"&gt;https://vuejs.org/guide/reusability/composables.html#conventions-and-best-practices&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/vue-mastery/coding-better-composables-flexible-arguments-2-5-6eff5983bb1"&gt;https://medium.com/vue-mastery/coding-better-composables-flexible-arguments-2-5-6eff5983bb1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#extracting-composables-for-code-organization"&gt;https://vuejs.org/guide/reusability/composables.html#extracting-composables-for-code-organization&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/reusability/composables.html#comparisons-with-other-techniques"&gt;https://vuejs.org/guide/reusability/composables.html#comparisons-with-other-techniques&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/vue-mastery/coding-better-composables-dynamic-returns-3-5-3542702dd618"&gt;https://medium.com/vue-mastery/coding-better-composables-dynamic-returns-3-5-3542702dd618&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/components/slots.html#scoped-slots"&gt;https://vuejs.org/guide/components/slots.html#scoped-slots&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/the_one/are-you-using-composition-api-the-right-way-4jmm"&gt;https://dev.to/the_one/are-you-using-composition-api-the-right-way-4jmm&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.sitepoint.com/vue-composition-api-reusable-components/"&gt;https://www.sitepoint.com/vue-composition-api-reusable-components/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vuejs.org/guide/scaling-up/sfc.html"&gt;https://vuejs.org/guide/scaling-up/sfc.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>vue</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What’s New With Nuxt 3</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Sun, 05 Mar 2023 14:39:59 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/whats-new-with-nuxt-3-1fo8</link>
      <guid>https://dev.to/muhammederdinc/whats-new-with-nuxt-3-1fo8</guid>
      <description>&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%2Fcdn-images-1.medium.com%2Fmax%2F2400%2F1%2AL_BbTRbEGswsniTONwErAQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2400%2F1%2AL_BbTRbEGswsniTONwErAQ.png" alt="Nuxt 3 Release Candidate ([Click for image source](https://nuxtjs.org/_nuxt/image/9e31ab.png))"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt 3 beta was announced on October 12, 2021 after 16 months of work, introducing a new foundation based on Vue 3, Vite and Nitro. About 6 months after the beta version was announced, the first Release Candidate for Nuxt 3 called “Mount Hope” was announced.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Release Candidates are beta versions that have the potential to be released as stable. This means that no major breaking changes are expected until the stable release.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Vue 3 &amp;amp; TypeScript
&lt;/h2&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%2Fcdn-images-1.medium.com%2Fmax%2F2480%2F1%2A2PfUTxI-YJxYlrYKABCcXA.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%2Fcdn-images-1.medium.com%2Fmax%2F2480%2F1%2A2PfUTxI-YJxYlrYKABCcXA.png" alt="TypeScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt 3 is built to provide a great Vue 3 experience along with great SSR support.&lt;/p&gt;

&lt;p&gt;Nuxt allows you to experience TypeScript with zero configuration. It automatically creates a TS configuration (.nuxt/tsconfig.json) and a generic type file (.nuxt/nuxt.d.ts) for this.&lt;/p&gt;

&lt;p&gt;To learn more about TypeScript in Nuxt 3, you can read the &lt;a href="https://v3.nuxtjs.org/guide/concepts/typescript/" rel="noopener noreferrer"&gt;related document.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vite &amp;amp; Webpack
&lt;/h2&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU3wXjGuLVZ57thfZYsfxyw.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU3wXjGuLVZ57thfZYsfxyw.png" alt="ViteJS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With Nuxt 3, Vite became the default bundler. Vite is a wrapper that aims to provide a faster development experience for modern web projects. Nuxt 3 also supports packaging with the latest version of Webpack (version 5).&lt;/p&gt;

&lt;h2&gt;
  
  
  Nitro Server Engine
&lt;/h2&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%2Fcdn-images-1.medium.com%2Fmax%2F2568%2F1%2ACt0kPjXRxzcQGGgF6QjWHQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2568%2F1%2ACt0kPjXRxzcQGGgF6QjWHQ.png" alt="Nitro Server Engine"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most important features of Nuxt 3, the new server engine is &lt;a href="https://github.com/unjs/nitro" rel="noopener noreferrer"&gt;unjs/nitro&lt;/a&gt;. Nitro allows us to create API paths outside of pages in Nuxt. In this way, it provides the opportunity to develop full-stack. In addition, it provides the opportunity to distribute Nuxt application to any system that supports JavaScript (Node.js, Serverless, Workers, Edge-side rendering, etc.).&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%2Fcdn-images-1.medium.com%2Fmax%2F2004%2F1%2AT-FM0B3EH3VEv_g4P4TWGw.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%2Fcdn-images-1.medium.com%2Fmax%2F2004%2F1%2AT-FM0B3EH3VEv_g4P4TWGw.png" alt="Nitro — Server Engine (Image source: [https://nitro.unjs.io/](https://nitro.unjs.io/))"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nitro Engine also supports adding middleware to API endpoints. Nuxt reads all files in the /server/middleware directory to build middleware for your project and these files are executed on every request. This is usually used so that you can add a common header to all responses, log responses, or modify an incoming request object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=FeKleFJkKNY&amp;amp;ab_channel=DanVega" rel="noopener noreferrer"&gt;Click to watch a sample video&lt;/a&gt; about Nuxt server engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nuxt Bridge
&lt;/h2&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%2Fcdn-images-1.medium.com%2Fmax%2F2458%2F1%2At9wOHaT3iVpGkJupNQ2DtQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2458%2F1%2At9wOHaT3iVpGkJupNQ2DtQ.png" alt="Nuxt Bridge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt Bridge is a layer created to make the transition from Nuxt 2 to Nuxt 3 as easy as possible, allowing you to experience many of the new Nuxt 3 features. Using Nuxt Bridge you can make sure your project is ready for Nuxt 3. To experience Nuxt 3 features in existing Nuxt 2 projects, you need to install @nuxt/bridge-edge in your project. Installation steps and more information can be found &lt;a href="https://v3.nuxtjs.org/bridge/overview/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Nuxt Bridge, to make the upgrade as easy as possible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Backward compatibility for nuxt.config.js used with Nuxt 2,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 supports backward compatibility for modules and plugins.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the same time, new features that came with Nuxt 3 have been brought to Nuxt 2. In this way, the transition from Nuxt 2 to Nuxt 3 can be carried out gradually. Some of these features are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using Nitro server engine with Nuxt 2,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using Composition API (same as Nuxt 3) with Nuxt 2,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using new CLI and DevTools with Nuxt 2,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Progressively upgrade to Nuxt 3,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compatibility with Nuxt 2 module ecosystem,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Upgrade piece by piece (Nitro, Composition API, Nuxt Kit)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the image below you can see the comparisons between Nuxt 2, Nuxt Bridge and Nuxt 3 versions.&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5StVHeYooZgJ55A4JUjgJw.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5StVHeYooZgJ55A4JUjgJw.png" alt="A quick comparison between Nuxt 2, Nuxt Bridge and Nuxt 3 versions ([Click for image source](https://v3.nuxtjs.org/getting-started/migration/))"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Nuxi
&lt;/h2&gt;

&lt;p&gt;Nuxi (Nuxt CLI) helps you create new projects with zero effort. It’s also backwards compatible, so you can still enjoy some of its benefits even if you’re on Nuxt 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nuxt Kit
&lt;/h2&gt;

&lt;p&gt;Nuxt Kit aims to make developing Nuxt modules easier. It provides users with a new flexible module development experience with cross-version compatibility. In this way, it allows the development of modules that will work on both Nuxt 2 and Nuxt 3.&lt;/p&gt;

&lt;p&gt;In summary, we can say about Nuxt 3:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It supports &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;webpack 5&lt;/a&gt; and &lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;, which supports hot module replacement during development and assembles your code for production,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses &lt;a href="https://esbuild.github.io/" rel="noopener noreferrer"&gt;esbuild&lt;/a&gt; so you can write the latest JavaScript syntax while supporting older browsers,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses &lt;a href="https://github.com/nuxt/framework/tree/main/packages/nuxi" rel="noopener noreferrer"&gt;Nuxi&lt;/a&gt; for Command line interface,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses &lt;a href="https://github.com/unjs/nitro" rel="noopener noreferrer"&gt;Nitro&lt;/a&gt; as the server engine,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses &lt;a href="https://github.com/nuxt/framework/tree/main/packages/kit" rel="noopener noreferrer"&gt;Nuxt Kit&lt;/a&gt; as development kit,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses &lt;a href="https://github.com/nuxt/bridge" rel="noopener noreferrer"&gt;Nuxt Bridge&lt;/a&gt; to ease the migration from Nuxt 2.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nuxtjs.org/announcements/nuxt3-rc/" rel="noopener noreferrer"&gt;https://nuxtjs.org/announcements/nuxt3-rc/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/guide/concepts/introduction" rel="noopener noreferrer"&gt;https://v3.nuxtjs.org/guide/concepts/introduction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/framework/tree/main/packages/vite" rel="noopener noreferrer"&gt;https://github.com/nuxt/framework/tree/main/packages/vite&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/framework/tree/main/packages/webpack" rel="noopener noreferrer"&gt;https://github.com/nuxt/framework/tree/main/packages/webpack&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/framework/tree/main/packages/nuxi" rel="noopener noreferrer"&gt;https://github.com/nuxt/framework/tree/main/packages/nuxi&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/bridge" rel="noopener noreferrer"&gt;https://github.com/nuxt/bridge&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/guide/concepts/server-engine" rel="noopener noreferrer"&gt;https://v3.nuxtjs.org/guide/concepts/server-engine&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/bridge/overview" rel="noopener noreferrer"&gt;https://v3.nuxtjs.org/bridge/overview&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/getting-started/migration" rel="noopener noreferrer"&gt;https://v3.nuxtjs.org/getting-started/migration&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/community/roadmap" rel="noopener noreferrer"&gt;https://v3.nuxtjs.org/community/roadmap&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>vue</category>
      <category>nuxt</category>
      <category>vite</category>
    </item>
    <item>
      <title>Nuxt 3 İle Birlikte Gelen Yenilikler</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Sun, 05 Mar 2023 14:39:17 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/nuxt-3-ile-birlikte-gelen-yenilikler-i3h</link>
      <guid>https://dev.to/muhammederdinc/nuxt-3-ile-birlikte-gelen-yenilikler-i3h</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IPfDjvwL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2400/1%2AURSce5KQnqfTOBnoJlu40w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IPfDjvwL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2400/1%2AURSce5KQnqfTOBnoJlu40w.png" alt="Nuxt 3 Release Candidate (Görselin kaynağı için [tıklayınız](https://nuxtjs.org/_nuxt/image/9e31ab.png))" width="880" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt 3 Beta, Vue 3, Vite ve Nitro’ya dayalı yeni bir temel ile 16 aylık bir çalışmanın ardından 12 Ekim 2021'de duyuruldu. Beta sürümü duyurulduktan yaklaşık 6 ay sonra “Mount Hope” adlı Nuxt 3 için ilk Release Candidate (sürüm adayı) duyuruldu.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Release Candidate (Sürüm Adayı), kararlı olarak yayınlanma potansiyeline sahip beta sürümleridir. Bu, kararlı sürüme kadar büyük bir değişikliğin beklenmediği anlamına gelir.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Vue 3 &amp;amp; TypeScript
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YLV2uCON--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2480/1%2AmoJeTvW97yShLB7URRj5Kg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YLV2uCON--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2480/1%2AmoJeTvW97yShLB7URRj5Kg.png" alt="TypeScript" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt 3, birinci sınıf SSR desteği ile birlikte harika bir Vue 3 deneyimi sağlamak için inşa edilmiştir.&lt;/p&gt;

&lt;p&gt;Nuxt, sıfır yapılandırmayla TypeScript deneyimi elde etmenize olanak tanır. Bunun için otomatik olarak bir TS yapılandırması (.nuxt/tsconfig.json) ve bir genel tür dosyası (.nuxt/nuxt.d.ts) oluşturur.&lt;/p&gt;

&lt;p&gt;Nuxt 3'te TypeScript hakkında daha fazla bilgi almak için &lt;a href="https://v3.nuxtjs.org/guide/concepts/typescript/"&gt;ilgili dokümanı okuyabilirsiniz&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vite &amp;amp; Webpack
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LRhl_902--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A01TAngTe5DDiuOAws0d5fA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LRhl_902--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A01TAngTe5DDiuOAws0d5fA.png" alt="ViteJs" width="409" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt 3 ile birlikte Vite varsayılan bundler(paketleyici) oldu. Vite, modern web projeleri için daha hızlı ve daha yalın bir geliştirme deneyimi sağlamayı amaçlayan bir paketleyicidir. Nuxt 3, Webpack’in en son sürümü (version 5) ile paketlemeyi de desteklemektedir.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nitro Server Engine
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aUxsAfX---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2568/1%2AeL4bkKpgk3ul_ff_kgtzAQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aUxsAfX---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2568/1%2AeL4bkKpgk3ul_ff_kgtzAQ.png" alt="Nitro Server Engine" width="880" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt 3'ün en önemli özelliklerinden biri, yeni sunucu motoru &lt;a href="https://github.com/unjs/nitro"&gt;unjs/nitro&lt;/a&gt;’dur. Nitro, Nuxt uygulamalarında sayfalar ile birlikte API yolları da oluşturmamıza izin verir. Bu sayede full-stack geliştirme yapma imkanı sunar. Bunlarla birlikte Nuxt uygulamasını JavaScript’i destekleyen herhangi bir sisteme (Node.js, Serverless, Workers, Edge-side rendering vb.) dağıtım imkanı sağlar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WhHnjY7h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2004/1%2A8kobVQe3LXk4FhoS5OzewQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WhHnjY7h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2004/1%2A8kobVQe3LXk4FhoS5OzewQ.png" alt="Nitro — Server Engine (Görselin kaynağı: [https://nitro.unjs.io/](https://nitro.unjs.io/))" width="880" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nitro Engine, API uç noktalarına middleware (ara katman yazılımı) eklemeyi de destekler. Nuxt, projeniz için middleware oluşturmak için /server/middleware dizinindeki tüm dosyaları okur ve bu dosyalar her istekte yürütülür. Bu genellikle, tüm yanıtlara ortak bir başlık ekleyebilmeniz, yanıtları günlüğe kaydedebilmeniz veya gelen bir istek nesnesini değiştirebilmeniz için kullanılır.&lt;/p&gt;

&lt;p&gt;Nuxt server engine ile ilgili örnek bir video izlemek için &lt;a href="https://www.youtube.com/watch?v=FeKleFJkKNY"&gt;tıklayınız&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nuxt Bridge
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k2LmN8Wc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2458/1%2AaojAGr9CRINRELokFaCIuA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k2LmN8Wc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2458/1%2AaojAGr9CRINRELokFaCIuA.png" alt="Nuxt Bridge" width="880" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt Bridge, Nuxt 2'den Nuxt 3'e geçişi mümkün olduğunca kolaylaştırmak için oluşturulmuş ve yeni Nuxt 3 özelliklerinin çoğunu deneyimlemenizi sağlayan bir katmandır. Nuxt Bridge’i kullanarak, projenizin (neredeyse) Nuxt 3 için hazır olduğundan emin olabilirsiniz. Nuxt 3 özelliklerini mevcut Nuxt 2 projelerinde deneyimlemek için @nuxt/bridge-edge’i projenize kurmanız gerekmektedir. Kurulum aşamaları ve daha fazla bilgiye &lt;a href="https://v3.nuxtjs.org/bridge/overview"&gt;buradan ulaşabilirsiniz.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nuxt Bridge, yükseltmeyi olabildiğince kolaylaştırmak için:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 ile kullanılan nuxt.config.js için geriye dönük uyumluluğu,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 modülleri ve eklentileri için geriye dönük uyumluluğu desteklemektedir.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aynı zamanda Nuxt 3 ile birlikte gelen yeni özellikler Nuxt 2'ye de getirilmiştir. Bu sayede Nuxt 2'den Nuxt 3'e geçiş aşamalı olarak gerçekleştirilebilir. Bu özelliklerden bazıları şunlardır:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 ile Nitro server engine kullanabilme,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 ile birlikte Nuxt 3 Composition API kullanabilme,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 ile yeni CLI ve DevTools kullanabilme,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2 modül ekosistemi ile uyumluluk&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parça parça yükseltme imkanı (Nitro, Composition API, Nuxt Kit)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aşağıdaki görselde Nuxt 2, Nuxt Bridge ve Nuxt 3 versiyonları arasındaki karşılaştırmaları görebilirsiniz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PSB47c3o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AL4fG-1TRxti1gqht1WvwlA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PSB47c3o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AL4fG-1TRxti1gqht1WvwlA.png" alt="Nuxt 2, Nuxt Bridge ve Nuxt 3 versiyonları arasında hızlı bir karşılaştırma (Görselin kaynağı için [tıklayınız.](https://v3.nuxtjs.org/getting-started/migration))" width="759" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Nuxi
&lt;/h2&gt;

&lt;p&gt;Nuxi (Nuxt CLI), yeni projeleri sıfır çabayla oluşturmanıza yardımcı olur. Geriye dönük olarak da uyumludur, bu nedenle Nuxt 2'de olsanız bile bazı avantajlarından yararlanabilirsiniz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nuxt Kit
&lt;/h2&gt;

&lt;p&gt;Nuxt Kit, Nuxt modüllerini geliştirmeyi daha kolay hale getirmeyi amaçlar. Kullanıcılara sürümler arası uyumluluk ile yeni bir esnek modül geliştirme deneyimi sağlar. Böylelikle hem Nuxt 2 hem de Nuxt 3 üzerinde çalışacak modüllerin geliştirilmesine olanak tanır.&lt;/p&gt;

&lt;p&gt;Özetle Nuxt 3 ile ilgili şunları söyleyebiliriz:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Geliştirme aşamasında hot module replacement’ı destekleyen ve kodunuzu üretim için bir araya getiren bir paketleyici olarak hem &lt;a href="https://webpack.js.org/"&gt;webpack 5&lt;/a&gt;'i hem de &lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt;’yi destekler.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eski tarayıcıları desteklerken en son JavaScript sözdizimini yazabilmeniz için &lt;a href="https://esbuild.github.io/"&gt;esbuild&lt;/a&gt; kullanır.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command line interface (Komut satırı arayüzü) olarak &lt;a href="https://github.com/nuxt/framework/tree/main/packages/nuxi"&gt;Nuxi&lt;/a&gt; kullanır.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server engine olarak &lt;a href="https://github.com/unjs/nitro"&gt;Nitro&lt;/a&gt; kullanır.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Development kit olarak &lt;a href="https://github.com/nuxt/framework/tree/main/packages/kit"&gt;Nuxt Kit&lt;/a&gt; kullanır.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nuxt 2'den geçişi kolaylaştırmak için &lt;a href="https://github.com/nuxt/bridge"&gt;Nuxt Bridge&lt;/a&gt; kullanır.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nuxt, eklenen yeni özellikler ve modüller ile birlikte sürekli gelişmektedir. Planlanan sürümleri ve mevcut durumu takip etmek için &lt;a href="https://v3.nuxtjs.org/community/roadmap"&gt;Roadmap&lt;/a&gt; sayfasını ziyaret edebilirsiniz. Ayrıca Nuxt 3'e hızlı bir başlangıç yapmak isterseniz &lt;a href="https://v3.nuxtjs.org/getting-started/quick-start/"&gt;Quick Start&lt;/a&gt; sayfasını inceleyebilirsiniz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Kaynaklar
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nuxtjs.org/announcements/nuxt3-rc/"&gt;https://nuxtjs.org/announcements/nuxt3-rc/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/guide/concepts/introduction"&gt;https://v3.nuxtjs.org/guide/concepts/introduction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/framework/tree/main/packages/vite"&gt;https://github.com/nuxt/framework/tree/main/packages/vite&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/framework/tree/main/packages/webpack"&gt;https://github.com/nuxt/framework/tree/main/packages/webpack&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/framework/tree/main/packages/nuxi"&gt;https://github.com/nuxt/framework/tree/main/packages/nuxi&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/nuxt/bridge"&gt;https://github.com/nuxt/bridge&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/guide/concepts/server-engine"&gt;https://v3.nuxtjs.org/guide/concepts/server-engine&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/bridge/overview"&gt;https://v3.nuxtjs.org/bridge/overview&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/getting-started/migration"&gt;https://v3.nuxtjs.org/getting-started/migration&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://v3.nuxtjs.org/community/roadmap"&gt;https://v3.nuxtjs.org/community/roadmap&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>vue</category>
      <category>nuxt</category>
      <category>vite</category>
    </item>
    <item>
      <title>What is the DOM &amp; How Does HTML Rendering Happen in Browsers?</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Sun, 05 Mar 2023 14:34:53 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/what-is-the-dom-how-does-html-rendering-happen-in-browsers-1ehm</link>
      <guid>https://dev.to/muhammederdinc/what-is-the-dom-how-does-html-rendering-happen-in-browsers-1ehm</guid>
      <description>&lt;p&gt;DOM is a W3C (World Wide Web Consortium) standard. It is a platform and language independent interface standard that allows programs and scripts to dynamically access and update the content, structure, and style of a document.&lt;/p&gt;

&lt;p&gt;When a web page loads, the browser builds the page’s DOM tree. In this way, we can change all HTML properties on the page, remove existing HTML elements and attributes, add new HTML elements and attributes, or change all CSS styles on the page with scripting languages ​​such as JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2HvSYC3Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AW91R-0YkyCNOVfQChFqZVg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2HvSYC3Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AW91R-0YkyCNOVfQChFqZVg.gif" alt="Example HTML DOM Tree (Image source: [https://www.w3schools.com/js/pic_htmltree.gif](https://www.w3schools.com/js/pic_htmltree.gif))" width="486" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the DOM Tree?
&lt;/h3&gt;

&lt;p&gt;A DOM tree is a type of tree whose nodes represent the content of the HTML and XML document. Every HTML or XML document has a unique DOM tree representation. For example, let’s examine the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;My document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;Header&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;Paragraph&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The DOM tree of the above code block is as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R-XvTove--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2736/1%2AiiNCB2zkF5a6mFMZZR5hgQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R-XvTove--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2736/1%2AiiNCB2zkF5a6mFMZZR5hgQ.png" alt="Example HTML DOM Tree 2" width="880" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How the Browser Renders HTML?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A web browser is a piece of software that downloads files from a remote server and displays them to you, allowing user interaction. The process of compiling the files downloaded from a remote server and showing them to the user is done by browser engines. If you are interested, you can examine &lt;a href="https://en.wikipedia.org/wiki/Comparison_of_browser_engines"&gt;different browser engines and comparisons&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Data is sent over the Internet as byte packets. The browser must convert these data bytes into a form it understands. Firstly, bytes are converted to HTML characters and then to Tokens. In the next step, Tokens are converted into nodes. Nodes are different objects with certain properties. After the nodes are created, the DOM tree is created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TaPyjB4S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2246/1%2AEU3XjJvJ8kg2kHUTWdMQVw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TaPyjB4S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2246/1%2AEU3XjJvJ8kg2kHUTWdMQVw.png" alt="Stages of creating the DOM tree (Image source: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/cSL20piziX7XLekCPCuD.png?auto=format&amp;amp;w=845))" width="880" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While creating the DOM tree, the “document” node is created first. Document is a node that represents the entire HTML document. The node that specifies an HTML tag is called “elements”. We can learn the type of any node in the DOM tree with “nodeType”. The NodeType property returns a number. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType"&gt;You can review the relevant document&lt;/a&gt; to find out which node type this number represents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vQzlj2im--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AqYNaclbzFAMrVVfIrZf1Zw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vQzlj2im--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AqYNaclbzFAMrVVfIrZf1Zw.png" alt="Type of document node" width="413" height="65"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The DOM tree has been successfully created, but the browser needs information on how the elements will appear in order to render the page. It is the CSSOM’s responsibility to know how the elements of a page should appear.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is the CSSOM?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While creating the DOM tree, a request is sent to the CSS link in the &lt;/p&gt; and the CSS styles are returned as a result of this request. As with HTML tags, CSS information comes in bytes, and the CSS Object Model (CSSOM) is created by going through certain stages.

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d1uDiN9x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2024/1%2AiYZO0f9IZa-o6oHigz3Y4A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d1uDiN9x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2024/1%2AiYZO0f9IZa-o6oHigz3Y4A.png" alt="Stages of CSSOM tree structure (Image source: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/yb5YfU0vx6vHvB7c0fyD.png?auto=format&amp;amp;w=845))" width="880" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS bytes are converted to characters, then tokens and nodes; Finally, a tree structure known as the &lt;strong&gt;CSS Object Model&lt;/strong&gt; or CSSOM for short, is created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x4cisp0z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AHxOuFyj7vIkdb3ZvzR6MVA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x4cisp0z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AHxOuFyj7vIkdb3ZvzR6MVA.png" alt="CSSOM tree example (Image source: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/keK3wDv9k2KzJA9QubFx.png?auto=format&amp;amp;w=650))" width="582" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Render Tree?
&lt;/h3&gt;

&lt;p&gt;DOM and CSSOM tree structures are two independent structures. The DOM contains all the information about the relationships of the HTML element of the page, while the CSSOM contains the information about how to style the elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a2GM3nka--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2300/1%2AFXGPMAFT3lXjMupFQOY4jg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a2GM3nka--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2300/1%2AFXGPMAFT3lXjMupFQOY4jg.png" alt="DOM + CSSOM = Render Tree (Image source: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/b6Z2Gu6UD1x1imOu1tJV.png?auto=format&amp;amp;w=845))" width="880" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Render Tree contains information about all visible DOM content on the page and all necessary CSSOM information for the different nodes. If an element is hidden by CSS (for example, &lt;em&gt;display: none&lt;/em&gt;), it means that the node will not be represented in the Render Tree.&lt;/p&gt;

&lt;p&gt;The hidden element (for example, &lt;em&gt;display: none&lt;/em&gt;) is present in the DOM, but not in the Render Tree. This is because the Render Tree combines information from both the DOM and the CSSOM.&lt;/p&gt;

&lt;p&gt;When the browser renders a Render Tree, it first renders each visible node, starting from the root of the DOM tree (Tags such as script, meta are not included in the Render Tree, and the nodes hidden by CSS are not included in the Render Tree).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;visibility: hidden&lt;/strong&gt; and **display: none **are different. The first makes the item invisible, but the item is contained in the Render Tree (as an empty node), whereas the second (display: none) removes the item from the Render Tree.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Layout and Paint Steps
&lt;/h3&gt;

&lt;p&gt;We have all the content and style information that will be displayed on the screen with the Render Tree, but the image has not yet appeared on the screen. Firstly, the browser has to calculate the exact size and position of each object on the page.&lt;/p&gt;

&lt;p&gt;To determine the exact size and position of each object, the browser starts at the root of the Render Tree and calculates each object on the page. As a result of this calculation, the exact location and size of each element is determined. In the next step, the browser paints the nodes one by one on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8F5Dellk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AvN2xwQDfRAXJaXH-OlAFWg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8F5Dellk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AvN2xwQDfRAXJaXH-OlAFWg.png" alt="Sample HTML Output (Image source: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/H9mc9hE33imsdh7TfCgm.png?auto=format&amp;amp;w=741))" width="741" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources Blocking Rendering
&lt;/h3&gt;

&lt;p&gt;DOM and CSSOM must be created before painting. Getting the HTML and CSS to the client as soon as possible is important for optimizing the time to first rendering of web applications.&lt;/p&gt;

&lt;p&gt;Even a simple web page is likely to have used JS. When the browser encounters a script tag while reading scripts, the DOM rendering process is paused and stopped until the script file has finished executing. This is because JavaScript can modify both the DOM and the CSSOM. Because the browser isn’t sure what the JavaScript will do, it takes precautions by completely stopping the entire DOM structure.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width,initial-scale=1"&amp;gt;
    &amp;lt;title&amp;gt;Örnek&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    **&amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;**
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  .....
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code example, when the browser comes to the script tag, the DOM rendering process will be stopped until the script file is finished executing. As a different scenario, if the app.js file was being pulled from a server rather than locally, and it was taking seconds to fetch app.js due to network connection, the DOM construction process would also be stopped for the same time.&lt;/p&gt;

&lt;p&gt;Let’s continue with a different scenario, for example, when the browser encounters a script tag, if the CSSOM is not ready yet, the JS execution will wait until the CSSOM is ready.&lt;/p&gt;

&lt;p&gt;By default the DOM construction process will be stopped whenever the browser encounters a script tag. If you add the “async” keyword to your script tag, the DOM rendering will not be stopped and will be executed when the script file is downloaded and ready.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br&gt;
&amp;lt;html&amp;gt;

&lt;p&gt;&amp;lt;head&amp;gt;&lt;br&gt;
 &amp;lt;meta name=”viewport” content=”width=device-width,initial-scale=1"&amp;gt;&lt;br&gt;
 &amp;lt;title&amp;gt;Örnek&amp;lt;/title&amp;gt;&lt;br&gt;
 &amp;lt;link rel=”stylesheet” href=”style.css”&amp;gt;&lt;br&gt;
 &lt;strong&gt;&amp;lt;script src=”&lt;a href="https://random-app.js"&gt;https://random-app.js&lt;/a&gt;" async&amp;gt;&amp;lt;/script&amp;gt;&lt;/strong&gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
 ....&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  References:&lt;br&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.w3schools.com/js/js_htmldom.asp"&gt;https://www.w3schools.com/js/js_htmldom.asp&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Comparison_of_browser_engines"&gt;https://en.wikipedia.org/wiki/Comparison_of_browser_engines&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Web_browser"&gt;https://en.wikipedia.org/wiki/Web_browser&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model"&gt;https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Performance/How_browsers_work"&gt;https://developer.mozilla.org/en-US/docs/Web/Performance/How_browsers_work&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://starkie.dev/blog/how-a-browser-renders-a-web-page"&gt;https://starkie.dev/blog/how-a-browser-renders-a-web-page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>dom</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>DOM Nedir &amp; Tarayıcılarda HTML Render İşlemi Nasıl Gerçekleşir?</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Sun, 05 Mar 2023 14:33:30 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/dom-nedir-tarayicilarda-html-render-islemi-nasil-gerceklesir-54a1</link>
      <guid>https://dev.to/muhammederdinc/dom-nedir-tarayicilarda-html-render-islemi-nasil-gerceklesir-54a1</guid>
      <description>&lt;p&gt;DOM, bir W3C (World Wide Web Consortium) standardıdır. Programların ve komut dosyalarının bir belgenin içeriğine, yapısına ve stiline dinamik olarak erişmesine ve bunları güncellemesine olanak tanıyan, platform ve dilden bağımsız bir arabirimdir.&lt;/p&gt;

&lt;p&gt;Bir web sayfası yüklendiğinde, tarayıcı sayfanın DOM ağacını oluşturur. Bu sayede JavaScript gibi betik diller ile sayfadaki tüm HTML özelliklerini değiştirebilir, mevcut HTML öğelerini ve nitelikliklerini kaldırabilir, yeni HTML öğeleri ve niteliklerini ekleyebilir veya sayfadaki tüm CSS stillerini değiştirebiliriz.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vd_vWz6P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ALA6AXbzvC0IQ_d2H8v3NCw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vd_vWz6P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ALA6AXbzvC0IQ_d2H8v3NCw.gif" alt="Örnek HTML DOM Ağacı (Görselin kaynağı: [https://www.w3schools.com/js/pic_htmltree.gif](https://www.w3schools.com/js/pic_htmltree.gif))" width="486" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DOM Ağacı Nedir?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DOM ağacı, düğümleri HTML veya XML belgesinin içeriğini temsil eden bir ağaç türüdür. Her HTML veya XML belgesinin benzersiz bir DOM ağacı temsili vardır. Örneğin aşağıdaki kodu inceleyelim:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;My document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;Header&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;Paragraph&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Yukarıdaki kod bloğunun DOM ağacı aşağıdaki gibidir:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ODdZQ1XF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2736/1%2AslkAIrjaKqzAMkj1QLocrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ODdZQ1XF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2736/1%2AslkAIrjaKqzAMkj1QLocrw.png" alt="Örnek HTML DOM Ağacı 2" width="880" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tarayıcılar HTML’yi Nasıl Render Eder?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Bir web tarayıcısı, uzaktaki bir sunucudan dosyaları yükleyen ve bunları size görüntüleyerek kullanıcı etkileşimine izin veren bir yazılım parçasıdır. Uzaktaki bir sunucudan yüklenen dosyaların derlenmesi ve kullanıcıya gösterilmesi işlemi tarayıcı motorları ile yapılır. Eğer ilginizi çekiyorsa farklı tarayıcı motorlarını ve karşılaştırmalarını &lt;a href="https://en.wikipedia.org/wiki/Comparison_of_browser_engines"&gt;inceleyebilirsiniz&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;İnternet üzerinden veriler byte paketleri olarak gönderilir. Tarayıcı ise bu veri byte’larını anladığı bir forma dönüştürmelidir. İlk olarak byte’lar HTML karakterlerine daha sonra ise Token’lara dönüştürülür. Sonraki adımda ise Token’lar düğümlere dönüştürülür. Düğümler belirli özelliklere sahip farklı nesnelerdir. Düğümler oluşturulduktan sonra DOM ağacı oluşturulur.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ir3Vztew--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2246/1%2ArW68P6kQ9mN-8yORGeWeGQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir3Vztew--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2246/1%2ArW68P6kQ9mN-8yORGeWeGQ.png" alt="DOM ağacının oluşturulma aşamaları (Görselin kaynağı: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/cSL20piziX7XLekCPCuD.png?auto=format&amp;amp;w=845))" width="880" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DOM ağacı oluşturulurken ilk önce “document” düğümü oluşturulur. Document tüm HTML belgesini temsil eden bir düğümdür. Bir HTML etiketini belirten düğüme ise “elements” denir. DOM ağacındaki herhangi bir düğümün türünü “nodeType” ile öğrenebiliriz. NodeType özelliği bir sayı döndürür. Bu sayının hangi düğüm tipini temsil ettiğini bulmak için ilgili dokümanı &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType"&gt;inceleyebilirsiniz&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vF87T8w9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AlM5e1_uQiIpIx1ZTNCCgEQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vF87T8w9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AlM5e1_uQiIpIx1ZTNCCgEQ.png" alt="document düğümünün türü" width="413" height="65"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DOM ağacı başarıyla oluşturuldu ancak tarayıcının sayfayı oluşturabilmesi için öğelerin nasıl görüneceğine dair bilgilere ihtiyacı vardır. Bir sayfanın öğelerinin nasıl görünmesi gerektiği bilgisi CSSOM sorumluluğundadır.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSSOM Nedir?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DOM ağacı oluşturulurken &lt;/p&gt; içinde yer alan CSS bağlantısına bir istek gönderilir ve bu isteğin sonucunda CSS stilleri döner. HTML etiketlerinde olduğu gibi CSS bilgileri de byte’larla gelir ve belli aşamalardan geçerek CSS Nesne Modeli(CSSOM) oluşturulur.

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_sdzuYRp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2024/1%2AN_atF-_2tffVlVhipNeeXw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_sdzuYRp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2024/1%2AN_atF-_2tffVlVhipNeeXw.png" alt="CSSOM ağaç yapısının oluşturulma aşamaları (Görselin kaynağı: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/yb5YfU0vx6vHvB7c0fyD.png?auto=format&amp;amp;w=845))" width="880" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS byte’ları karakterlere, daha sonra token’lara ve düğümlere dönüştürülür; son olarak da CSS Nesne Modeli veya kısaca CSSOM olarak bilinen bir ağaç yapısı oluşturulur.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bHSAMgX---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ANBVI2PTPj7TXB6bOm4Yn6A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bHSAMgX---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ANBVI2PTPj7TXB6bOm4Yn6A.png" alt="CSSOM ağaç örneği (Görselin kaynağı: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/keK3wDv9k2KzJA9QubFx.png?auto=format&amp;amp;w=650))" width="582" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Render Tree Nedir?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DOM ve CSSOM ağaç yapıları iki bağımsız yapılardır. DOM, sayfanın HTML öğesinin ilişkileri hakkındaki tüm bilgileri içerirken, CSSOM, öğelerin nasıl şekillendirileceğine ilişkin bilgileri içerir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BAaDF-a1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2300/1%2ADDiTAbp5TzyntJFXLXOXHQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BAaDF-a1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2300/1%2ADDiTAbp5TzyntJFXLXOXHQ.png" alt="DOM + CSSOM = Render Tree (Görselin kaynağı: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/b6Z2Gu6UD1x1imOu1tJV.png?auto=format&amp;amp;w=845))" width="880" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Render Tree, sayfadaki tüm görünür DOM içeriğiyle ilgili bilgileri ve farklı düğümler için gerekli tüm CSSOM bilgilerini içerir. Bir öğe CSS tarafından gizlenmişse (örneğin, display: none), düğümün Render Tree’de temsil edilmeyeceği anlamına gelir.&lt;/p&gt;

&lt;p&gt;Gizli öğe(örneğin, display: none), DOM’de bulunur, ancak Render Tree içinde bulunmaz. Bunun nedeni, Render Tree’nin hem DOM’den hem de CSSOM’den gelen bilgileri birleştirmesidir.&lt;/p&gt;

&lt;p&gt;Tarayıcı Render Tree oluştururken öncelikle DOM ağacının kökünden başlayarak görünür her bir düğümü işler. (script, meta gibi etiketler Render Tree içinde yer almazlar ayrıca CSS ile gizlenen düğümler de Render Tree içinde yer almazlar)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;visibility: hidden&lt;/strong&gt; ile &lt;strong&gt;display: none&lt;/strong&gt; birbirinden farklıdır. İlki öğeyi görünmez yapar ancak öğe Render Tree içinde yer alır (boş bir düğüm olarak), buna karşılık ikincisi (display: none) öğeyi Render Tree’den çıkarır.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Layout ve Paint Adımları&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Render Tree ile birlikte ekranda gösterilecek olan tüm içeriğe ve stil bilgilerine sahibiz ancak ekranda henüz bir görüntü oluşmadı. İlk olarak, tarayıcının sayfadaki her nesnenin tam boyutunu ve konumunu hesaplaması gerekir.&lt;/p&gt;

&lt;p&gt;Her bir nesnenin kesin boyutunu ve konumunu belirlemek için tarayıcı, Render Tree’nin kökünden başlar ve sayfadaki her bir nesnenin hesaplamasını yapar. Bu hesaplama sonucunda her bir öğenin kesin konumu ve boyutu belirlenmiş olur. Bundan sonraki aşamada ise tarayıcı düğümleri tek tek ekrana boyar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k6HLcjZ4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ANrvw6_Qy_YQK5u5LNOW1qg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6HLcjZ4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ANrvw6_Qy_YQK5u5LNOW1qg.png" alt="Örnek HTML Çıktısı (Görselin kaynağı: [web-dev](https://web-dev.imgix.net/image/C47gYyWYVMMhDmtYSLOWazuyePF2/H9mc9hE33imsdh7TfCgm.png?auto=format&amp;amp;w=741))" width="741" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Render İşlemini Engelleyen Kaynaklar&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DOM ve CSSOM, boyama(paint) işleminden önce oluşturulmalıdırlar. HTML ve CSS’lerin mümkün olan en kısa sürede istemciye ulaşması, web uygulamalarının ilk render olma süresine kadar geçen süreyi optimize etmek için önemlidir.&lt;/p&gt;

&lt;p&gt;Basit bir web sayfasında bile JS kullanılmış olma ihtimali yüksektir. Tarayıcı komut dosyalarını okurken bir script etiketiyle karşılaştığında DOM oluşturma süreci duraklatılır ve script dosyasının yürütülmesi bitene kadar durdurulur. Bunun nedeni, JavaScript’in hem DOM’yi hem de CSSOM’yi değiştirebilmesidir. Tarayıcı, JavaScript’in ne yapacağından emin olmadığı için, tüm DOM yapısını tamamen durdurarak önlem alır.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width,initial-scale=1"&amp;gt;
    &amp;lt;title&amp;gt;Örnek&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    **&amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;**
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  .....
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Yukarıdaki kod örneğinde tarayıcı script etiketine geldiğinde script dosyasının yürütülmesi bitene kadar DOM oluşturma süreci durdurulacaktır. Farklı bir senaryo olarak app.js dosyası local’de değil de bir sunucudan çekiliyor olsaydı ve ağ bağlantısından dolayı app.js’yi getirmek saniyeler sürüyor olsaydı, DOM yapım işlemi de saniyelerce durdurulacaktı.&lt;/p&gt;

&lt;p&gt;Yine farklı bir senaryo ile devam edelim, örneğin tarayıcı bir script etiketiyle karşılaştığında CSSOM henüz hazır değilse, JS yürütme işlemi CSSOM hazır olana kadar bekletilecektir.&lt;/p&gt;

&lt;p&gt;Varsayılan olarak tarayıcı her script etiketiyle karşılaştığında DOM yapım süreci durdurulacaktır. Eğer script etiketinize “async” anahtar sözcüğünü eklerseniz DOM yapımı durdurulmayacak ve script dosyası indirilip hazır olduğunda çalıştırılacaktır.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width,initial-scale=1"&amp;gt;
    &amp;lt;title&amp;gt;Örnek&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    **&amp;lt;script src="https://random-app.js" async&amp;gt;&amp;lt;/script&amp;gt;**
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  .....
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kaynaklar&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.w3schools.com/js/js_htmldom.asp"&gt;https://www.w3schools.com/js/js_htmldom.asp&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Comparison_of_browser_engines"&gt;https://en.wikipedia.org/wiki/Comparison_of_browser_engines&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Web_browser"&gt;https://en.wikipedia.org/wiki/Web_browser&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model"&gt;https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Performance/How_browsers_work"&gt;https://developer.mozilla.org/en-US/docs/Web/Performance/How_browsers_work&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://starkie.dev/blog/how-a-browser-renders-a-web-page"&gt;https://starkie.dev/blog/how-a-browser-renders-a-web-page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>dom</category>
      <category>html</category>
    </item>
    <item>
      <title>What Is The Open Graph Protocol?</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 01 Mar 2023 22:25:20 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/what-is-the-open-graph-protocol-28l9</link>
      <guid>https://dev.to/muhammederdinc/what-is-the-open-graph-protocol-28l9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2Fsb95pg336cw6yx6x3jxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsb95pg336cw6yx6x3jxl.png" width="377" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://ogp.me/" rel="noopener noreferrer"&gt;Open Graph Protocol&lt;/a&gt; is a protocol created by Facebook for standardizing &lt;a href="https://en.wikipedia.org/wiki/Search_engine_optimization" rel="noopener noreferrer"&gt;SEO&lt;/a&gt; metadata on Web pages that controls how URLs are displayed when shared on social media. Standardizing metadata has eliminated cross-site metadata mismatch. Today, the Open Graph protocol is also used by other social media sites such as LinkedIn and Twitter, apart from Facebook. Open Graph tags are located in the head section of a Web page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe3f7h8po4u78tu2dmz7j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe3f7h8po4u78tu2dmz7j.png" alt="The title and image in the preview of this URL shared on LinkedIn comes from the Open Graph tags." width="556" height="715"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Social media is very important for your content to reach more people. Users are more likely to see and click on content shared with optimized Open Graph tags. This means more social media traffic for your website. Here are the benefits of previews created with Open Graph tags:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;They make the content more eye-catching on social media streams.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A preview of what the content is about.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They help Facebook understand what the content is about, which will help you increase your brand visibility through search.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fmbf2e3u8m2gftdokw9id.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fmbf2e3u8m2gftdokw9id.png" alt="The image, title and description information in the preview of this URL shared on Twitter comes from the Open Graph tags." width="602" height="609"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we look at the &lt;/p&gt; section of the &lt;a href="https://github.blog/changelog/2022-02-23-the-new-github-issues-february-23rd-update/" rel="noopener noreferrer"&gt;site&lt;/a&gt; shared on Twitter and LinkedIn, we can see the Open Graph meta tags.

&lt;p&gt;&lt;a href="https://media2.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%2Fqbnxqzlohh3oiokbcf62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqbnxqzlohh3oiokbcf62.png" alt="The site’s meta tags in the sample posts above" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The four basic Open Graph tags required for each page are; og:title, og:type, og:image and og:url. Let’s take a quick look at some meta tags and their descriptions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;“og:title”&lt;/strong&gt;: It will represent the title of your page. It is often the same as the &lt;/p&gt; tag of the web page.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:type”&lt;/strong&gt;: It represents the type of website. In the example above, this is indicated as “article”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:image”&lt;/strong&gt;: The URL of the image representing your page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:url”&lt;/strong&gt;: It refers to the current URL of your page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:description”&lt;/strong&gt;: It refers to a brief description of your content. Usually the same as &amp;lt;meta type=”description”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:audio”&lt;/strong&gt;: The URL of the audio file that represents your content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:video”&lt;/strong&gt;: The video URL that represents your content.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fc0q4dq25x95cq2sa209h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fc0q4dq25x95cq2sa209h.png" alt="Anatomy of twitter card created with open graph tags" width="800" height="622"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Meta Tags for Images
&lt;/h3&gt;

&lt;p&gt;Some meta tags may have additional meta tags attached to them. For example, let’s go over the og:image tag. Usually it will be enough to proceed with the og:image tag, but in some cases the preview of your content may not look the way you want. You may need additional meta tags for this. For example, you may want to adjust the height and width of your image. Below you can see some meta tags and descriptions for og:image.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“og:image:url”&lt;/strong&gt;: Same as og:image. Indicates the URL of the image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“og:image:secure_url”&lt;/strong&gt;: An alternate url to use if the webpage requires &lt;a href="https://en.wikipedia.org/wiki/HTTPS" rel="noopener noreferrer"&gt;HTTPS&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“og:image:type”&lt;/strong&gt;: Indicates the &lt;a href="https://en.wikipedia.org/wiki/Media_type" rel="noopener noreferrer"&gt;media type&lt;/a&gt; information for the image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:image:width”&lt;/strong&gt;: Expresses the width of the image in pixels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:image:height”&lt;/strong&gt;: Expresses the height of the image in pixels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og: image:alt”&lt;/strong&gt;: A description of what is in the image (not a caption). If the page specifies an og:image it should specify og:image:alt.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A-dGr_wIzgPbc_h3MFytaKg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A-dGr_wIzgPbc_h3MFytaKg.png" alt="Use of og:image meta tags (Source link: [ogp](https://ogp.me/#structured))" width="800" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing Open Graph Tags
&lt;/h3&gt;

&lt;p&gt;After adding your Open Graph meta tags, you can test how your content appears on social media sites. This will make debugging your meta tags much easier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fslnr3yba4l5djq06y3z1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fslnr3yba4l5djq06y3z1.png" alt="Twitter Card Validator" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below are the test links for Facebook and Twitter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Facebook: &lt;a href="https://developers.facebook.com/tools/debug/" rel="noopener noreferrer"&gt;https://developers.facebook.com/tools/debug/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Twitter: &lt;a href="https://cards-dev.twitter.com/validator" rel="noopener noreferrer"&gt;https://cards-dev.twitter.com/validator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://ogp.me/" rel="noopener noreferrer"&gt;https://ogp.me/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Social_graph" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Social_graph&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Facebook_Platform#Open_Graph_protocol" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Facebook_Platform#Open_Graph_protocol&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/what-is-open-graph-and-how-can-i-use-it-for-my-website/#:~:text=Open%20Graph%20is%20an%20internet,the%20duration%20of%20a%20video" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/what-is-open-graph-and-how-can-i-use-it-for-my-website/#:~:text=Open%20Graph%20is%20an%20internet,the%20duration%20of%20a%20video&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Social_graph#/media/File:Sna_large.png" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Social_graph#/media/File:Sna_large.png&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://ogp.me/#structured" rel="noopener noreferrer"&gt;https://ogp.me/#structured&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.facebook.com/tools/debug/" rel="noopener noreferrer"&gt;https://developers.facebook.com/tools/debug/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cards-dev.twitter.com/validator" rel="noopener noreferrer"&gt;https://cards-dev.twitter.com/validator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Media_type" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Media_type&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup" rel="noopener noreferrer"&gt;https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>career</category>
      <category>education</category>
      <category>employment</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>Open Graph Protokolü Nedir?</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 01 Mar 2023 22:21:38 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/open-graph-protokolu-nedir-801</link>
      <guid>https://dev.to/muhammederdinc/open-graph-protokolu-nedir-801</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2Fguz2lufynbnatev3rz0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fguz2lufynbnatev3rz0w.png" width="377" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ogp.me/" rel="noopener noreferrer"&gt;Open Graph Protokolü&lt;/a&gt;, &lt;a href="https://tr.wikipedia.org/wiki/URL" rel="noopener noreferrer"&gt;URL&lt;/a&gt;’lerin sosyal medyada paylaşıldığında nasıl görüntüleceğini kontrol eden ve &lt;a href="https://tr.wikipedia.org/wiki/World_Wide_Web" rel="noopener noreferrer"&gt;Web&lt;/a&gt; sayfalarındaki &lt;a href="https://tr.wikipedia.org/wiki/Arama_motoru_optimizasyonu" rel="noopener noreferrer"&gt;SEO&lt;/a&gt; meta verilerinin standartlaştırılması için &lt;a href="https://tr.wikipedia.org/wiki/Meta,_Inc." rel="noopener noreferrer"&gt;Facebook&lt;/a&gt; tarafından oluşturulmuş bir protokolüdür. Meta verilerinin standartlaştırılması, siteler arası meta veri uyumsuzluğunu ortadan kaldırmıştır. Günümüzde Open Graph protokolü, Facebook dışında &lt;a href="https://tr.wikipedia.org/wiki/LinkedIn" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; ve &lt;a href="https://tr.wikipedia.org/wiki/Twitter" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; gibi diğer sosyal medya siteleri tarafından da kullanılmaktadır. Open Graph etiketleri bir Web sayfasının head bölümünde yer alırlar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F1a6mdj8x5o4cxgokcw8h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1a6mdj8x5o4cxgokcw8h.png" alt="LinkedIn’de paylaşılan bu URL’nin önizlemesinde yer alan başlık ve görüntü Open Graph etiketlerinden gelmektedir." width="556" height="715"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;İçeriğinizi daha geniş kitlelere ulaştırmak için sosyal medya siteleri oldukça önemlidir. Kullanıcıların optimize edilmiş Open Graph etiketleriyle paylaşılan içeriği görme ve tıklama olasılıkları, oluşan önizlemenin içerikle uyumlu olması nedeniyle daha yüksektir, bu da web siteniz için daha fazla sosyal medya trafiği anlamına gelir. Open Graph etiketleriyle oluşturulan önizlemelerin faydaları ise şunlardır:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Sosyal medya akışlarında içeriği daha dikkat çekici hale getirirler.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;İnsanlara içeriğin ne hakkında olduğunu bir bakışta söylerler.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Facebook’un içeriğin ne hakkında olduğunu anlamasına yardımcı olurlar, bu da arama yoluyla marka görünürlüğünüzü artırmanıza yardımcı olacaktır.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2zc4lar80bjo0773z5u2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2zc4lar80bjo0773z5u2.png" alt="Twitter’da paylaşılan bu URL’nin önizlemesinde yer alan görüntü, başlık ve açıklama bilgisi Open Graph etiketlerinden gelmektedir." width="602" height="609"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter ve LinkedIn’de paylaşılan &lt;a href="https://github.blog/changelog/2022-02-23-the-new-github-issues-february-23rd-update/" rel="noopener noreferrer"&gt;sitenin&lt;/a&gt; &lt;/p&gt; bölümüne baktığımızda Open Graph meta etiketlerini görebiliriz.

&lt;p&gt;&lt;a href="https://media2.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%2Ff9zyzsvkcgzcnzs6bh8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ff9zyzsvkcgzcnzs6bh8w.png" alt="Yukarıdaki örnek paylaşımlarda yer alan sitenin meta etiketleri" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Her sayfa için gerekli olan dört temel Open Graph etiketleri; og:title, og:type, og:image ve og:url’dir. Bazı meta etiketlerine ve açıklamalarına kısaca bakalım:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;“og:title”&lt;/strong&gt;: Sayfanızın başlığını temsil edecektir. Çoğu zaman web sayfasının &lt;/p&gt; etiketiyle aynıdır.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:type”&lt;/strong&gt;: Web sitesinin türünü temsil etmektedir. Yukarıdaki örnekte bu “article” olarak belirtilmiştir.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:image”&lt;/strong&gt;: Sayfanızı temsil eden resmin URL’sidir.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:url”&lt;/strong&gt;: Sayfanızın geçerli URL’sini ifade eder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:description”&lt;/strong&gt;: İçeriğinizin kısa bir açıklamasını ifade eder. Genellikle &amp;lt;meta type=”description” ile aynıdır.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:audio”&lt;/strong&gt;: İçeriğinizi temsil eden ses dosyasının URL’sidir.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:video”&lt;/strong&gt;: İçeriğinizi temsil eden video URL’sidir.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fk39yr6qgot1fryfxuyyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fk39yr6qgot1fryfxuyyo.png" alt="Open graph etiketleriyle oluşturulan twitter kartının anatomisi" width="800" height="622"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Görüntüler İçin Ek Meta Etiketleri
&lt;/h3&gt;

&lt;p&gt;Bazı meta etiketlerinde, kendilerine eklenmiş ek meta etiketleri olabilir. Örneğin og:image etiketi üzerinden ilerleyelim. Genellikle og:image etiketi ile ilerlemek yeterli olacaktır fakat bazı durumlarda içeriğinizin önizlemesi istediğiniz gibi görünmeyebilir. Bunun için ek meta etiketlerine ihtiyaç duyabilirsiniz. Örneğin görüntünüzün yükseklik ve genişlik bilgisini ayarlamak isteyebilirsiniz.&lt;/p&gt;

&lt;p&gt;Aşağıda og:image için bazı meta etiketlerini ve açıklamalarını görebilirsiniz.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“og:image:url”&lt;/strong&gt;: og:image ile aynıdır. Görüntünün URL’sini ifade eder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“og:image:secure_url”&lt;/strong&gt;: Web sayfası için &lt;a href="https://tr.wikipedia.org/wiki/HTTPS" rel="noopener noreferrer"&gt;HTTPS&lt;/a&gt; gerekiyorsa kullanılabilecek alternatif URL’yi temsil eder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“og:image:type”&lt;/strong&gt;: Görüntü için &lt;a href="https://en.wikipedia.org/wiki/Media_type" rel="noopener noreferrer"&gt;medya türü&lt;/a&gt; bilgisini ifade eder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:image:width”&lt;/strong&gt;: Görüntünün genişlik bilgisini piksel olarak ifade eder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og:image:height”&lt;/strong&gt;: Görüntünün yükseklik bilgisini piksel olarak ifade eder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“&lt;strong&gt;og: image:alt”&lt;/strong&gt;: Görüntünün içeriği ile ilgili açıklamayı ifade eder.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AyPuPpXyfBN4HQA3Vm4wpMg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AyPuPpXyfBN4HQA3Vm4wpMg.png" alt="og:image meta etiketlerinin kullanımı ([Ekran görüntüsünün kaynağı](https://ogp.me/#structured))" width="800" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Open Graph Etiketlerini Test Etmek
&lt;/h3&gt;

&lt;p&gt;Open Graph meta etiketlerinizi ekledikten sonra içeriğinizin sosyal medya sitelerinde nasıl göründüğünü test edebilirsiniz. Bu sayede meta etiketlerinizde hata ayıklama işlemi çok daha kolay olacaktır.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ft45w3emqxedlp531oqbp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ft45w3emqxedlp531oqbp.png" alt="Twitter kart önizleme örneği" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Facebook ve Twitter için test linkleri aşağıdadır:&lt;/p&gt;

&lt;p&gt;Facebook: &lt;a href="https://developers.facebook.com/tools/debug/" rel="noopener noreferrer"&gt;https://developers.facebook.com/tools/debug/&lt;/a&gt;&lt;br&gt;
Twitter: &lt;a href="https://cards-dev.twitter.com/validator" rel="noopener noreferrer"&gt;https://cards-dev.twitter.com/validator&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Kaynaklar
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://ogp.me/" rel="noopener noreferrer"&gt;https://ogp.me/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Social_graph" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Social_graph&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Facebook_Platform#Open_Graph_protocol" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Facebook_Platform#Open_Graph_protocol&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/what-is-open-graph-and-how-can-i-use-it-for-my-website/#:~:text=Open%20Graph%20is%20an%20internet,the%20duration%20of%20a%20video" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/what-is-open-graph-and-how-can-i-use-it-for-my-website/#:~:text=Open%20Graph%20is%20an%20internet,the%20duration%20of%20a%20video&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Social_graph#/media/File:Sna_large.png" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Social_graph#/media/File:Sna_large.png&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://ogp.me/#structured" rel="noopener noreferrer"&gt;https://ogp.me/#structured&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.facebook.com/tools/debug/" rel="noopener noreferrer"&gt;https://developers.facebook.com/tools/debug/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cards-dev.twitter.com/validator" rel="noopener noreferrer"&gt;https://cards-dev.twitter.com/validator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Media_type" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Media_type&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup" rel="noopener noreferrer"&gt;https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>automation</category>
      <category>ai</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Global Error Management in Nuxt.js Projects</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 01 Mar 2023 22:19:17 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/global-error-management-in-nuxtjs-projects-3d16</link>
      <guid>https://dev.to/muhammederdinc/global-error-management-in-nuxtjs-projects-3d16</guid>
      <description>&lt;p&gt;Today, frontend projects have become more complex and dynamic compared to the past. Therefore, we have to consider many parameters while developing a frontend project. One of these parameters is error management.&lt;/p&gt;

&lt;p&gt;With a error management, our project will not crash in the face of undesirable situations, the cause of the error will be shown to the user and the user experience will be increased.&lt;/p&gt;

&lt;p&gt;In a frontend project, it is important to show the user the information about the operations that the application performs or cannot for some reason. This information can be displayed to the user with the snackbar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4k1alsp1iygsbpdb2dyf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4k1alsp1iygsbpdb2dyf.png" alt="Snackbar example" width="712" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are developing a frontend project with Nuxt.js and you are making HTTP requests with axios, it is very easy to catch and process errors caused by HTTP requests globally with &lt;a href="https://axios.nuxtjs.org/helpers/" rel="noopener noreferrer"&gt;Axios Interceptors&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Axios Interceptors?
&lt;/h3&gt;

&lt;p&gt;Axios interceptors are functions that are called on every HTTP request or response. HTTP requests and responses can be handled with the help of these functions before they are handled (by “then” or “catch”) within the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global Error Management with Axios Interceptors
&lt;/h3&gt;

&lt;p&gt;With axios-module, a special version of Axios for Nuxt, it is possible to do global error management with a simple plugin that you add to your project.&lt;br&gt;
For this, respectively;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let’s create the axios.js file in the Plugins folder and include it in nuxt.config.js.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;We can now catch and manage HTTP errors with $axios.onError. Also, onRequest, onResponse, onRequestError and onResponseError can be used together with onError as needed.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

HTTP requests and responses along with global error handling will help us build a clean and maintainable architecture. In addition, it will be much easier to eliminate possible errors and add new features, and the maintenance cost of the project will decrease.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://axios.nuxtjs.org/helpers/" rel="noopener noreferrer"&gt;https://axios.nuxtjs.org/helpers/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://axios.nuxtjs.org/extend" rel="noopener noreferrer"&gt;https://axios.nuxtjs.org/extend&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://material.io/components/snackbars#anatomy" rel="noopener noreferrer"&gt;https://material.io/components/snackbars#anatomy&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>introduction</category>
      <category>softwareengineering</category>
      <category>ai</category>
      <category>learning</category>
    </item>
    <item>
      <title>Nuxt.js Projelerinde Global Hata Yönetimi</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Wed, 01 Mar 2023 22:17:38 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/nuxtjs-projelerinde-global-hata-yonetimi-22d4</link>
      <guid>https://dev.to/muhammederdinc/nuxtjs-projelerinde-global-hata-yonetimi-22d4</guid>
      <description>&lt;p&gt;Günümüzde frontend projeleri eskiye kıyasla daha karmaşık ve dinamik bir hale gelmiş durumdadırlar. Bu nedenle bir frontend projesi geliştirirken birçok parametreyi göz önünde bulundurmak zorundayız. Bu parametlerden biri de iyi bir hata yönetiminin yapılmasıdır.&lt;/p&gt;

&lt;p&gt;İyi bir hata yönetimi ile birlikte istenmeyen durumlar karşısında projemiz çökmeyecek, hatanın sebebi kullanıcıya gösterilebilecek ve kullanıcı deneyimi artmış olacaktır.&lt;/p&gt;

&lt;p&gt;Bir frontend projesinde uygulamanın gerçekleştirdiği veya bir sebepten dolayı gerçekleştiremediği işlemler ile ilgili bilgileri kullanıcıya göstermek önemlidir. Bu bilgiler &lt;a href="https://material.io/components/snackbars" rel="noopener noreferrer"&gt;snackbar&lt;/a&gt; ile kullanıcıya gösterilebilir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe7sbbn03jasn034ng9ex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe7sbbn03jasn034ng9ex.png" alt="Snackbar örneği" width="361" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Eğer Nuxt.js ile frontend projesi geliştiriyorsanız ve HTTP isteklerini axios ile yapıyorsanız, HTTP isteklerinden kaynaklanan hataların global olarak yakalanıp işlenmesi &lt;a href="https://axios.nuxtjs.org/helpers" rel="noopener noreferrer"&gt;Axios Interceptors&lt;/a&gt; ile oldukça kolaydır.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Axios Interceptors Nedir?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Axios interceptors, her HTTP isteği veya yanıtında çağrılan fonksiyonlardır. HTTP istekleri ve yanıtları uygulama içinde ele alınmadan (“then” veya “catch” tarafından işlenmeden) önce bu fonksiyonlar yardımıyla ele alınabilirler.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Axios Interceptors İle Global Hata Yönetimi Yapmak&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Axios’un Nuxt’a özel sürümü olan &lt;a href="https://github.com/nuxt-community/axios-module" rel="noopener noreferrer"&gt;axios-module&lt;/a&gt; ile birlikte, projenize ekleyeceğiniz basit bir plugin ile global hata yönetimi yapmak mümkündür. Bunun için sırasıyla;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Plugins klasörü içine axios.js dosyasını oluşturup nuxt.config.js içerisine dahil edelim.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Artık $axios.onError ile birlikte HTTP hatalarını yakalayıp yönetebiliriz. Ayrıca ihtiyaca göre onError ile birlikte onRequest, onResponse, onRequestError ve onResponseError da kullanılabilir.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

Global hata yönetimi ile birlikte HTTP isteklerininin ve yanıtlarının merkezi olarak yönetilmesi, temiz ve sürdürülebilir bir mimari kurmamıza yardımcı olacaktır. Ayrıca olası hataların giderilmesi ve yeni özelliklerin eklenmesi çok daha kolay olacak, projenin bakım maliyeti düşecektir.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;h3&gt;
  
  
  Kaynaklar
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://axios.nuxtjs.org/helpers/" rel="noopener noreferrer"&gt;https://axios.nuxtjs.org/helpers/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://axios.nuxtjs.org/extend" rel="noopener noreferrer"&gt;https://axios.nuxtjs.org/extend&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://material.io/components/snackbars#anatomy" rel="noopener noreferrer"&gt;https://material.io/components/snackbars#anatomy&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devto</category>
      <category>posts</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>Writing Complex Classes Using @apply and Postcss-Nesting with TailwindCSS</title>
      <dc:creator>Muhammed Erdinç</dc:creator>
      <pubDate>Fri, 24 Feb 2023 11:56:31 +0000</pubDate>
      <link>https://dev.to/muhammederdinc/writing-complex-classes-using-apply-and-postcss-nesting-with-tailwindcss-2epm</link>
      <guid>https://dev.to/muhammederdinc/writing-complex-classes-using-apply-and-postcss-nesting-with-tailwindcss-2epm</guid>
      <description>&lt;p&gt;When we look at the examples where TailwindCSS is used, we can see that the code written in inline has low readability and is not usable for big projects. In such cases, we can avoid this problem by using the existing TailwindCSS classes with @apply in our own custom CSS classes. Let’s try to clarify the issue by going through a simple button component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VC43wTRs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A-3Beu2ErN9p5AooWWZrSZA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VC43wTRs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A-3Beu2ErN9p5AooWWZrSZA.png" alt="Example button component" width="248" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mJghugBB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3420/1%2ANWYZn17saSIby_liEqHb0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mJghugBB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3420/1%2ANWYZn17saSIby_liEqHb0Q.png" alt="" width="880" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, when we style our button by typing the TailwindCSS classes in inline, we can see that the code is not very readable. In this example, the higher the number of codes, the lower the readability will be. Let’s refactor the above example using @apply.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dxc9AkgP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3560/1%2AJe0dshif8Wa8lO2uK3-5Jw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dxc9AkgP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3560/1%2AJe0dshif8Wa8lO2uK3-5Jw.png" alt="btn classes with @apply" width="880" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mK7shEJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2024/1%2A21RCI9QbgAjJd-LDPC6mmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mK7shEJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2024/1%2A21RCI9QbgAjJd-LDPC6mmw.png" alt="Use of btn classes" width="880" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we have obtained a more readable and manageable code base. While specifying CSS class names, we can proceed by following the BEM standard and also by writing nested custom classes as in SCSS. However, since PostCSS does not support nested classes by default, we will need to install a PostCSS plugin and move forward.&lt;/p&gt;

&lt;p&gt;Since TailwindCSS is a PostCSS plugin, we can use it with Sass, Less, Stylus or other preprocessors just like any other PostCSS plugin like Autoprefixer. However, since we will write very little CSS in a TailwindCSS project (perhaps not at all), we don’t have to use a preprocessor. In fact, it would be better to work with PostCSS only, unless it is mandatory. The advantages of developing projects using only PostCSS and its plugins are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Since your CSS doesn’t have to be parsed and processed by multiple tools, your CSS will compile much quicker using only PostCSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Because Tailwind adds some new non-standard keywords to CSS (like &lt;a class="mentioned-user" href="https://dev.to/tailwind"&gt;@tailwind&lt;/a&gt;, @apply, theme(), etc.), you often have to write your CSS in annoying, unintuitive ways to get a preprocessor to give you the expected output. Working exclusively with PostCSS avoids this.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Considering the above items, it will be sufficient for us to develop only with PostCSS unless we have to. If necessary, we can install PostCSS plugins and continue to develop. You can review the PostCSS GitHub repository for available &lt;a href="https://github.com/postcss/postcss/blob/main/docs/plugins.md"&gt;PostCSS plugins&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since we only want to move forward with PostCSS, we need to use a PostCSS plugin that allows us to write nested classes. For this, we have two alternatives, &lt;a href="https://github.com/postcss/postcss-nested"&gt;postcss-nested&lt;/a&gt; and &lt;a href="https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting"&gt;postcss-nesting&lt;/a&gt;. In this article we will use the postcss-nesting plugin as it is recommended in the TailwindCSS document. Installation and more detailed information can be found &lt;a href="https://tailwindcss.com/docs/using-with-preprocessors#nesting"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s try to move forward through an example again. Let’s create the following buttons using TailwindCSS helper classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BlchPiIO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AL08oZyOA3TwgCT41hcIWLQ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BlchPiIO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AL08oZyOA3TwgCT41hcIWLQ.gif" alt="button examples" width="802" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The codes we will write to create the above buttons will be as follows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tXxvtPiY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5748/1%2AVC4uoorm5eeZYQsNSq522Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tXxvtPiY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5748/1%2AVC4uoorm5eeZYQsNSq522Q.png" alt="" width="880" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above usage, since editing or developing the buttons would be very costly for us, let’s try to edit this code together now. We will now be able to use our CSS codes by nesting them with the Postcss-Nesting plugin. Now let’s edit our code and see how it looks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LSKvF51G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5084/1%2Ab-DfSWDWDni1VrJ5-v7uAA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LSKvF51G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5084/1%2Ab-DfSWDWDni1VrJ5-v7uAA.png" alt="" width="880" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that the newly created CSS classes are more readable and organized. Now it will be much easier to manage and develop our button components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fNl8_QOv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3568/1%2AHy3H2zjGTMMc3a8ZfPFfBg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fNl8_QOv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3568/1%2AHy3H2zjGTMMc3a8ZfPFfBg.png" alt="" width="880" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, we can edit the “focus” and “hover” parts to increase the readability of the code. Here, let’s rewrite our code by enclosing the “hover” and “focus” classes in separate blocks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4DwNVBmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3660/1%2AWxIEIA20V4deymgeW06opA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4DwNVBmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3660/1%2AWxIEIA20V4deymgeW06opA.png" alt="" width="880" height="706"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think we have achieved a better code base with our recent edits. Proceeding in this way will both make the code more readable and make a new development much less costly. In addition, when working as a team, it will be much easier to make code reviews and find possible errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;References:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/functions-and-directives#apply"&gt;https://tailwindcss.com/docs/functions-and-directives#apply&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/using-with-preprocessors#using-sass-less-or-stylus"&gt;https://tailwindcss.com/docs/using-with-preprocessors#using-sass-less-or-stylus&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/using-with-preprocessors#nesting"&gt;https://tailwindcss.com/docs/using-with-preprocessors#nesting&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/csstools/postcss-nesting"&gt;https://github.com/csstools/postcss-nesting&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/using-with-preprocessors#using-post-css-as-your-preprocessor"&gt;https://tailwindcss.com/docs/using-with-preprocessors#using-post-css-as-your-preprocessor&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>tailwindcss</category>
      <category>css</category>
      <category>webdev</category>
      <category>postcss</category>
    </item>
  </channel>
</rss>
