<?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: Miguel</title>
    <description>The latest articles on DEV Community by Miguel (@un4uthorized).</description>
    <link>https://dev.to/un4uthorized</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%2F468593%2F930968ae-14a5-40f9-81dc-44e42098273b.jpg</url>
      <title>DEV Community: Miguel</title>
      <link>https://dev.to/un4uthorized</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/un4uthorized"/>
    <language>en</language>
    <item>
      <title>Mock isolated service in a React Application</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Tue, 25 Jan 2022 01:37:18 +0000</pubDate>
      <link>https://dev.to/un4uthorized/mock-isolated-service-in-a-react-application-4on3</link>
      <guid>https://dev.to/un4uthorized/mock-isolated-service-in-a-react-application-4on3</guid>
      <description>&lt;p&gt;The term division to conquer was used throughout history in political and political ideals, consisting of the fragmentation of powers, thus, it is a strategy that aims to break or accompany between social structures and take them independently.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Divide and Conquer. - Júlio César"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hi guys, how are you today? &lt;/p&gt;

&lt;p&gt;Based on the divide and conquer principle, i am writing this post to demonstrate how it is possible to isolate services in a react application and test them independently.&lt;/p&gt;

&lt;p&gt;Step one: &lt;strong&gt;Understanding the structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OJtHEURb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rkdvvmsizhhd9pkq78e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OJtHEURb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rkdvvmsizhhd9pkq78e.png" alt="structure" width="800" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adapters&lt;/strong&gt; work as a bridge to the outside world, this is done through external functions or developed interfaces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Services&lt;/strong&gt; are a similar construct used by the repository pattern often used by the backend to build a superficial and literal layer between code and database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entities&lt;/strong&gt; are interfaces and literal representations of the members of our application.&lt;/p&gt;

&lt;p&gt;Step two: &lt;strong&gt;Building an adapter&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;import axios from "axios";

const api = axios.create({
  baseURL: process.env.API_BASE,
});

export default api;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;center&gt;/adapters/api.ts&lt;/center&gt;
&lt;/blockquote&gt;

&lt;p&gt;The code above is very simple, we are just creating a new instance of axios and exporting it to the rest of the application.&lt;/p&gt;

