<?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: Kubilay Çakmak</title>
    <description>The latest articles on DEV Community by Kubilay Çakmak (@kubilayckmk).</description>
    <link>https://dev.to/kubilayckmk</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%2F289632%2Ffff78cf4-cdc5-4a6a-9587-55ac1b261fa5.png</url>
      <title>DEV Community: Kubilay Çakmak</title>
      <link>https://dev.to/kubilayckmk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kubilayckmk"/>
    <language>en</language>
    <item>
      <title>React &amp; Redux</title>
      <dc:creator>Kubilay Çakmak</dc:creator>
      <pubDate>Wed, 27 Apr 2022 22:49:11 +0000</pubDate>
      <link>https://dev.to/kubilayckmk/react-redux-3562</link>
      <guid>https://dev.to/kubilayckmk/react-redux-3562</guid>
      <description>&lt;h2&gt;
  
  
  Hello React lovers!
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvcg8o574zoiagb4zu1m1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvcg8o574zoiagb4zu1m1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this and the next two articles I will write, I plan to discuss &lt;strong&gt;redux&lt;/strong&gt; and its &lt;em&gt;relationship&lt;/em&gt; with &lt;strong&gt;react&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I will touch on these concepts before I think it would be difficult to understand &lt;strong&gt;Redux&lt;/strong&gt; without understanding the &lt;em&gt;state management&lt;/em&gt; issue and its problems.&lt;/p&gt;

&lt;p&gt;The topics that I will cover in this article are shown below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. What is state management?&lt;/li&gt;
&lt;li&gt;2. State management problems.&lt;/li&gt;
&lt;li&gt;3. Technologies that find solutions to problems.&lt;/li&gt;
&lt;li&gt;4. What is Redux?&lt;/li&gt;
&lt;li&gt;5. Basic concepts in Redux.&lt;/li&gt;
&lt;li&gt;6. How Redux works.&lt;/li&gt;
&lt;li&gt;7. Redux example.&lt;/li&gt;
&lt;li&gt;8. What is state management?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;State is the properties and information that each of the components in our applications currently have. The variability of this feature and information reveals the concept called state. &lt;br&gt;
For example, whether a checkbox is checked or not is a state, an information. We use this information to determine how to move forward in our practice. On the other hand, the location, size, shape, etc. of this checkbox. Since the information is fixed, it would be more logical not to specify it as a state.&lt;br&gt;
&lt;strong&gt;State management problems&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;As the components inside the application increase, these cases increase. As such, the management of these situations is becoming more and more inextricable. For example, models of states may replace one another, or a case may act on an unrelated component. The most common example of this problem in many places is the problem that Facebook has with its messages and notifications. This problem is uncontrolled data flow. Facebook solves this with its flux architecture. This architecture reduces complexity by providing one-way data flow.&lt;br&gt;
_&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Technologies that find solutions to problems.&lt;br&gt;
_&lt;br&gt;
These problems were first solved with the flux architecture. Apart from that, most of the developing technologies have similarities with this architecture. Almost all of them have the same concepts.&lt;br&gt;
Here are a few of them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;redux&lt;/li&gt;
&lt;li&gt;Akita&lt;/li&gt;
&lt;li&gt;NGRX&lt;/li&gt;
&lt;li&gt;mobx&lt;/li&gt;
&lt;li&gt;React Context&lt;/li&gt;
&lt;li&gt;vuex&lt;/li&gt;
&lt;li&gt;carebral&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What is Redux?
&lt;/h2&gt;

&lt;p&gt;It is an open source state management library, almost the most used. If we understood state management, I think we understood what redux actually does. In general, it tries to make state more manageable by centralizing the state and reducing the complexity of the implementation. Redux is created by the head of react (dan abramov). It is a standalone library with React. The reason why it is mentioned so much with React is that it works very compatible with React (see: react-redux). We can use this library in other javascript libraries very easily.&lt;br&gt;
Basic concepts in Redux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action&lt;/strong&gt;: It is a javascript object. It carries the information (type) and state data of which state will change in the store (payload).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{ type: ORDER_INCREASE , payload: 1 }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We often use Action Creators to make Actions more useful. Action Creators are arrow functions. It just takes the changed payload part as a parameter and returns an action. Types are usually kept in a separate file (actionTypes) as they are only directional constants that do not change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Action Creator
const orderIncrementSuccess = quantity =&amp;gt; ({ type: ORDER_INCREASE, payload: quantity });
//actionTypes.js
export const ORDER_INCREASE = ”ORDER_INCREASE”
export const ORDER_DECREASE = ”ORDER_DECREASE”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reducer&lt;/strong&gt;: It is a pure function that takes state and action as parameters and returns the new state. It changes the state according to the action's type and returns the new state. An up-to-date copy of the state must be returned. Otherwise, the components will not render themselves. The purpose of doing this is to change the reference of the state. We can use Object.assign() or Object spread opretaor methods for this. We should not forget to give the initial value so that the state is not undifined at the start of the program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reducer=(state=0,action)=&amp;gt;{
     switch(action.type){
            case 'ORDER_INCREASE':
                return state+action.payload;
            case 'ORDER_DECREASE':
                return state-action.payload;
            default:
                return state;
       }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We do not use reducer directly. We send reducers as parameters to the store. When we create the action we send using store,dispatch and the state defined in the store, we pass parameters to the reducer function that we send. As a result of this operation, the returned state is overwritten by the state in the store. So we just tell the store how to change the state using the dispatch function. Store runs the reducer function.&lt;/p&gt;

&lt;p&gt;Here is a question that may come to your mind. “Store, which action will be passed to which reducer? How does he determine that?” I thought a lot about this question. The most logical explanation to me is; It does this in all reducers by passing the actionu parameter. Whichever switch is caught, it does the relevant operation there. At least I haven't seen the opposite yet. If friends who know write in the comment section, we will get more accurate information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Store&lt;/strong&gt;: This is where the State is kept. We use the createStore function to create the Store. It takes reducers as parameters. When there are more than one reducer, which is usually the case. We use the combineReducer function to send them together. Redux keeps these reducers in a common object for us, making it easy to access and use. Although it does it for itself, we just use it.&lt;br&gt;
Three functions return.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dispatch&lt;/li&gt;
&lt;li&gt;getState&lt;/li&gt;
&lt;li&gt;subscribe&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dispatch&lt;/strong&gt;: Triggers the reducer by taking the action as parameters. As a result, the state is changed. Every time this function is run, all subscribed components are rendered again. Of course, after the state changes, the rendering is done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getState&lt;/strong&gt;: Returns the current state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;subscribe&lt;/strong&gt;: Components subscribe to the Store using this function. Store stores all subscribed components in it. As a parameter, it takes the function that the component depends on the state, that is, it will render whenever the state changes, it is important that this function uses the getState function. Actually the purpose here is to run getState. In this way, we can see that the state has changed in the view. Otherwise, the state changes, but this is not reflected in the view.&lt;/p&gt;

&lt;p&gt;How Redux works;&lt;/p&gt;

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

&lt;p&gt;I will write the steps of the above flow in items.&lt;br&gt;
The user performs an action in the view that will &lt;strong&gt;&lt;em&gt;trigger&lt;/em&gt;&lt;/strong&gt; the &lt;strong&gt;action&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Dispatch passes the incoming action as a parameter to the reducer with the current state in the store.&lt;br&gt;
As a result of this operation, the relevant parts of the state change and a new state is formed. Here we understand the importance of &lt;strong&gt;Object.assign()&lt;/strong&gt; or Object spread operator methods for reducer, if state holds more than one data.&lt;br&gt;
As the state is updated, all subscribed components are rendered again.&lt;/p&gt;