&lt;p&gt;Third step: &lt;strong&gt;Assembling the entity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The entity is just a type with its respective attributes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export type TUser = {
  name: string;
  email: string;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;center&gt;/entities/user.ts&lt;/center&gt;
&lt;/blockquote&gt;

&lt;p&gt;Last step: &lt;strong&gt;Finally the services&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 registerUser = (user: TUser) =&amp;gt; {
  return api.post("api/user", user);
}

export const getUser = (id: number) =&amp;gt; {
  return api.get(`api/user/${id}`, user);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;center&gt;/services/user.ts&lt;/center&gt;

&lt;p&gt;Ui&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Our ui is composed of two inputs and a button with their respective data-testid&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;Input data-testid="inputName" /&amp;gt;
&amp;lt;Input data-testid="inputEmail" /&amp;gt;
&amp;lt;Button data-testid="submit" type="submit"&amp;gt;Save&amp;lt;/Button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Writing the tests&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First let's mock the service&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as user from "/services/user.ts";

jest.spyOn(user, "registerUser").mockImplementation(() =&amp;gt;
   Promise.resolve({
      message: "created"
   })
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The magic is in the code above, we are exporting the entire service file and telling spyOn to look at it as a function object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it("Must submit a new user", async () =&amp;gt; {
  const { getAllByTestId } = render(&amp;lt;User /&amp;gt;);

  const name = getAllByTestId("inputName")[0] as   HTMLInputElement;
  const email = getAllByTestId("inputEmail")[0] as HTMLInputElement;
  const submit = getAllByTestId("submit");

  fireEvent.change(email, { target: { value: "email@email.com" } });
  fireEvent.change(name, { target: { value: "Miguel" } });
  fireEvent.submit(submit);
  await waitFor(() =&amp;gt; 
        expect(user.registerUser).toHaveBeenCalledTimes(1));
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case we expect our form to call our registration function at least once.&lt;/p&gt;

&lt;p&gt;And we reached the end of the tests, the big point is in the import of the service that will be a mock. Take a good look at how the spy function works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ixrOz7Hq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/068j7du3ioxra0e5os4v.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ixrOz7Hq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/068j7du3ioxra0e5os4v.gif" alt="Naruto" width="500" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;Time is very important, thanks for sharing a little bit of yours with me 😊.&lt;/center&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X0Hgo7Mj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/badge/GitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image" width="92" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How and why to use infer in typescript</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Wed, 20 Oct 2021 09:28:54 +0000</pubDate>
      <link>https://dev.to/un4uthorized/how-and-why-to-use-infer-in-typescript-4e13</link>
      <guid>https://dev.to/un4uthorized/how-and-why-to-use-infer-in-typescript-4e13</guid>
      <description>&lt;p&gt;Hi everyone, how are you today? Hope you all are doing well!&lt;/p&gt;

&lt;p&gt;Today I'm going to explain how hell works and why it's important in conditional structures in typescript. Initially the concept is relatively simple, but the implementation makes us question its real reason for use.&lt;/p&gt;

&lt;p&gt;First, it is important to note that the use of hell is directly related to ternary conditions in the typescript. But why?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oTL7m2jd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ui20ndop35pztuakxg6i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oTL7m2jd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ui20ndop35pztuakxg6i.png" alt="Infer Theory" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we can infer T, G will be the result, if not, F will be the result&lt;/p&gt;

&lt;p&gt;The purpose of inference is to test whether an inference is possible, see the example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wFhV3ARf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjur5xfwzt3f50ugjm92.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wFhV3ARf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjur5xfwzt3f50ugjm92.png" alt="Example 01" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It turns out that when we use our custom type we will have never as an answer when trying to infer an object with no return.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YmH9SKA8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1qaestwqlurempbclyt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YmH9SKA8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1qaestwqlurempbclyt.png" alt="Example 02" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take one more example, if S cannot infer in the sentence pattern it will return never.&lt;/p&gt;

&lt;p&gt;There is great power when using inference in conjunction with generics and conditional structures in typescript. They are very useful when in recursive conditional structures in typescript.&lt;/p&gt;

&lt;p&gt;I tried to show you real use cases from hell and maybe you don't get the theory at first, but if you have any questions just send me a message and I'll be happy to answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ixrOz7Hq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/068j7du3ioxra0e5os4v.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ixrOz7Hq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/068j7du3ioxra0e5os4v.gif" alt="Naruto" width="500" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;Time is very important, thanks for sharing a little bit of yours with me 😊.&lt;/center&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X0Hgo7Mj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/badge/GitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image" width="92" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/_devneto"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bpeFljpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/badge/LinkedIn-0077B5%3Fstyle%3Dfor-the-badge%26logo%3Dlinkedin%26logoColor%3Dwhite" alt="image" width="107" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How does pick work in typescript ⛏️</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Mon, 09 Aug 2021 02:09:39 +0000</pubDate>
      <link>https://dev.to/un4uthorized/how-does-pick-work-in-typescript-ach</link>
      <guid>https://dev.to/un4uthorized/how-does-pick-work-in-typescript-ach</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hi everyone&lt;/strong&gt;, how are you today? Hope you all are doing well!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JrriqD4k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tox757fyljf2vbycaslb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JrriqD4k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tox757fyljf2vbycaslb.gif" alt="Rick and Morty" width="480" height="241"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h4&gt;
  
  
  Preface
&lt;/h4&gt;

&lt;p&gt;Today we are going to understand how the pick utility works and how it is built!&lt;/p&gt;



&lt;h4&gt;
  
  
  Concepts
&lt;/h4&gt;

&lt;p&gt;First, it is important to understand that the&lt;br&gt;
&lt;strong&gt;Typescript&lt;/strong&gt; is considered a&lt;br&gt;
superset of Javascript, is responsible for adding static type definitions.&lt;/p&gt;

&lt;p&gt;Types provide a way to describe the shape of objects, allowing TypeScript to verify that the code is working correctly.&lt;/p&gt;



&lt;h4&gt;
  
  
  To work
&lt;/h4&gt;

&lt;p&gt;The pick utility builds a new type based on the set of properties chosen in the second generic position.See an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Water = {
  hydrogen: number;
  oxygen: number;
};

type Electrolysis = Pick&amp;lt;Water, "hydrogen"&amp;gt;;

const electrolysis: Electrolysis = {
  hydrogen: 2,
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we are extracting hydrogen from the water type to create a new type, in this case electrolysis&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This produces an exothermic reaction. In the case of hydrogen and oxygen, the energy released is almost impossible to control, and most often leads to an explosion.&lt;/em&gt; &lt;/p&gt;



&lt;h4&gt;
  
  
  But how does the pick do it?
&lt;/h4&gt;

&lt;p&gt;First, we must understand what mapping functions are.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A mapped type is a generic type that uses a union of key properties to iterate through keys to create a new type.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;See an example: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HlTl4MUW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vg83l3bohha1eqaq0u0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HlTl4MUW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vg83l3bohha1eqaq0u0.png" alt="example" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;P will interact about id and name. T[P] returns the readonly type of iterated position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;keyof&lt;/strong&gt; produces a string or numeric literal union of keys of type. &lt;/p&gt;



&lt;h4&gt;
  
  
  Deconstructing the pick utility
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pa3-LzJK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i72wgjoxhft0kdnpxfev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pa3-LzJK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i72wgjoxhft0kdnpxfev.png" alt="Pick" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case we use a generic to capture the keys we want and restrict with extends, after that we use the mapping function to traverse all K (parameters passed to generic)!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XS99lqWk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9psqiuvagm57g4iit0y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XS99lqWk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9psqiuvagm57g4iit0y.gif" alt="happy face" width="470" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;this is magic!&lt;/center&gt;




&lt;center&gt;Time is very important, thanks for sharing a little bit of yours with me 😊.&lt;/center&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X0Hgo7Mj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/badge/GitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image" width="92" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/_devneto"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6ibmId_t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/badge/Twitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="image" width="100" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>typescript</category>
      <category>algorithms</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to create a custom many to many relationship in TypeORM</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Tue, 03 Aug 2021 01:23:36 +0000</pubDate>
      <link>https://dev.to/un4uthorized/how-to-create-a-custom-many-to-many-relationship-in-typeorm-8go</link>
      <guid>https://dev.to/un4uthorized/how-to-create-a-custom-many-to-many-relationship-in-typeorm-8go</guid>
      <description>&lt;p&gt;&lt;b&gt;Hi guys&lt;/b&gt;, how are you today? I hope you are fine!&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%2Fx1086a6u7tctsi7chp6s.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%2Fx1086a6u7tctsi7chp6s.gif" alt="Big Hero Hug"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h4&gt;
  
  
  Preface
&lt;/h4&gt;

&lt;p&gt;&lt;b&gt;Many-to-many&lt;/b&gt; relationships are quite common when you're developing any kind of app, from food stores to large inventory.&lt;/p&gt;

&lt;p&gt;Most of the time this relationship is not simple and you need to add more information in the pivo table (table generated from the relationship). We will learn how to make this custom relationship using typeORM.&lt;/p&gt;



&lt;h4&gt;
  
  
  Concepts
&lt;/h4&gt;

&lt;p&gt;First of all let's review some concepts:&lt;/p&gt;

&lt;p&gt;The purpose of &lt;b&gt;typeORM&lt;/b&gt; is to support JavaScript features that help you develop any type of application that uses databases - from small applications with a few tables to large-scale enterprise applications with multiple databases.&lt;/p&gt;

&lt;p&gt;The many-to-many relationship infers that A can have many B and B can have many A. In other words, both sides can report a variety on the other side.&lt;/p&gt;



&lt;h4&gt;
  
  
  To work
&lt;/h4&gt;

&lt;p&gt;After all the initial configuration of typeORM, we need to generate the models and migrations.&lt;/p&gt;

&lt;p&gt;In this example, we will build heroes that can have different individualities.&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%2Fc3a6it0y33kmoai6mtfw.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%2Fc3a6it0y33kmoai6mtfw.gif" alt="Midoriya,boku no hero"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can create &lt;b&gt;models&lt;/b&gt; with the following command:&lt;/p&gt;

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

typeorm  entity:create -n Hero


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our hero will have a name and skills. Put this in your model:&lt;/p&gt;

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


@Entity("heros")
class Hero {
  @PrimaryGeneratedColumn("increment")
  id: number;

  @Column({ length: 30 })
  name: string;

  @ManyToMany(() =&amp;gt; Skill)
  @JoinTable({
    name: "hero_skills",
  })
  skills: Skill[];
}

export default Hero;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;center&gt;src/models/Hero.ts&lt;/center&gt;



&lt;p&gt;and...&lt;/p&gt;

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

typeorm  entity:create -n Skill


&lt;/code&gt;&lt;/pre&gt;

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

@Entity("skills")
class Skill {
  @PrimaryGeneratedColumn("increment")
  id: number;

  @Column()
  skill: string;
}

export default Skill;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;center&gt;src/models/Skill.ts&lt;/center&gt;



&lt;p&gt;&lt;b&gt;And here comes the magic, let's create a model to reference the relationship!&lt;/b&gt;&lt;/p&gt;

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

typeorm  entity:create -n HeroSkills


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And inside let's put:&lt;/p&gt;

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

@Entity("hero_skills")
class HeroSkills {

  @Column({ type: "text" })
  description: string;

  @Column({ type: "int" })
  episode: number;

  @PrimaryColumn({ type: "int" })
  skills_id: number;

  @PrimaryColumn({ type: "int" })
  heros_id: number;

  @OneToOne(() =&amp;gt; Hero)
  @JoinTable()
  hero: Hero;

  @OneToOne(() =&amp;gt; Skill)
  @JoinTable()
  skill: Skill;
}

export default HeroSkills;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;center&gt;src/models/HeroSkills.ts&lt;/center&gt;



&lt;p&gt;In this case, we'll show you when a hero first demonstrated his individuality and what he looks like.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Let's do migrations now&lt;/b&gt;&lt;/p&gt;

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

typeorm migration:create -n CreateHeroTable


&lt;/code&gt;&lt;/pre&gt;

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

...
  public async up(queryRunner: QueryRunner): Promise&amp;lt;void&amp;gt; {
    await queryRunner.createTable(
      new Table({
        name: "heros",
        columns: [
          {
            name: "id",
            type: "int",
            isPrimary: true,
            generationStrategy: "increment",
          },
          {
            name: "name",
            type: "varchar",          
          },
          {
            name: "skills_id",
            type: "int",          
          },
        ],
        foreignKeys: [
          {
            name: "Skills",
            referencedTableName: "skills",
            referencedColumnNames: ["id"],
            columnNames: ["skills_id"],
            onDelete: "CASCADE",
            onUpdate: "CASCADE",
          },
        ],
      })
    );
  }
...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;center&gt;src/database/migrations/&lt;time&gt;CreateHeroTable.ts&lt;/time&gt;
&lt;/center&gt;



&lt;p&gt;Note that the foreign key relationship is explicit.&lt;/p&gt;

&lt;p&gt;*In the case of a many-to-many relationship, it does not matter in which table the relationship will be explicit, as long as the relationship exists&lt;/p&gt;

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

....
  public async up(queryRunner: QueryRunner): Promise&amp;lt;void&amp;gt; {
    await queryRunner.createTable(
      new Table({
        name: "skills",
        columns: [
          {
            name: "id",
            type: "int",
            isPrimary: true,
            generationStrategy: "increment",
          },
          {
            name: "skill",
            type: "varchar",
          },
        ],
      })
    );
  }
...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;center&gt;src/database/migrations/&lt;time&gt;CreateSkillsTable.ts&lt;/time&gt;
&lt;/center&gt;



&lt;p&gt;Now let's go to the relational migration:&lt;/p&gt;

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

typeorm migration:create -n CreateHeroSkillsTable


&lt;/code&gt;&lt;/pre&gt;

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

...
 await queryRunner.createTable(
      new Table({
        name: "hero_skills",
        columns: [
          {
            name: "id",
            type: "int",
            isPrimary: true,
            generationStrategy: "increment",
          },
          {
            name: "description",
            type: "text",
          },
          {
            name: "episode",
            type: "int",
          },
          {
            name: "heros_id",
            type: "int",
          },
          {
            name: "skills_id",
            type: "int",
          },
        ],
        foreignKeys: [
          {
            name: "Hero",
            referencedTableName: "heros",
            referencedColumnNames: ["id"],
            columnNames: ["heros_id"],
            onDelete: "CASCADE",
            onUpdate: "CASCADE",
          },
          {
            name: "Skill",
            referencedTableName: "skills",
            referencedColumnNames: ["id"],
            columnNames: ["skills_id"],
            onDelete: "CASCADE",
            onUpdate: "CASCADE",
          },
        ],
      })
    );
...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And finally run:&lt;/p&gt;

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

typeorm migration:run


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If all goes well, all tables will be created with their respective relationships!&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%2F7g15kqlc5n5m72zm5ara.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%2F7g15kqlc5n5m72zm5ara.gif" alt="All might congrats"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;Time is very important, thanks for sharing a little bit of yours with me 😊.&lt;/center&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/_devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FTwitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>beginners</category>
      <category>database</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Deploy your Vue aplication in less than 5 minutes.</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Mon, 05 Apr 2021 15:01:10 +0000</pubDate>
      <link>https://dev.to/un4uthorized/deploy-your-vue-aplication-in-less-than-5-minutes-3g8j</link>
      <guid>https://dev.to/un4uthorized/deploy-your-vue-aplication-in-less-than-5-minutes-3g8j</guid>
      <description>&lt;h1&gt;
  
  
  Begin
&lt;/h1&gt;

&lt;p&gt;Hey guys, performing a deploy tends to be a task commonly portrayed as problematic. Based on that, I wrote this article teaching how to do the same without major complications and in a short time.&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%2Fu48rtb8q9sytq6jqs3ch.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%2Fu48rtb8q9sytq6jqs3ch.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First of all it is important that you have an account at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.heroku.com" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;h3&gt;
  
  
  Starting with git.
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This article takes into account that you already have an instantiated vue project and just wanted to deploy it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Create an empty Git repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After creating the project repository, we will create a connection between it and our local project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote add origin https://github.com/user/repo.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your project, create the &lt;code&gt;static.json&lt;/code&gt; file with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "root": "dist",
    "clean_urls": true,
    "routes": {
      "/**": "index.html"
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change these lines in the &lt;code&gt;package.json&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;| change the line server to start&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "scripts": {
    "start": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit",
    "lint": "vue-cli-service lint"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that manages the build in the cli of your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;make sure you have removed the &lt;code&gt;/dist&lt;/code&gt; directory from your .gitignore file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;All set, let's upload our application to github with the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add .
$ git commit -m "build: heroku config"
$ git push 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Heroku config
&lt;/h3&gt;

&lt;p&gt;Create a app in heroku.&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%2F197828t8nbwumd0p8vrs.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%2F197828t8nbwumd0p8vrs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the github option and search for your project:&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%2Fej8gi6t0kaat62544n2e.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%2Fej8gi6t0kaat62544n2e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the settings tab, press add buildpacks and enter the url:&lt;code&gt;https://github.com/heroku/heroku-buildpack-static&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;b&gt;Buildpacks&lt;/b&gt; provide framework and runtime support for apps. Buildpacks typically examine your apps to determine what dependencies to download and how to configure the apps to communicate with bound services.&lt;/em&gt;&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%2F45fm8b5nomfsupivvlur.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%2F45fm8b5nomfsupivvlur.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lastly...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Set enable automatic deploys and deploy branch.&lt;/p&gt;

&lt;p&gt;If everything went well, the information that the deployment was successful will appear on your dashboard and your app will be ready for use.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Time is very important, thanks for sharing a little bit of yours with me 😊.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/_devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FTwitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>heroku</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Produtividade no front-end com a utilização de mocks.</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Fri, 02 Apr 2021 22:25:36 +0000</pubDate>
      <link>https://dev.to/un4uthorized/produtividade-com-a-utilizacao-de-mocks-3enc</link>
      <guid>https://dev.to/un4uthorized/produtividade-com-a-utilizacao-de-mocks-3enc</guid>
      <description>&lt;p&gt;Durante o processo de desenvolvimento de uma aplicação é provável que em algum momento você irá desejar realizar determinado teste de uma feature (funcionalidade do sistema que entrega um benefício ou resolve um problema) que ainda não foi desenvolvida pelo back-end do projeto. &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%2Flwleqb5728l2tffokwqh.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%2Flwleqb5728l2tffokwqh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Todo esse processo é pensado ignorando a utopia, onde a logística de um projeto funciona perfeitamente e as tarefas são distribuídas de forma que o desenvolvimento de todas as partes do mesmo ensamblem, porém o universo é entropia, portanto comumente são utilizados mocks para realizar esse teste de integração. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Mas o que é um mock?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Um mock é a abstração do comportamento de uma entidade que ele está representando.&lt;/b&gt; Baseado no comportamento citado acima, o comportamento pode representar o retorno de um api rest, uma vez que a mesma ainda não foi desenvolvida, mas pode-se considerar um padrão de retorno.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Como criar um mock?&lt;/b&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mockapi.io&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hodiernamente existem diversas técnicas e tecnologias para realizar a construção de uma abstração de um objeto. O &lt;a href="https://mockapi.io/" rel="noopener noreferrer"&gt;mockapi.io&lt;/a&gt; é um desses serviços que provem diversas funcionalidades para construção de um mock, entre elas está a geração de dados falsos para simular de forma semelhante informações reais.&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%2F92sn4xdzdypsdnqdbi8z.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%2F92sn4xdzdypsdnqdbi8z.png" alt="mockapi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Após toda configuração, o mockapi gera um endereço para vocês realizar os teste baseados em uma api rest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET https://6067732f98f405001728edf3.mockapi.io/users/
HTTP/1.1 200 OK
Server: Cowboy
Connection: keep-alive
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: X-Requested-With,Content-Type,Cache-Control,access_token
Content-Type: application/json
Content-Length: 5479
Etag: "-1074860086"
Vary: Accept-Encoding
Date: Fri, 02 Apr 2021 21:36:29 GMT
Via: 1.1 vegur

[{"id":"1","createdAt":"2021-04-02T16:50:39.873Z","name":"Rudolph Ryan","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/jacobbennett/128.jpg"},
{"id":"2","createdAt":"2021-04-02T02:42:21.504Z","name":"Alvera Predovic","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/paulfarino/128.jpg"},
{"id":"3","createdAt":"2021-04-01T23:53:59.741Z","name":"Jedediah Kirlin","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/vanchesz/128.jpg"},
{"id":"4","createdAt":"2021-04-02T01:43:26.824Z","name":"Twila McDermott Jr.","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/simobenso/128.jpg"},
{"id":"5","createdAt":"2021-04-02T17:12:51.473Z","name":"Eli Feil","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/rez___a/128.jpg"}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;O mockapi é extremamente competente no âmbito que se compromete a resolver os problemas, porém sua versão gratuita lhe permite a criação de apenas uma rota.&lt;/p&gt;



&lt;blockquote&gt;
&lt;p&gt;json-server&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Diferente do mockapi.io, o &lt;a href="https://www.npmjs.com/package/json-server" rel="noopener noreferrer"&gt;json-server&lt;/a&gt; é um pacote do npm que estimula a criação de um mock baseado em um arquivo json.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Utilizando:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;json-server --watch db.json&lt;/code&gt;&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%2Fv1nr73enigjt8qoqakth.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%2Fv1nr73enigjt8qoqakth.png" alt="json-server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Considerações&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Ambos os serviços são de suma importância caso você deseja solucionar os problemas citados acima. Espero de coração que esse artigo seja útil no seu âmbito profissional e pessoal. O tempo é muito importante, obrigado por compartilhar um pouco do seu comigo 😊.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/_un4me" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FTwitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;



</description>
      <category>javascript</category>
      <category>programming</category>
      <category>productivity</category>
      <category>performance</category>
    </item>
    <item>
      <title>The Guard Statement: Guard clause ou Early return.</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Mon, 18 Jan 2021 20:46:06 +0000</pubDate>
      <link>https://dev.to/un4uthorized/the-guard-statement-guard-clause-ou-early-return-54li</link>
      <guid>https://dev.to/un4uthorized/the-guard-statement-guard-clause-ou-early-return-54li</guid>
      <description>&lt;p&gt;Estruturas condicionais são sem duvida um dos assuntos mais importantes no âmbito computacional, indiferentemente do nível ou paradigma empregado. Apesar de possuir uma grande responsabilidade no desenvolvimento de aplicações, a utilização de profusas estruturas condicionais pode  comprometer a legibilidade do código e aumentar a carga cognitiva do desenvolvedor responsável.&lt;br&gt;&lt;br&gt;
&lt;br&gt; &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%2Fi%2Faofw6zc86amnhn3fp3ht.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%2Fi%2Faofw6zc86amnhn3fp3ht.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;"Decisões são importantes."&lt;/center&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;b&gt;O que é Guard Clause?&lt;/b&gt; 🤔&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Guard clause ou Early return são termos utilizados ao arquitetarmos uma estrutura sequencial de código condicional, normalmente reconhecido como pré condição.&lt;/p&gt;

&lt;p&gt;Comumente podemos construir Guard clauses respeitando 3 padrões:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Processa os parâmetros e retorna caso algum deles não respeite nossa regra de negócio;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verifica o estado de um objeto e retorna um valor, sujeitado-se ao estado passado;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Elimina casos triviais.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;center&gt;Esses padrões são baseados na filosofia de "&lt;b&gt;Handle errors in the same place where you detected them(Trate os erros no mesmo local onde os detectou).&lt;/b&gt;"&lt;/center&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;b&gt;Como desenvolver um Guard Clause? 🧑🏻‍💻 &lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Imagine um cenário em que estamos construindo uma batalha medieval e nosso guerreiro precisar lutar, porem para lutar nosso guerreiro precisa de determinados requisitos.&lt;/p&gt;

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

const getWarriorStatus = ({status}) =&amp;gt; {
  let responseWarrior;
  if (status.stamina &amp;lt; 10){
    responseWarrior = isExhausted();
  }
  else {
    if (!status.equipped){
      responseWarrior = equip();
    }
    else {
      if (!status.blessed){
        responseWarrior = toBless();
      }
      else{
        responseWarrior = battle();
      }
    }
  }
  return responseWarrior;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Olhando o código assim podemos concluir que o mesmo não se torna escalável caso o guerreiro comece a conquistar novo atributos.&lt;/p&gt;

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

const getWarriorStatus = ({status}) =&amp;gt; {
  if (status.stamina &amp;lt; 10){
    return isExhausted();
  }
  if (!status.equipped){
    return equip();
  }
  if (!status.blessed){
    return toBless();
  }
  return battle();
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Aplicando os conceitos de &lt;b&gt;Guard Clause&lt;/b&gt; conseguimos transformar o código outrora obsoleto em um produto agradável e escalável.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Obrigado por me deixar fazer parte do seu tempo! 🥰&lt;/b&gt;&lt;/p&gt;




&lt;p&gt;&lt;b&gt;Referências: &lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://wiki.c2.com/?GuardClause" rel="noopener noreferrer"&gt;https://wiki.c2.com/?GuardClause&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.eastof8thstreet.com/art-of-mouse-guard" rel="noopener noreferrer"&gt;http://www.eastof8thstreet.com/art-of-mouse-guard&lt;/a&gt; (art)

&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://github.com/devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.instagram.com/dev.neto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FInstagram-E4405F%3Fstyle%3Dfor-the-badge%26logo%3Dinstagram%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/https_rabbit" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FTwitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>computerscience</category>
      <category>writing</category>
    </item>
    <item>
      <title>Vue composition api: Guia prático para alquimistas.</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Wed, 30 Dec 2020 00:09:21 +0000</pubDate>
      <link>https://dev.to/un4uthorized/parte-01-vue-composition-api-guia-pratico-para-alquimistas-ic2</link>
      <guid>https://dev.to/un4uthorized/parte-01-vue-composition-api-guia-pratico-para-alquimistas-ic2</guid>
      <description>&lt;p&gt;Bom dia, site.&lt;/p&gt;

&lt;p&gt;Hoje venho compartilhar um pouco do conhecimento adquirido nas ultimas semanas estudando a nova api do vue, a &lt;code&gt;VUE COMPOSITION API&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Sumário:&lt;/p&gt;

&lt;p&gt;1. Introdução: Boas vindas, jovem mago;&lt;br&gt;
2. Setup(): O cérebro do componente;&lt;br&gt;
2.1 JSX;&lt;br&gt;
2.2 Capturando Props;&lt;br&gt;
2.3 Context;&lt;br&gt;
3. Reatividade: A lei da Alquimia;&lt;br&gt;
3.1 Reactive;&lt;br&gt;
3.2 Ref;&lt;br&gt;
3.3 Reactive ou ref?;&lt;br&gt;
4. Computed: O watch que observa diferente;&lt;br&gt;
5. ReadOnly: Simple;&lt;br&gt;
6. Watch: O olhar sanguinário do vigia;&lt;br&gt;
7. Ciclos de vida;&lt;/p&gt;
&lt;h4&gt;
  
  
  Introdução, O problema dos mixins.
&lt;/h4&gt;

&lt;p&gt;&lt;b id="introducao"&gt;Boas vindas, jovem mago.&lt;/b&gt;&lt;br&gt;&lt;br&gt;
Primeiramente deve-se entender o processo que ocasionou o desenvolvimento da composition api. Apesar das inúmeras features da segunda versão do vue, &lt;b&gt;o mesmo ainda possuía uma defasagem problemática em relação ao encapsulamento de código de forma performática utilizando mixins&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;É provável que o instanciamento de dois ou mais mixins não possam ser utilizados de forma isócrona, por exemplo, se ambos mixins utilizam o método foo(), o método será interrompido pois o método remanescente irá sobrescrever o precedentemente.&lt;/p&gt;

&lt;p&gt;Harmonizar centenas de funções em projetos que dependem de ser altamente escaláveis pode ser um grande problema, pois você deve refatorar o mixin e depois realizar o mesmo processo em todos os componentes que implementam o mesmo.&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%2Fi%2Faemdpn7bpmwqqri9lln6.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%2Fi%2Faemdpn7bpmwqqri9lln6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Esse é apenas um dos nêmesis que o composition api foi forjado para resolver, veremos mais nos próximos tópicos desse artigo. &lt;/p&gt;
&lt;h4&gt;
  
  
  Setup(): O cérebro do componente.
&lt;/h4&gt;

&lt;p&gt;Considere o método &lt;b id="setup"&gt;setup&lt;/b&gt; como o cérebro do componente, pois é a partir do mesmo que iremos definir os demais métodos e instanciaremos nossas variáveis, não ficou muito claro ainda, não é mesmo? Sem problemas, veja a imagem abaixo:&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%2Fi%2Fs6wp0787apzmvrw1l5l2.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%2Fi%2Fs6wp0787apzmvrw1l5l2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Considerando o tempo de execução da aplicação, o método setup() se encontra no ciclo &lt;code&gt;beforeCreate()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Observe que o objeto mage não é reativo, veremos mais sobre reatividade no próximo capitulo.&lt;/p&gt;

&lt;p&gt;Acessando as &lt;b id="props"&gt;props&lt;/b&gt; de um componente.&lt;/p&gt;

&lt;p&gt;Podemos acessar as propriedades de um componente através do primeiro parâmetro de do método setup:&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%2Fi%2Fl3rhqnk0izyb0f3rjivb.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%2Fi%2Fl3rhqnk0izyb0f3rjivb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;b&gt;Não force a desestruturação&lt;/b&gt; das propriedades pois você perderá a reatividade e receberá um erro no console e seu componente não será montado&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Para encerrar esse capítulo precisamos falar um pouco sobre o &lt;b id="context"&gt;context&lt;/b&gt;, que é o segundo parâmetro recebido por setup(), em suma, o context obtêm todo objeto de instancia previamente exibida pelo &lt;code&gt;this&lt;/code&gt; da segunda versão do vue. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;retorno fornecido pelo context:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;attrs: (...)
emit: (...)
expose: exposed =&amp;gt; {…}
props: (...)
slots: (...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uma vez que setup() é chamado antes do contexto, o &lt;code&gt;this como conhecemos não está disponível&lt;/code&gt;!&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;span id="reatividade"&gt;Reatividade: A lei da Alquimia.&lt;/span&gt;
&lt;/h4&gt;

&lt;p&gt;Considero essa a mudança mais considerável para a versão antecedente do vue, outrora, utilizávamos a propriedade &lt;code&gt;data&lt;/code&gt; como mecanismo de definição de valores reativos.&lt;/p&gt;

&lt;p&gt;Existem algumas formas de transformar uma variável comum, em uma variável reativa:&lt;/p&gt;

&lt;p&gt;Utilizando &lt;b id="reactive"&gt;reactive&lt;/b&gt; , pegamos um objeto e retornamos um proxy reativo do original.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { reactive } from 'vue'
  export default {
    setup() {
      const mage = reactive({
        type: 'fire',
        strong: 8
      })

      const changeTypeOfMage = () =&amp;gt; mage.type = 'water'

      return {
        mage,
        changeTypeOfMage
      }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nota-se que retornamos o método que muda o type do nosso objeto mage, uma vez que o método será utilizado dentro do jsx, como observamos nos capítulos anteriores.&lt;/p&gt;

&lt;p&gt;Se você deseja transformar um tipo de dado primitivo em uma propriedade reativa, utilize o hook &lt;b id="ref"&gt;ref&lt;/b&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ref } from 'vue'
  export default {
    setup() {
      let isMage = ref(true)
      const notMage = () =&amp;gt; isMage.value = !isMage.value;
      return {
        isMage,
        notMage
      }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;b id="reactiveorref"&gt;Quando usar reactive e quando usar ref?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Vamos para lei da alquimia geral, tenha pretensão de usar ref para tipos primitivos, como: String, Number, BigInt, Boolean, Symbol, Null e Undefined. Para objetos onde a teremos uma deep reactive, utilize reactive.&lt;/p&gt;

&lt;h4&gt;
  
  
  Computed: O watch que observa diferente.
&lt;/h4&gt;

&lt;p&gt;Assim como o &lt;b id="computed"&gt;computed&lt;/b&gt; da versão anterior, pense em uma variável que retorna uma função, a diferença dessa vez é que o computed do vue composition api retorna 2 métodos: o &lt;code&gt;get()&lt;/code&gt; que retorna uma função com o dado imutável e não reativo, e o método &lt;code&gt;set()&lt;/code&gt;, que consegue mutar essa regra e mudar os valores contidos no retorno do computed;&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;p&amp;gt;Name: {{mage.name}}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Type: {{mage.type}}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Strong: {{mage.strong}}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Status: {{status}}&amp;lt;/p&amp;gt;
  &amp;lt;button @click="enchant"&amp;gt;enchant armor&amp;lt;/button&amp;gt;
  &amp;lt;button @click="disenchant"&amp;gt;disenchant armor&amp;lt;/button&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
&amp;lt;template&amp;gt;
  &amp;lt;p&amp;gt;Name: {{mage.name}}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Type: {{mage.type}}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Strong: {{mage.strong}}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Status: {{status}}&amp;lt;/p&amp;gt;
  &amp;lt;button @click="enchant"&amp;gt;enchant armor&amp;lt;/button&amp;gt;
  &amp;lt;button @click="poison"&amp;gt;poison armor&amp;lt;/button&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
import { computed, reactive } from "vue";
export default {
  setup() {
    const mage = reactive({
      type: 'fire',
      strong: 4,
      name: 'Black Mage',
    })

    const status = computed({
      get: () =&amp;gt; mage.strong &amp;gt; 7 ? 'stronger' : 'weak',
      set: (value) =&amp;gt; mage.type = value
    })

    const enchant = () =&amp;gt; mage.strong = mage.strong + 4
    const poison = () =&amp;gt; {
      mage.strong = mage.strong - 4;
      status.value = 'poisoned'
    }

    return { mage, status, enchant, poison }
  },
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Observe o caso acima, declaramos um objeto inferindo que ele seja uma mago e que possua tais atributos, o computed está ali para observar o nível de força de nosso mago e mudar seu status caso ele se torne fraco ou forte, para pegar esse detalhe utilizamos seu método &lt;code&gt;get()&lt;/code&gt; como explicado acima, porem por default o status se torna imutável e não reativo, para isso utilizamos o &lt;code&gt;set()&lt;/code&gt; definido no computed para atribuir um novo status ao nosso mago. Ainda ficou com alguma dúvida? copie e execute o código, verá que na prática irá fazer mais sentido!&lt;/p&gt;

&lt;h4&gt;
  
  
  Readonly: Literalmente isso.
&lt;/h4&gt;

&lt;p&gt;O hook &lt;b id="readonly"&gt;readonly&lt;/b&gt; pega um objeto (reativo ou simples) ou um ref e retorna um proxy somente leitura para o original. Um proxy somente leitura: qualquer propriedade aninhada acessada também será somente leitura.&lt;/p&gt;

&lt;h4&gt;
  
  
  Readonly: Watch: O olhar sanguinário do vigia.
&lt;/h4&gt;

&lt;p&gt;O &lt;b id="watch"&gt;&lt;code&gt;watchEffect&lt;/code&gt;&lt;/b&gt; é uma novidade também, porem com grandes poderes vem grandes responsabilidades, a utilização watcheffect pode ter N aplicação uma vez que ela se transforma qualquer dado inferido no setup como um dado observável.&lt;/p&gt;

&lt;p&gt;Considere o código construído no exemplo do computed, caso você queira observar a mudança constante do nível de força de nosso mago você adicionaria o código abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;watchEffect(() =&amp;gt; console.log(mage.strong));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Comumente ao ciclo de vida do componente, o watchEffect é desfeito toda vez que nosso componente morre.&lt;/p&gt;

&lt;h4&gt;
  
  
  Ciclos de vida.
&lt;/h4&gt;

&lt;p&gt;Apesar da mudança de alguns nomes, grande parte dos hooks ainda possuem suas respectivas funções, exceto o setup() e &lt;code&gt;dois novos hooks&lt;/code&gt;: &lt;code&gt;onRenderTracked&lt;/code&gt; e &lt;code&gt;onRenderTriggered&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Antigo&lt;/th&gt;
&lt;th&gt;Novo&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;beforeCreate&lt;/td&gt;
&lt;td&gt;setup()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;created&lt;/td&gt;
&lt;td&gt;setup()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;beforeMount&lt;/td&gt;
&lt;td&gt;onBeforeMount&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;mounted&lt;/td&gt;
&lt;td&gt;onMounted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;beforeUpdate&lt;/td&gt;
&lt;td&gt;onBeforeUpdate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;updated&lt;/td&gt;
&lt;td&gt;onUpdated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;beforeDestroy&lt;/td&gt;
&lt;td&gt;onBeforeUnmount&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;destroyed&lt;/td&gt;
&lt;td&gt;onUnmounted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;activated&lt;/td&gt;
&lt;td&gt;onActivated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;deactivated&lt;/td&gt;
&lt;td&gt;onDeactivated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;errorCaptured&lt;/td&gt;
&lt;td&gt;onErrorCaptured&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;-Como utilizar os hooks?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Mage = {
  setup() {
    onMounted(() =&amp;gt; {
      console.log('Drop!')
    })
    onUpdated(() =&amp;gt; {
      console.log('New Level!')
    })
    onUnmounted(() =&amp;gt; {
      console.log('Dead!')
    })
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Em minha concepção essa são as mudanças fundamentais realizadas na nova versão do vue, em breve postarei a parte 2 e nela irei explicar um pouco sobre injeção de dependência, vue3 com typescript, unity testes e alguns tips de reatividade.&lt;/p&gt;

&lt;p&gt;Obrigado por ler até aqui, o objetivo desse post é deixar a sintaxe e esclarecer alguns pontos sobre o vue composition api, não deixe de entrar em contato ou escrever um comentário caso eu tenha errado em algum momento.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PARTE 2: undefined&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.instagram.com/dev.neto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FInstagram-E4405F%3Fstyle%3Dfor-the-badge%26logo%3Dinstagram%26logoColor%3Dwhite" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>computerscience</category>
      <category>algorithms</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Como expor seu localhost para teste em um cenário de desenvolvimento.</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Sat, 19 Dec 2020 22:30:56 +0000</pubDate>
      <link>https://dev.to/un4uthorized/como-expor-seu-localhost-para-teste-em-um-cenario-de-desenvolvimento-2a03</link>
      <guid>https://dev.to/un4uthorized/como-expor-seu-localhost-para-teste-em-um-cenario-de-desenvolvimento-2a03</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Bom dia site,&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Venho hoje compartilhar uma ferramenta que outrora utilizava para outros fins acadêmicos e que hoje utilizo para compartilhar informações como minha equipe de desenvolvimento, como o preview de uma aplicação local ou o compartilhamento de um banco de dados através de uma api sem a realização prévia de um deploy.&lt;/p&gt;

&lt;p&gt;Isso tudo é possível através de uma ferramenta chamada &lt;strong&gt;&lt;a href="https://ngrok.com" rel="noopener noreferrer"&gt;ngrok&lt;/a&gt;&lt;/strong&gt;, o mesmo tem como finalidade criar proxy reverso que estabelece um túnel seguro de um localhost para um serviço da web, como a captura e analise de todo o tráfego no túnel para inspeção e reprodução.&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%2Fi%2Fp4nhi1plyuqbpnlqb5qs.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%2Fi%2Fp4nhi1plyuqbpnlqb5qs.png" alt="Alt Text" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Mas e o firewall?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Como o ngrok é baseado em tuneis, a conexão preliminar é feita sempre do lado do cliente criando uma conexão tcp, onde muitos soquetes lógicos são criados por meio de conexões de soquete físicas, essa técnica é chamada &lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Multiplexing" rel="noopener noreferrer"&gt;Multiplexing&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Como criar um túnel para minha aplicação?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Imagine o determinado cenário de uma pequena api com uma rota get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) =&amp;gt; {
  res.send('ngrok server!')
})

app.listen(port, () =&amp;gt; {
  console.log(`App listening at http://localhost:${port}`)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nota-se que nosso servidor está escutando a porta &lt;code&gt;3000&lt;/code&gt;, guarde essa informação pois ela é importante.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Bom, agora precisamos baixar o ngrok para realizar a exposição.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Let's start with alchemy&lt;/em&gt; 🧙🏽‍♂️&lt;/p&gt;

&lt;p&gt;Entre no site oficial da ferramenta &lt;strong&gt;&lt;a href="https://ngrok.com" rel="noopener noreferrer"&gt;ngrok&lt;/a&gt;&lt;/strong&gt; e crie uma conta, esse processo é bem simples uma vez que ela oferece suporte de inscrição pelo github e demais serviços.&lt;/p&gt;

&lt;p&gt;Após o registro, você deve estar vendo uma tela parecida com essa: &lt;br&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%2Fi%2Fg56n4c4vjra61zmtwgpg.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%2Fi%2Fg56n4c4vjra61zmtwgpg.png" alt="Alt Text" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Faça o download para seu ambiente de uso.&lt;/p&gt;

&lt;p&gt;Por padrão a ferramenta vem compactada e se você estiver usando linux pode realizar o processo de descompactação com o seguinte comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;unzip /path/to/ngrok.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Defina as permissões do arquivo com:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x ngrok
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e execute o mesmo com a hash disponível no seu perfil do site oficial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./ngrok authtoken _SUA_HASH_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Por fim, vamos realizar o processo de exposição com a ferramenta, como nossa aplicação está rodando na porta 3000 o processo terá que ser feito da seguinte maneira:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./ngrok http 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;E voilà.&lt;/p&gt;
&lt;/blockquote&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%2Fi%2F23rowc15jz2ijdfb83de.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%2Fi%2F23rowc15jz2ijdfb83de.png" alt="Alt Text" width="787" height="362"&gt;&lt;/a&gt;&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%2Fi%2Ft1azh0xqzxae2910gc5r.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%2Fi%2Ft1azh0xqzxae2910gc5r.png" alt="Alt Text" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Agora temos nosso servidor prontinho e exposto para toda web!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Considerações finais&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Esse é meu primeiro post aqui, desde já, peço desculpa caso tenha errado em algum momento. Estou aberto a criticas e podem me acompanhar ou bater uma prosa através das minhas redes sociais:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/devneto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-100000%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="image" width="95" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.instagram.com/dev.neto" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FInstagram-E4405F%3Fstyle%3Dfor-the-badge%26logo%3Dinstagram%26logoColor%3Dwhite" alt="image" width="123" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/https_rabbit" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FTwitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="image" width="83" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tooling</category>
      <category>productivity</category>
      <category>security</category>
    </item>
  </channel>
</rss>