&lt;p&gt;Finally, this state is reflected back to the view.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our example will be a counter instance, as in most examples.&lt;br&gt;
Below are the html codes and images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
 &amp;lt;head&amp;gt;
 &amp;lt;/head&amp;gt;
 &amp;lt;body&amp;gt;
  &amp;lt;div id="root"&amp;gt;
   &amp;lt;h1 id="value"&amp;gt;&amp;lt;/h1&amp;gt;
   &amp;lt;button id="btn_increase"&amp;gt;+1&amp;lt;/button&amp;gt;
   &amp;lt;button id="btn_decrease"&amp;gt;-1&amp;lt;/button&amp;gt;   
  &amp;lt;/div&amp;gt;
  &amp;lt;script src="sampleRedux.js"&amp;gt;&amp;lt;/script&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;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7v5j492ny0brgrwji2f2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7v5j492ny0brgrwji2f2.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;We will simply increase and decrease the counter. We will keep the value of the counter as state.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reducer&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const counterReducer=(state=0, action)=&amp;gt;{
         switch(action.type){
              case 'INCREMENT':
                   return state+1;
              case 'DECREMENT':
                   return state-1;
              default:
                   return state;
            }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We set the initial value of the reducer to zero. We return the new state according to the type of the incoming action. If there is a type that does not match, we return the current state. Since the action of the incoming type is fixed, the payload feature is not given to the action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Store&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const createStore=(reducer)=&amp;gt;{
         let state;
         let listeners=[];

         const getState=()=&amp;gt;state;

         const dispatch=(action)=&amp;gt;{
             state=reducer(state ,action);
             listeners.forEach(listener=&amp;gt;listener());
         };

         const subscribe=(listener)=&amp;gt;{
             listeners.push(listener);
             return()=&amp;gt;{
                listener=listener.filter(l=&amp;gt;l!==listener);
             };
         }

         dispatch({});

    return {getState, dispatch, subscribe}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;GetState&lt;/strong&gt; returns the current state in the Store.&lt;br&gt;
If you notice in the dispatch function, it sends the action, which comes as a parameter with the state defined in the store, to the reducer, which comes as a parameter to our store. It sets the return value to state.&lt;br&gt;
After this process, it renders by browsing through all the subscribed components in listeners. In this way, it is reflected in the current state view.&lt;br&gt;
The subscribe function takes parameters and pushes the components that want to subscribe to the listeners array. Running the loopback function unsubscribes the subscribed component.&lt;br&gt;
Before returning these three functions, we run dispatch once for the state to be created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const store = createStore(counterReducer);
const render=()=&amp;gt;{
    document.getElementById("value").innerText=store.getState();
}
var unSubscribe = store.subscribe(render);
//unSubscribe();
render();
document.getElementById("btn_increase").addEventListener('click',()=&amp;gt;{
     store.dispatch({type:'INCREMENT'});
})
document.getElementById("btn_decrease").addEventListener('click',()=&amp;gt;{
    store.dispatch({type:'DECREMENT'});
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we create our store by passing the reducer as a parameter. We render the places where the State will be displayed by connecting getState to the relevant components (rendering).&lt;/p&gt;

&lt;p&gt;To be notified when the state changes, we subscribe with the store.subscribe function. This function returns a function (unSubscribe). If we run it, we unsubscribe the component.&lt;br&gt;
By running the render function once, we reflect the current state to the component. Zero will appear because its initial value is zero.&lt;/p&gt;

&lt;p&gt;Finally, we connect the dispatch methods to the click event of the buttons. Since each button sends a different action, it will have different actions on the state.&lt;/p&gt;

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

&lt;p&gt;HAPPY CODING!&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>statemanagement</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Vue.js State Management with Vuex</title>
      <dc:creator>Kubilay Çakmak</dc:creator>
      <pubDate>Mon, 07 Feb 2022 19:51:28 +0000</pubDate>
      <link>https://dev.to/kubilayckmk/vuejs-state-management-with-vuex-1h5b</link>
      <guid>https://dev.to/kubilayckmk/vuejs-state-management-with-vuex-1h5b</guid>
      <description>&lt;p&gt;When using current JavaScript frameworks in an application, we use multiple components (bi). It can be obtained from locations like communicating or exchanging data, as well as the (parent) component it contains or is in. Component counts and productions by apps do not become more difficult in this way. We'll learn about Vuex in this tutorial, which allows us to manage state (state) management for the Vue.js framework from a central location.&lt;/p&gt;

&lt;h2&gt;
  
  
  What exactly is Vuex?
&lt;/h2&gt;

&lt;p&gt;Vuex is an open-source library for managing Vue.js state from a central location. It is created by Vue.js programmers. &lt;/p&gt;

&lt;p&gt;So, what is the point of Vuex? Let's look at an example of code.&lt;/p&gt;

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

&lt;p&gt;When we look at the code in the image above, we can see that the state value is stored in a Vue instance (instance). &lt;/p&gt;

&lt;p&gt;The data (count) that will be used in the programme. &lt;br&gt;
The field (template) where the data from the State will be presented is known as the View. &lt;br&gt;
Action: A structure (increment) that modifies the state in response to a user event. &lt;br&gt;
When we model the above code on the figure, we get something like this. There is a one-way data flow in this image. (data flow in one direction)&lt;/p&gt;

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

&lt;p&gt;It's a basic structure, but when there are different parts using similar states, this straightforwardness becomes subtle. Different views may need to use similar states. More than one Action may be required to follow similar states. There are ways around the above, but acknowledging them destroys the ease of work, and the application becomes more cluttered. For example: To solve the main problem, it is possible to make a solved part and send the state as a prop to a sub-part, but sending props to a solved design consistently and changing prop values ​​in the sub-part will not give an adaptation.&lt;/p&gt;

&lt;p&gt;This and similar situations have led to the centralization of state management; separate state from components, make it a singleton and manage it. In this way, no matter which component is in, you can access the relevant state, trigger any Action, and operate on the same state. That's what Vuex gives us. Ensure state is managed from a central location by decoupling from the application the structure that will change this state.&lt;/p&gt;
&lt;h2&gt;
  
  
  Vuex Architecture and Core Concepts
&lt;/h2&gt;

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

&lt;p&gt;Due to its ease of maintenance and development, Vuex has gathered the state and the structures that will operate on this state in a central place.&lt;/p&gt;

&lt;p&gt;All situations seen in the image above are registered in the store in Vuex. Store, in simple terms, is the structure that contains the state of the application.&lt;/p&gt;

&lt;p&gt;Although we say that Vuex's store is a global object, there are two main events that distinguish it from global objects.&lt;/p&gt;

&lt;p&gt;The Vuex store is reactivity (healthier to know its reactive, non-translational version). When there is any change in the state in the store, the components will be warned and updated effectively.&lt;br&gt;
We cannot directly change the state in the store. It should be clearly stated with the help of Commit (which we will talk about later in the article).&lt;br&gt;
vuex; It consists of 4 basic parts: Actions, Mutations, State, Getters. To see these in more detail, we will go through a basic application.&lt;/p&gt;

&lt;p&gt;Let's create an empty project with the help of vue-cli:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vue create vuex-example&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Let's choose the "Default ([Vue 2] babel, eslint)" option since we will show the Vuex implementation for a start.&lt;/p&gt;

&lt;p&gt;Install Vuex with npm:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install vuex ---save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The implementation of Vuex is quite simple. The steps we need to do are as follows;&lt;/p&gt;

&lt;p&gt;We create a JavaScript file called index.js under the store folder. In it, we say that Vue should use Vuex, then we create a new Store instance, define the relevant fields (state, getters, actions, mutations) and export them.&lt;br&gt;
In js, we add it to Vue so that all components can access the store.&lt;/p&gt;

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

&lt;p&gt;Above, we basically created a Vuex Store object and exported it to be used in main.js. The process of registering this exported store value in main.js is as follows;&lt;/p&gt;

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

&lt;p&gt;This is the basic implementation.&lt;/p&gt;

&lt;p&gt;In the store of Vuex; We talked about the existence of fields such as state, getters, mutations, actions, and we defined them as empty in the implementation part. If we look at the details of these;&lt;/p&gt;
&lt;h2&gt;
  
  
  State
&lt;/h2&gt;

&lt;p&gt;We mentioned that Vuex maintains a singleton state. All structures in the application use the same state. State data in the application is kept here.&lt;/p&gt;

&lt;p&gt;There are many ways to access the values defined in the state in the component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    {{ count }}
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
export default {
  computed: {
    count() {
      return this.$store.state.count;
    },
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Previously, we performed the bind operation of the store in Vue and we mentioned that the store contains the state. When we look at the code above, we use $store to access the state value and it is located in the Vue instance. With $store.state.count, we can easily access the count data in the state. This process could be done directly in the template, but it would be healthier to do it in computed. When there is any change due to the reactivity of the state, computed will be triggered and the related fields will be updated again.&lt;/p&gt;

&lt;p&gt;As the number of data on the state increases, putting the relevant data in computed can be annoying and cause a lot of code. For such problems, we can do it automatically with the mapState that comes in Vuex.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
import { mapState } from "vuex";

export default {
  data() {
    return {
      localCount: 5,
    };
  },
  computed: mapState({
    // arrow function can be used to define it briefly.
    count: (state) =&amp;gt; state.count,

    // alias can be given to the relevant state name, `state =&amp;gt; state.count` expression corresponds to count.
    countAlias: "count",

    // The relevant local variable can also be accessed with the this keyword using the normal function.
    countPlusLocalState(state) {
      return state.count + this.localCount;
    },
  }),
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While making the definitions in the mapState, we can also pass it as an array, just like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;computed: mapState([
  // Now we can access the value in state.count by saying this.count.
  "count",
])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of typing &lt;code&gt;this.$store.state.count&lt;/code&gt; for a long time or bind, we can access that data in the state by typing this.count.&lt;/p&gt;

&lt;p&gt;Looking at the above code example, we have assigned the object that mapState returns directly to computed. If we want to use the data in the state as well as to define our own computed properties specifically, we can perform these operations with the spread operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;computed: {
  // We can specifically create local computed.
  localComputed() {
    /* ... */
  },
  // We can complete the state in the store.
  ...mapState({
    /* ... */
  }),
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Getters
&lt;/h2&gt;

&lt;p&gt;The structure we call Getter is similar to the computed property in Vue.&lt;br&gt;
To filter the instance when we want to pass a data in the state in the application through certain operations. We can do something like the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;computed: {
  doneTodosCount() {
    return this.$store.state.todos.filter((todo) =&amp;gt; todo.done).length;
  },
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we look at the code above, the number of completed ones in the todos array in the state is brought, but when we want to use the result of the filtering process in a few components, we need to copy the above code and put it in other components. In such scenarios, the Getter structure provided by Vuex is used.&lt;br&gt;
&lt;strong&gt;When we look at the definition of getter, it takes 2 arguments and the first of these arguments is the state value and the second is the getters where the other getters are located.&lt;br&gt;
**&lt;br&gt;
Below are the **state&lt;/strong&gt; and &lt;strong&gt;getters&lt;/strong&gt; defined in &lt;strong&gt;store/index.js&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const store = new Vuex.Store({
    state: {
        todos: [
            { id: 1, text: "...", done: true },
            { id: 2, text: "...", done: false },
        ],
    },
    getters: {
        doneTodosCount: (state, getters) =&amp;gt; {
            return state.todos.filter((todo) =&amp;gt; todo.done).length;
        },
    },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are similar ways for the related getter to be called in the component, just like in the state.&lt;/p&gt;

&lt;p&gt;For direct access via Store in Component (template): &lt;/p&gt;

&lt;p&gt;&lt;code&gt;this.$store.getters.doneTodosCount; // -&amp;gt; 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Usage in Computed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;computed: {
  doneTodosCount() {
    return this.$store.getters.doneTodosCount;
  },
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do the practical mapping for Getters just like we do using mapState in State. For this, we use mapGetters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    {{ doneCount }}
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import { mapGetters } from "vuex";

export default {
  computed: {
    ...mapGetters({
      // map `this.doneCount` to `this.$store.getters.doneTodosCount`
      doneCount: "doneTodosCount",
    }),
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An alias has been given to the relevant Getter above. If we want to map directly, we can use it as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    {{ doneTodosCount }}
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import { mapGetters } from "vuex";

export default {
  computed: {
    ...mapGetters(["doneTodosCount", "anotherGetter"]),
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Mutations
&lt;/h2&gt;

&lt;p&gt;We use structures called mutations to update the data in the state. Each mutation here contains 2 structures, namely handler and type. The field we call Type is the method name, and the handler is the method that will update the relevant state. This method takes 2 parameters and the first parameter is state and the other parameter is data.&lt;/p&gt;

&lt;p&gt;Below are the state and mutations defined in store/index.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const store = new Vuex.Store({
    state: {
        count: 0,
    },
    mutations: {
        increment(state) {
            // mutate state
            state.count++;
        },
    },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A mutation can be seen above, and its operation is to increase the count in the state by one. Unfortunately, as in State and Getters, direct access is not available in Mutations. To realize this, it is necessary to declare with commit.&lt;/p&gt;

&lt;p&gt;Access from within the Vue component is as follows.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this.$store.commit("increment");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A mutation has been triggered above, if data is also wanted to be sent as a parameter, it is sent as the second parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const store = new Vuex.Store({
    state: {
        count: 0,
    },
    mutations: {
        increment(state, payload) {
            // mutate state
            state.count += payload.amount;
        },
    },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Vuex documentation suggests sending the payload as an object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;this.$store.commit("increment", { amount: 4 });&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We use mapMutations to perform practical mapping operations within the Component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    &amp;lt;h1&amp;gt;
      {{ this.$store.state.count }}
    &amp;lt;/h1&amp;gt;
    &amp;lt;button @click="increment"&amp;gt;Up
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import { mapMutations } from "vuex";

export default {
  methods: {
    ...mapMutations([
      "increment", // map `this.increment()` to `this.$store.commit('increment')`

      // `mapMutations supports payload:
      "incrementBy", // map `this.incrementBy(amount)` to `this.$store.commit('incrementBy', amount)`
    ]),
    ...mapMutations({
      add: "increment", // map `this.add()` to `this.$store.commit('increment')`
    }),
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As seen above, we can get the same name as a direct array, by giving alias.&lt;/p&gt;

&lt;h2&gt;
  
  
  Actions
&lt;/h2&gt;

&lt;p&gt;Actions and Mutations are similar constructs, but there are important differences between them. Because of this difference, the place of use is very important.&lt;br&gt;
The most important difference; action supports asynchronous operation. It is often used in API calls.&lt;/p&gt;

&lt;p&gt;Below are the state, mutations and actions defined in store/index.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const store = new Vuex.Store({
    state: {
        todos: [],
    },
    mutations: {
        insertTodos(state, payload) {
            state.todos = payload;
        },
    },
    actions: {
        fetchTodos(context) {
            fetch("https://jsonplaceholder.typicode.com/todos")
                .then((response) =&amp;gt; response.json())
                .then((data) =&amp;gt; {
                    context.commit("insertTodos", data);
                });
        },
    },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, a method named fetchTodos is defined, and it receives the todo list by requesting the relevant place and triggers the mutation to update the state. In this way, the data coming with the Action will update the State related to the Mutation and the relevant fields will be updated as a component update.&lt;/p&gt;

&lt;p&gt;Methods defined in Action take a parameter called context. Context in itself; It contains features such as state, getters, commit, dispatch. Depending on the situation, the appropriate process can be used.&lt;/p&gt;

&lt;p&gt;The call of the defined action in the component is carried out with the &lt;em&gt;&lt;strong&gt;dispatch&lt;/strong&gt;&lt;/em&gt; operation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
export default {
  created() {
    this.$store.dispatch("fetchTodos");
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We touched on many concepts above, to summarize the process of the work:&lt;/p&gt;

&lt;p&gt;The relevant action is triggered by dispatch, API request is made and data is received.&lt;br&gt;
Mutation is used to update the value in the state with the data coming in the action, and the commit is made.&lt;br&gt;
It updates the relevant Mutation state value and the Getter using that state is triggered and the component update using that Getter.&lt;br&gt;
To give a general example that includes these,&lt;br&gt;
Below are the &lt;em&gt;&lt;strong&gt;state&lt;/strong&gt;&lt;/em&gt;, &lt;em&gt;&lt;strong&gt;getters&lt;/strong&gt;&lt;/em&gt;, &lt;em&gt;&lt;strong&gt;mutations&lt;/strong&gt;&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;actions&lt;/strong&gt;&lt;/em&gt; defined in store/index.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export const store = new Vuex.Store({
    state: {
        todos: [],
    },
    getters: {
        getCompletedTodos(state) {
            return state.todos.filter((todo) =&amp;gt; todo.completed);
        },
    },
    mutations: {
        insertTodos(state, payload) {
            state.todos = payload;
        },
    },
    actions: {
        fetchTodos(context) {
            fetch("https://jsonplaceholder.typicode.com/todos")
                .then((response) =&amp;gt; response.json())
                .then((data) =&amp;gt; {
                    context.commit("insertTodos", data);
                });
        },
    },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is an action called &lt;em&gt;&lt;strong&gt;fetchTodos&lt;/strong&gt;&lt;/em&gt; above, it takes the data with the API request and triggers the relevant &lt;em&gt;&lt;strong&gt;mutation&lt;/strong&gt;&lt;/em&gt; with commit, our method here is &lt;em&gt;&lt;strong&gt;insertTodos&lt;/strong&gt;&lt;/em&gt;. Mutation, on the other hand, updates the state, and due to this update, the components using the &lt;em&gt;&lt;strong&gt;getCompletedTodos&lt;/strong&gt;&lt;/em&gt; Getter use the relevant current data as an update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div id="app"&amp;gt;
    &amp;lt;ul&amp;gt;
      &amp;lt;li v-for="todo in getCompletedTodos" :key="todo.id"&amp;gt;
        {{ todo.title }}
      &amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import { mapActions, mapGetters } from "vuex";

export default {
  methods: {
    ...mapActions(["fetchTodos"]),
  },
  computed: {
    ...mapGetters(["getCompletedTodos"]),
  },
  created() {
    this.fetchTodos();
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above is the mapping, use and listing of the related transactions.&lt;/p&gt;

&lt;p&gt;So far, we have learned what components Vuex consists of, what conveniences it provides and how it is used.&lt;/p&gt;

&lt;p&gt;More information about the state management process is more readable, maintainable (moving to modular structure) and other details is in its official documentation.&lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vuex.vuejs.org/"&gt;VueJs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>vuex</category>
      <category>statemanagement</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to write clean code?!</title>
      <dc:creator>Kubilay Çakmak</dc:creator>
      <pubDate>Tue, 18 Jan 2022 05:00:49 +0000</pubDate>
      <link>https://dev.to/kubilayckmk/how-to-write-clean-code-544f</link>
      <guid>https://dev.to/kubilayckmk/how-to-write-clean-code-544f</guid>
      <description>&lt;p&gt;&lt;strong&gt;To write a clean code&lt;/strong&gt;, it will start with thinking simple. The most important thing is less code is equal to readable code which is clean code.&lt;/p&gt;

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

&lt;p&gt;A good programmer (not just a programmer) is someone who works hard regardless of their experience level or level of expertise. Your responsibility lies in the quality of the code you write, so make it good enough so that other developers can understand and don't mock you every time they have a difficult time with the code you wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object Destructuring
&lt;/h2&gt;

&lt;p&gt;In object destructuring, you can extract specific fields from an object and assign them to a variable instantly. The number of lines of code we need to extract the object properties is reduced, and the code is easier to understand.&lt;/p&gt;

&lt;p&gt;In addition to saving a lot of explicit variable declarations, object destructuring is very helpful in situations where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An object can have multiple properties.&lt;/li&gt;
&lt;li&gt;One property can be used more than once.&lt;/li&gt;
&lt;li&gt;A property that is deeply nested in an object can be used more than once.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const student = {name: ‘John’, email: ‘john@example.com’, phone:’236412354'};

//with destucturing

const {name, email, phone} = student;

//without destucturing

const name = student.name;
const email = student.email;
const phone = student.phone;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both examples (with and without destructuring) have the same output. Destructuring objects simplifies the code and makes it easier to understand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make Use of Arrow Functions
&lt;/h2&gt;

&lt;p&gt;With arrow functions, you can write concise JavaScript functions while solving the problem of accessing this property inside callbacks.&lt;br&gt;
When you use arrow functions, curly braces, parenthesis, function, and return keywords become optional. Your code becomes clearer and easier to understand.&lt;br&gt;
In the following example, a single-line arrow function without parentheses is compared to a regular function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Arrow function

const students = student =&amp;gt; console.log(student);

// Regular Function

function(student){
   console.log(student);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;For example, using arrow functions is not the best approach when working with object prototypes, classes, or object literals.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Spread Extension Operator
&lt;/h2&gt;

&lt;p&gt;Another new feature of ES6 is the spread extension operator (...). This operator allows literals, such as arrays, to be expanded into individual elements with a single line of code.&lt;br&gt;
When we need to put an array or object into a new array or object or to combine multiple parameters in an array, this operator is really useful.&lt;br&gt;
The following code shows how to combine two arrays using the spread operator. As you can see, it makes the code clean and easy to understand since we don’t need to use loops or conditions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = [adam, john, silvia];
let y = [mike, teddy, ..x, frank]
console.log (y);
// mike, teddy, adam, john, silvia, frank
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Shorthand Whenever Possible
&lt;/h2&gt;

&lt;p&gt;The shorthand method can save you a lot of time and space when working with conditions. &lt;br&gt;
If you want to check for empty, null, and undefined conditions for a variable, for example, you'll need to add two conditions in the if statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (x !== “” &amp;amp;&amp;amp; x !== null &amp;amp;&amp;amp; x !== undefined) { ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final
&lt;/h2&gt;

&lt;p&gt;In this tutorial, I'll show you how to use JavaScript's features to produce clean code. &lt;br&gt;
As developers, we should always produce clean code since it improves readability and makes the code easier to grasp for you and your team. &lt;br&gt;
I hope that these tips will assist you in improving the readability of your code, and if you have any further suggestions, please leave them in the comments area.&lt;/p&gt;

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

</description>
      <category>cleancode</category>
      <category>coding</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How Algorithms Solves Problems?</title>
      <dc:creator>Kubilay Çakmak</dc:creator>
      <pubDate>Wed, 29 Sep 2021 18:19:05 +0000</pubDate>
      <link>https://dev.to/kubilayckmk/how-algorithms-solves-problems-582k</link>
      <guid>https://dev.to/kubilayckmk/how-algorithms-solves-problems-582k</guid>
      <description>&lt;h4&gt;
  
  
  What is Algorithm and what is connection with programs?
&lt;/h4&gt;

&lt;p&gt;All programming languages are based on algorithms. Algorithms can be implemented through programming languages.&lt;/p&gt;

&lt;p&gt;Regardless of the language and usage area used in the program, there is no program without an algorithm. In the program, all inputs coming from outside for the operation of an algorithm are defined as &lt;strong&gt;"variables"&lt;/strong&gt;. Loops and operations in the algorithm take place over these variables.&lt;/p&gt;

&lt;p&gt;All possibilities in the algorithm should be specified and clear. No possibility should be left to chance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tw1yjF4w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0gyln996vgew2sx4xu3f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tw1yjF4w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0gyln996vgew2sx4xu3f.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every algorithm should be simple enough to be written down on paper. Algorithms can be represented in plain text or in flowcharts.&lt;br&gt;
Flow charts show the operation of the algorithm in order, showing the cause-effect relationship.&lt;/p&gt;

&lt;p&gt;Let's see couple of example of algorithm. We will write algorithm on a problem.&lt;/p&gt;

&lt;p&gt;The problem can be take sum of the 3 numbers and lets say the variables should be x, y and z.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;step -&amp;gt; start&lt;/li&gt;
&lt;li&gt;step -&amp;gt; define x&lt;/li&gt;
&lt;li&gt;step -&amp;gt; define y&lt;/li&gt;
&lt;li&gt;step -&amp;gt; define z&lt;/li&gt;
&lt;li&gt;step -&amp;gt; result = (x+y+z)/3&lt;/li&gt;
&lt;li&gt;step -&amp;gt; show result to console&lt;/li&gt;
&lt;li&gt;step -&amp;gt; stop&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A solution path consisting of a sequential and finite number of processing steps to be followed to solve a problem.&lt;br&gt;
Sequential presentation of process steps on how to perform a task/job.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It should be clear and unambiguous and should not include vague steps.&lt;/li&gt;
&lt;li&gt;Must have a start state and an end&lt;/li&gt;
&lt;li&gt;The order in which the steps will be performed should be clearly stated.&lt;/li&gt;
&lt;li&gt;In algorithms, large and complex operations are divided into smaller and simpler steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not forget, Key features of the algorithms are;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Must be certain&lt;/li&gt;
&lt;li&gt;Must be executable &lt;/li&gt;
&lt;li&gt;Must be sequential&lt;/li&gt;
&lt;li&gt;Must be finite&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  How algorithms solves problems?
&lt;/h4&gt;

&lt;p&gt;The process of writing correctly by designing appropriate syntax to enable people to communicate with machines is called programming. Programming consists of two sub-elements. Analysis/Design and Coding.&lt;/p&gt;

&lt;p&gt;Analysis/Design -&amp;gt; Designing correctly for problem solving.&lt;br&gt;
Coding -&amp;gt; Expressing this designed way with codes.&lt;/p&gt;

&lt;p&gt;In other words, the way designed to solve the problem with coding is translated into a language that the computer can understand by using a programming language.&lt;/p&gt;

&lt;p&gt;Therefore, what we call an algorithm is actually the solution to the problem that we put forward in the analysis and design process.&lt;/p&gt;

&lt;p&gt;In other words, while creating the solution of a problem in computer language, it is revealing the general operation of the program with logically sequential processing steps before it is coded in a programming language at the analysis stage.&lt;/p&gt;

&lt;p&gt;Problem solving in computer environment...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Understanding the problem (examination, analysis).&lt;/li&gt;
&lt;li&gt;To present alternative solutions.&lt;/li&gt;
&lt;li&gt;To design the algorithm of the program by choosing one of the proposed solutions.&lt;/li&gt;
&lt;li&gt;Coding the designed algorithm in a programming language.&lt;/li&gt;
&lt;li&gt;Detecting errors in the editor where the program was coded and corrected them.
to do.&lt;/li&gt;
&lt;li&gt;To test the operation of the program with sample input and output values.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thanks for reading. Hope its help you about what exactly Algorithms and how to solves problems.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>solveproblems</category>
      <category>coding</category>
    </item>
    <item>
      <title>Would you like to be a Software developer?</title>
      <dc:creator>Kubilay Çakmak</dc:creator>
      <pubDate>Tue, 31 Aug 2021 18:39:06 +0000</pubDate>
      <link>https://dev.to/kubilayckmk/would-you-like-to-be-a-software-developer-3enl</link>
      <guid>https://dev.to/kubilayckmk/would-you-like-to-be-a-software-developer-3enl</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VsqI4FRS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fja2i6h6xdkwln1db46.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VsqI4FRS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fja2i6h6xdkwln1db46.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey there, This is Kubilay Cakmak, I am from Turkey and now I moved to Canada for getting improve myself and maybe find a job here in Canada.&lt;/p&gt;

&lt;p&gt;I am writing this blog for all people who wants to be software developer. Believe me it is not too hard to be. But I am here to explain you what I saw as a student and a jr. in software stuff.&lt;/p&gt;

&lt;p&gt;First of all I got admitted to University. My field was Computer Engineering which we can call Computer Science in Canada. I studied 5 years in University. First year I got prep school which is only about English because my field was 100% English. After graduated from prep school I started to the software classes which is basic introductions ( What is computer, hardware, software ) after those classes we got algorithm class which is actually most important class in Computer science. I cannot think coding without algorithms.&lt;/p&gt;

&lt;p&gt;Algorithm as I said is the most important class which you must make sure you understand. If you don't in class do study out of class. Believe me, when you finish the school you will understand why I am worried about that.&lt;/p&gt;

&lt;p&gt;Secondly, I started to coding at C language which is the 'human-readable form, while the executable that comes out of the compiler is the machine-readable and executable form.'(1)&lt;/p&gt;

&lt;p&gt;We were coding some basic programs with using C language and also we did use algorithms to do practises.&lt;/p&gt;

&lt;p&gt;I will not going deeply what I learned on University because everything in your hands. Teacher will give you basic information on languages and you will chose what you want after graduate. Back-end developer, Front-end developer or Full-stack developer. &lt;/p&gt;

&lt;p&gt;As a student I highly recommend you to do projects. Do with your friends or do as a freelancer. Any projects can be, the goal here is you will finish a project and after that you will have a product. Those products are your portfolio for applying a company. If those projects has story, that will be perfect. What I mean about story is, you did this project for some stuff and you thought this app will help something and while you coding you and your friends found some bugs on frameworks etc.&lt;/p&gt;

&lt;p&gt;While studying I wanted to improve myself on mobile and web developments, I started to write code on Java and Kotlin for Android and Swift for IOS. After understanding how you can code, the languages have similar changes. After you can learn syntax you can code what language and what purpose you want.&lt;/p&gt;

&lt;p&gt;I want to talk about my experience on startup company (GMOBIL). I started my first job just before I graudated from my university and it was full time Front-end developing. I used VueJS and ReactJS for web developing. (VueJS and ReactJS are framework of Javascript). Those frameworks are easy to develop a applications on Javascript with better understanding and better coding. Those technologies have their state management on what you do on status.&lt;/p&gt;

&lt;p&gt;In this company I also created a mobile application with using Flutter (Flutter is an open-source UI software development kit created by Google. It is used to develop cross platform applications for Android, iOS, Linux, Mac, Windows, Google Fuchsia, and the web from a single codebase.(2)).&lt;/p&gt;

&lt;p&gt;After 1 year experience on GMOBIL I decided to leave for moving Canada. While this experience I got, I learned a lot of technology I can use and I did not stop to learning. I am also a freelancer to make fully functional web and mobile applications with using NodeJS (NodeJS is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser.(3))&lt;/p&gt;

&lt;p&gt;I am here wants to be a full-time IOS developer using Swift, and also part-time freelancer on web and mobile developer. Why I want to be a Web and Mobile developer, because I really like to see what is building while I am coding. Some day, I want to be a part of Apple as a IOS developer in future.&lt;/p&gt;

&lt;p&gt;If you have some question please let me know.&lt;br&gt;
Instagram @ kubilaycakmk&lt;br&gt;
Youtube @ Kanada Tecrübesi (&lt;a href="https://www.youtube.com/channel/UCjKzBcazMjDhxkENwFW7bEg"&gt;https://www.youtube.com/channel/UCjKzBcazMjDhxkENwFW7bEg&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;REFERENCES&lt;br&gt;
(1) - &lt;a href="https://computer.howstuffworks.com/c1.htm"&gt;https://computer.howstuffworks.com/c1.htm&lt;/a&gt;&lt;br&gt;
(2) - &lt;a href="https://flutter.dev"&gt;https://flutter.dev&lt;/a&gt;&lt;br&gt;
(3) - &lt;a href="https://nodejs.org"&gt;https://nodejs.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@ffstop?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Fotis Fotopoulos&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/software?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>developer</category>
      <category>softwareengineer</category>
      <category>softwarestudent</category>
    </item>
  </channel>
</rss>
