<?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: Htech</title>
    <description>The latest articles on DEV Community by Htech (@htech).</description>
    <link>https://dev.to/htech</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%2Forganization%2Fprofile_image%2F3611%2F7899d2b3-8200-42fb-b0ca-b36a292ce268.png</url>
      <title>DEV Community: Htech</title>
      <link>https://dev.to/htech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/htech"/>
    <language>en</language>
    <item>
      <title>Trabajando con registros privados</title>
      <dc:creator>Israel Olvera</dc:creator>
      <pubDate>Mon, 14 Mar 2022 19:30:05 +0000</pubDate>
      <link>https://dev.to/htech/trabajando-con-registros-privados-35i7</link>
      <guid>https://dev.to/htech/trabajando-con-registros-privados-35i7</guid>
      <description>&lt;p&gt;&lt;em&gt;El contenido presentado es orientado al ambiente de desarrollo con JS y TS, y hay una gran cantidad de recursos que pueden explicar este contenido, pero yo trataré de explicarlo de la forma más clara y sencilla que me sea posible. &lt;br&gt;&lt;br&gt; Claro está que también compartiré las cosas con las que me he encontrado y te daré la solución con un fundamento detrás para que no solo hagas copy/paste&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Los registros privados son muy comunes, en el entorno empresarial; cuando se requiere alojar múltiples módulos de uso interno, sin necesidad de pagar por el servicio organizacional de npm. También servicios de alojamiento de repositorios como Github y GitLab ofrecen la funcionalidad de tener esta característica.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contenidos
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Login

&lt;ul&gt;
&lt;li&gt;Login con 2FA activo&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Instalación&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Login
&lt;/h2&gt;

&lt;p&gt;&lt;a id="login"&gt;&lt;/a&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;El login es sencillo, recordemos que por defecto siempre se va a apuntar al registro público de &lt;a href="https://registry.npmjs.org"&gt;npm&lt;/a&gt;, entonces, para hacer el login basta con ejecutar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ó bien para apuntar a un registro privado:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm login &lt;span class="nt"&gt;--registry&lt;/span&gt; &amp;lt;dirección-del-registro&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cambiar la configuración del registro por defecto&lt;/strong&gt;, también es fácil:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm config &lt;span class="nb"&gt;set &lt;/span&gt;registry &amp;lt;dirección-del-registro&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;con esta modificación se puede ejecutar &lt;em&gt;&lt;strong&gt;npm login&lt;/strong&gt;&lt;/em&gt; y el login será directo a la dirección del registro que se asignó&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTA: Esta configuración solo será aplicada de forma "local", pero para que las modificaciones tomen efecto para todo el sistema recuerda usar la bandera &lt;strong&gt;&lt;em&gt;--global&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Login con 2FA activo
&lt;/h3&gt;

&lt;p&gt;&lt;a id="login2fa"&gt;&lt;/a&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cuando se hace uso del Two-Factor Authentication (2FA), se requiere un token para poder hacer un login "exitoso". Si se realiza un login sin el token y se trata de instalar alguna dependencia organizacional o de un repositorio privado; la instalación fallará.&lt;/p&gt;

&lt;p&gt;Para lograr realizar la instalación se tiene que realizar lo siguiente:&lt;/p&gt;

&lt;p&gt;1.- Ejecutar: &lt;strong&gt;&lt;code&gt;npm login&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
2.- Obtener el token que se ha creado&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Este token se genera automáticamente, se encuentra en el archivo .npmrc ubicado en el directorio $HOME &lt;br&gt;&lt;br&gt; En Windows es: C:/Users/ y en Linux, si soy sincero, no lo recuerdo y no quiero obtener la respuesta de google; quiero reforzar un poco la memoria. Pero puedes obtener la ruta del directorio con $HOME. &lt;br&gt;&lt;br&gt; El token es la cadena de texto dentro de las comillas después de &lt;strong&gt;&lt;em&gt;:authToken=&lt;/em&gt;&lt;/strong&gt;, este a su vez deberá corresponder de la dirección del registro a la cual está asignada.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.- Volver a ejecutar el login pero agregando el token al final de la siguiente forma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm login &lt;span class="nt"&gt;--registry&lt;/span&gt; &amp;lt;dirección-del-registro&amp;gt;/:_authToken&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.- Volver a tratar de instalar las dependencias&lt;/p&gt;

&lt;h2&gt;
  
  
  Instalación
&lt;/h2&gt;

&lt;p&gt;&lt;a id="installation"&gt;&lt;/a&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cuando se hace uso de los registros que proveen servicios como Gitlab, se requiere un token (con los permisos para acceder al registro), puedes encontrar más información en &lt;a href="https://docs.gitlab.com/ee/user/packages/package_registry/"&gt;Gitlab | Package Registry&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTA: El token para la instalación de dependencias &lt;strong&gt;no&lt;/strong&gt; es el mismo que el token que se requiere para hacer el login&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Es común que en los proyectos se llegue a ver un archivo .npmrc dentro del proyecto, con la configuración para poder conocer los scopes (alcances) de las dependencias que el proyecto requiere&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTA: Es IMPORTANTE que NUNCA, NUNCA, NUNCA se agreguen tokens o keys dentro de estos, por cuestiones de seguridad, es más conveniente que se usen variables de entorno para asignarlos.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Como se puede ver en &lt;a href="https://docs.gitlab.com/ee/user/packages/npm_registry/index.html#authenticate-with-a-ci-job-token"&gt;Gitlab&lt;/a&gt;, hay varias formas de identificar a los módulos/dependencias de un proyecto. En la documentación se centra en el CI/CD, pero se puede realizar a nivel instancia, como se expondrá en este articulo.&lt;/p&gt;

&lt;p&gt;Primero en el proyecto, debe de existir el fichero .npmrc, en el que se deberá identificar al registro del cual se obtendrán las dependencias, como por ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;@foo:registry&lt;span class="o"&gt;=&lt;/span&gt;https://gitlab.example.com/api/v4/packages/npm/
//gitlab.example.com/api/v4/packages/npm/:_authToken&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;TOKEN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;NOTA: Es importante que se mantenga la sección &lt;strong&gt;&lt;em&gt;${TOKEN}&lt;/em&gt;&lt;/strong&gt;, esto; tomará el valor de la variable que se indica entre las llaves&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ahora, deberás generar un &lt;a href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html"&gt;token&lt;/a&gt;, como ya se mencionó este token deberá tener permisos para poder acceder al registro.&lt;/p&gt;

&lt;p&gt;Este token puede ser usado como variable del entorno, si se ejecuta el siguiente comando:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Esto funcionará siempre en entornos *NIX, en sistemas Windows, en lo personal uso Git Bash pero desafortunadamente con esta ultima opción; esto no persiste en el entorno. En entornos Windows con sub kernel de linux, desconozco si funciona.&lt;/p&gt;

&lt;p&gt;Hecho esto, ya se podrán instalar las dependencias desde los registros privados.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Managing the state in Vue (responsibly)</title>
      <dc:creator>Jesús Escamilla</dc:creator>
      <pubDate>Thu, 02 Sep 2021 22:29:54 +0000</pubDate>
      <link>https://dev.to/htech/managing-the-state-in-vue-responsibly-2gp5</link>
      <guid>https://dev.to/htech/managing-the-state-in-vue-responsibly-2gp5</guid>
      <description>&lt;p&gt;Summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn different ways to manage state.&lt;/li&gt;
&lt;li&gt;Review some examples.&lt;/li&gt;
&lt;li&gt;Evolution.&lt;/li&gt;
&lt;li&gt;Recommend a good structure.&lt;/li&gt;
&lt;li&gt;Conclusions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this post, we will be covering the most common ways to manage state in a Vue app. I will share some of my personal experience and the evolution of our implementation in our workplace, which allows us to structure them depending on our objectives.&lt;/p&gt;

&lt;p&gt;Here we go!!!&lt;/p&gt;

&lt;h2&gt;
  
  
  A lot of different ways to manage state
&lt;/h2&gt;

&lt;p&gt;In summary, we can classify them in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local state inside component.&lt;/li&gt;
&lt;li&gt;Global state in the window object.&lt;/li&gt;
&lt;li&gt;Global state with vuex.&lt;/li&gt;
&lt;li&gt;Shared observables.&lt;/li&gt;
&lt;li&gt;Shared reactives.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;The examples are written for Vue 2 or Vue 3 and some code may be omitted, the objective is to specify the parts about state management. Of course I'm here to help you if something is unclear.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local state inside component
&lt;/h3&gt;

&lt;p&gt;Vue 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;updateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vue 3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;setLoading&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For both Vue versions the example is essentially the same, shown in two different ways. Basically a var updated by a method.&lt;/p&gt;

&lt;p&gt;That could be the simplest form of state management; you may consider that updating the variable directly is better, but I recommend using a method. Primarily because a method is better for understanding the objective and possible values (especially if you are using typescript).&lt;/p&gt;

&lt;p&gt;As a recommendation, try and maintain the most amount of data separated, in its own component, don't share data unless you truly need to.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global state in the window object
&lt;/h3&gt;

&lt;p&gt;Have you used something like this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spoiler, I wouldn't recommend doing this in this way for most cases because there are no controls in place. Although, in a simple app, it could be a fast way to share some high level data.&lt;/p&gt;

&lt;p&gt;Another popular use in Vue is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eventBus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll leave communication between components for another post, here we will talk within the context of state management.&lt;/p&gt;

&lt;p&gt;I've decided to include this here because I consider this a shortcut if you only need to share a small amount of data, as a method or an utility. Keep in mind that this is for small amounts of data, for larger amounts of data, please consider the following option:&lt;/p&gt;

&lt;h3&gt;
  
  
  Global state with vuex
&lt;/h3&gt;

&lt;p&gt;Now a general example for a posts vuex module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;types&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../mutation-types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;unreadedPosts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readed&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setLoading&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SET_LOADING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;loadPosts&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;LOAD_POSTS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SET_LOADING&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;LOAD_POSTS&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;getters&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mutations&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;And the Vue 2 component implementation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mapGetters&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapActions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;mapGetters&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;mapActions&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;loadPosts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;getPosts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPosts&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loadPosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see I added a basic api method to get posts and send them to the state.&lt;/p&gt;

&lt;p&gt;I commonly see people make the api request in the vuex action, I used to do it that way too, but now I highly recommend separating the concerns no matter how simple the code might seem to be. You'll thank me later, as the code gets larger.&lt;/p&gt;

&lt;p&gt;Also remember that executing an action, calling a mutation, updating a state and reading getters make up a beautiful cycle that you need to respect and keep as simple as possible.&lt;/p&gt;

&lt;p&gt;So, if you need a vuex, keep actions limited to (at most) validating the entrance of data, never asynchronous or unpredictable methods. Keeping mutations only to update the state and getters only to provide data or basic filtering/formatting.&lt;/p&gt;

&lt;p&gt;Finally, when exactly do you need vuex? Anytime you need to retrieve data that all the application needs, within different views and modules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shared observables
&lt;/h3&gt;

&lt;p&gt;As simple as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;A Vue observable exposes a reactive object that could be accessed and updated in different components such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sidenavState&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./sidenavState&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;isOpenSidenav&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sidenavState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setSidenavStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;sidenavState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's not a law, but I highly recommend reading the observable by a computed property (which becomes useful later if you need to listen to it by a watch) and updating by a method (remember the update methods I listed in the examples).&lt;/p&gt;

&lt;p&gt;The advantage here is that other components can read from the same observable and get updated with the same data.&lt;/p&gt;

&lt;p&gt;In principle it’s a simpler alternative to vuex, but without actions and mutations.&lt;/p&gt;

&lt;p&gt;In general, remember to add methods or computed properties to keep it manageable.&lt;/p&gt;

&lt;p&gt;Also, I recommend vue observables for small-medium things, like data shared between views in the same module, but with a data nesting or no direct relation that allows props/emits communication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shared reactives
&lt;/h3&gt;

&lt;p&gt;In Vue 3 composition api, the evolution of observables are here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;isMovile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setMovile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isMovile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nx"&gt;setMovile&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we keep them if the app is in mobile state, it can be used for taking responsive decisions or hiding/showing components.&lt;/p&gt;

&lt;p&gt;Finally, expose a method to update and, woah, a readonly helper to help us prevent someone from directly updating the state.&lt;/p&gt;

&lt;p&gt;That is the main advantage I see in comparison to observables. I really recommend exposing the state as a readonly and update by the methods I've described.&lt;/p&gt;

&lt;p&gt;I see a lot of potential in that structure and recommend it thoroughly for all application levels and replacement of observables if you're migrating from Vue 2 to Vue 3.&lt;/p&gt;

&lt;p&gt;An important recommendation I can give you is to not use only one state file, it's much better to divide them into single concerns and locate them in the corresponding app level (component, view, module or app).&lt;/p&gt;

&lt;p&gt;Also remember to keep exposed methods simple, never asynchronous, complex stuff or business logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evolution from vuex to reactives
&lt;/h2&gt;

&lt;p&gt;I started (like many others) with a flux styles strategy, coming from react and redux, in vue (2.x), with vuex as expected.&lt;/p&gt;

&lt;p&gt;Our projects started very small, so we used vuex for everything, what could go wrong?&lt;/p&gt;

&lt;p&gt;We were thinking in a lineal flow, where data is generated as the user progresses through to the final view. We considered 4 or 5 views, simple enough, one vuex module per view.&lt;/p&gt;

&lt;p&gt;All was well at first, but as new views were added, alternate flows, processes that came in and out of external sites (say goodbye to your saved state), it all became a nightmare to maintain.&lt;/p&gt;

&lt;p&gt;That is when we started exploring observables and even more recently reactives, introducing Vue 3 to our projects.&lt;/p&gt;

&lt;p&gt;We found that major cases really don't need much data to be shared globally so vuex was omitted in new projects. Now, Reactive stores have been introduced, they are simpler because they can be divided on each app level that requires it. Also because most data only needs to be in its respective component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structuring
&lt;/h2&gt;

&lt;p&gt;Now the best part, how to organize this? I propose a hierarchical way, so it can be easy to understand the scope of the state.&lt;/p&gt;

&lt;p&gt;This is not limited to one specific state management method, but I will recommend something for each level based on my experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Component
&lt;/h3&gt;

&lt;p&gt;Use internal data options, some refs or reactives. Data received by apis lives only in this component and is shared to others by props or events.&lt;/p&gt;

&lt;p&gt;If it is a big amount of data, it may be taken out to another file in the same folder level.&lt;/p&gt;

&lt;h3&gt;
  
  
  View/module
&lt;/h3&gt;

&lt;p&gt;This is similar to Component level, but, think of a view as a classic routed component, and a module as a more complex component (header, menus, etc.). So consider three more possible things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are more than two nesting levels.&lt;/li&gt;
&lt;li&gt;So many props are required for many sub components.&lt;/li&gt;
&lt;li&gt;Some get/set methods are required to share too.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using Observables or reactives in a specific file at the view/module level is a good option.&lt;/p&gt;

&lt;h3&gt;
  
  
  Between views/modules
&lt;/h3&gt;

&lt;p&gt;First of all, if we talk about sub-views or low-level modules, the escenario may be similar to the previous level. Here, we are talking mostly about first level views or modules, and between them we need to share state.&lt;/p&gt;

&lt;p&gt;Here, we use an app level shared state. It may be created with reactives or vuex modules but remember to organize based on objectives or entities, not in view names or module names (if this is the case, go back to previous level).&lt;/p&gt;

&lt;h3&gt;
  
  
  App
&lt;/h3&gt;

&lt;p&gt;If you got here, we can talk about data that is not related to any view, module, or component, like some authentication status, or user configurations may be.&lt;/p&gt;

&lt;p&gt;Reactives or Vuex are recommended but the main difference with previews level is, as you can imagine, that the state managed here is independent of all and, by definition, may be useful for each part of the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Top to down
&lt;/h2&gt;

&lt;p&gt;At this point you might say, if I have a state value in App level, I can access them in any component, but that is a bad idea. Going back to the hierarchical proposal, low level components must get data only from props.&lt;/p&gt;

&lt;p&gt;For example, a view component can access data from app level state and share it to children by props. This can be done easily and ensures that the children remain independent, no need to know more about higher levels, while making them more shareables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Vue reactives vs vuex
&lt;/h2&gt;

&lt;p&gt;I think a tool is only as strong as the user. So I wouldn’t say no to vuex. In our projects we found there are very limited cases to use it because the composition api utilities and a good structure as shown before give us a simpler and more maintainable way.&lt;/p&gt;

&lt;p&gt;If you do, in fact, need all the power and beauty of vuex, remember the previous recommendations.&lt;/p&gt;

&lt;p&gt;If you need simplicity and flexibility use the composition api reactive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Everything I’ve said can be  condensed as... the state is something you could have under control, organized, easy-breezy, or you could have a snowball running down hill, about to crush you.&lt;/p&gt;

&lt;p&gt;So remember to use the least global state possible, keep it only in its respective components and share it directly by props and events, while maintaining it in specific files within the required level.&lt;/p&gt;

&lt;p&gt;Update the state view specific methods to ensure data quality and don't attach low level components to higher levels without reason.&lt;/p&gt;

&lt;p&gt;I hope this will help you improve your project structure and keep in order your app state, so that you can have a happier life.&lt;/p&gt;

&lt;h3&gt;
  
  
  Follow us to get more posts about Vue soon.
&lt;/h3&gt;

</description>
      <category>vue</category>
      <category>vuex</category>
      <category>observables</category>
      <category>reactive</category>
    </item>
    <item>
      <title>Exploring vertical slices in dotnet core</title>
      <dc:creator>Mig Salazar</dc:creator>
      <pubDate>Fri, 05 Mar 2021 21:25:58 +0000</pubDate>
      <link>https://dev.to/htech/exploring-vertical-slices-in-dotnet-core-3mik</link>
      <guid>https://dev.to/htech/exploring-vertical-slices-in-dotnet-core-3mik</guid>
      <description>&lt;p&gt;Talking about software architecture is complex, often due to the technical aspects but largely due to the fact that there's no single answer, rarely conclusions and always depends on the context.&lt;/p&gt;

&lt;p&gt;Why it depends on the context? because it can contains a lot concerns; the strategy and business model, cost and time constraints, team capabilities and skills of each individual team-member, technologies/techniques and &lt;a href="https://en.wikipedia.org/wiki/No_Silver_Bullet" rel="noopener noreferrer"&gt;their accidental complexity&lt;/a&gt;, etc. So, our technical decisions might be biased by all of these things and will change our path toward desired state.&lt;/p&gt;

&lt;p&gt;The fact is, &lt;a href="https://en.wikipedia.org/wiki/Technical_debt" rel="noopener noreferrer"&gt;technical debt&lt;/a&gt; is inherent in software and this gives us enough reasons to look for answers and the best way to build software; even, when the reality &lt;a href="https://hennyportman.wordpress.com/2021/01/06/review-standish-group-chaos-2020-beyond-infinity/" rel="noopener noreferrer"&gt;can be quite painful&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our context
&lt;/h2&gt;

&lt;p&gt;Recently at HTech, we started a project that aims to manage the features of other software products. From a &lt;em&gt;digital product&lt;/em&gt; perspective, it could be categorized as a back-office software. For me, it represents a set of rules that acts as an interface of business rules from other products. Some considerations about our project are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The interface rules -inside of our back-office software- of a specific product, must be built by the team that knows the business rules that the specific product has. This means that one team should be able to add functionality without fear of impacting the functionality of another team.&lt;/li&gt;
&lt;li&gt;The team is variable depending on the their time and anyone could &lt;em&gt;select for development&lt;/em&gt; a jira-issue and work on it.&lt;/li&gt;
&lt;li&gt;From (1) and (2) it's likely that the work will be triggered in a bounded time, and there will be a lot of &lt;em&gt;commits&lt;/em&gt; of multiple teams at the same time. &lt;em&gt;&lt;a href="https://project-management.info/number-of-communication-channels-pmp-formula-calculator/" rel="noopener noreferrer"&gt;Communication channels complexity here?&lt;/a&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;The functionalities are clearly independent from others and also this tasks are generally feature oriented.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Software layers
&lt;/h1&gt;

&lt;p&gt;Generally, in the software architecture space, what we're looking for is an appropriate component segregation. The traditional way is separate the software in &lt;em&gt;layers&lt;/em&gt;, and we understand as "layer", as a segregation oriented to non-functional responsibilities; sometimes it's just in a logical and chaotic way; and at best, physical and orderly.&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%2F21ugoaw79brlrzvefm3a.jpg" 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%2F21ugoaw79brlrzvefm3a.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The real struggle and non-trivial thing about layered architecture, is &lt;em&gt;how&lt;/em&gt; this layers interact with each other. Some of the most popular software architecture approaches, and accepted in the community, are the concentric-like architectures. For example &lt;a href="https://alistair.cockburn.us/hexagonal-architecture/" rel="noopener noreferrer"&gt;hexagonal architecture&lt;/a&gt;, &lt;a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/" rel="noopener noreferrer"&gt;onion architecture&lt;/a&gt;, &lt;a href="https://www.dddcommunity.org/" rel="noopener noreferrer"&gt;domain driven design&lt;/a&gt;, &lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html" rel="noopener noreferrer"&gt;clean architecture&lt;/a&gt;, etcetera.&lt;/p&gt;

&lt;p&gt;Something that these approaches have in common is that all of these are trying to keep the core/business layer (a.k.a domain) independent of frameworks and isolated from the rest of the layers. My &lt;em&gt;mental representation&lt;/em&gt; of this looks like:&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%2Fm2y8m8b4yo9uiox3qqdg.jpg" 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%2Fm2y8m8b4yo9uiox3qqdg.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our backend, generally, we follow these approaches. Although I agree with this, it's true that for many contexts these approaches might not be suitable -or at least not from the beginning-. These architectures are usually complex by nature, they have rigid rules of &lt;a href="https://martinfowler.com/articles/injection.html" rel="noopener noreferrer"&gt;inversion of control&lt;/a&gt;, a lot of abstractions and in many cases they are unnecessary.&lt;/p&gt;

&lt;p&gt;My aim here isn't to break with the &lt;a href="https://en.wikipedia.org/wiki/Separation_of_concerns" rel="noopener noreferrer"&gt;&lt;em&gt;separation of concerns&lt;/em&gt;&lt;/a&gt; -and other benefits that these approaches bring us- but given the conditions of our context, such as the fact that the team could be constantly rotating in a bounded time, I am looking for a way to reduce the learning curve that the concentric architectures has. But, at the same time, without losing the notion of the fact that the domain must be pushed toward the center and keeping &lt;a href="https://martinfowler.com/bliki/UbiquitousLanguage.html" rel="noopener noreferrer"&gt;the ubiquitous language&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Vertical slices
&lt;/h1&gt;

&lt;p&gt;The first time I heard the "vertical-slices" term was &lt;a href="https://en.wikipedia.org/wiki/Vertical_slice" rel="noopener noreferrer"&gt;in the agile world&lt;/a&gt;; and recently, I had the opportunity to listen &lt;a href="https://www.youtube.com/watch?v=5kOzZz2vj2o" rel="noopener noreferrer"&gt;an online talk&lt;/a&gt; by Jimmy Bogard, who promotes an architecture oriented to vertical slices. Basically, his approach is in the following way:&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%2F3tet9a0m7dmic2d3xr4m.jpg" 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%2F3tet9a0m7dmic2d3xr4m.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way he describes this is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When adding or changing a feature in an application, I'm typically touching many different "layers" in an application. I'm changing the user interface, adding fields to models, modifying validation, and so on. &lt;strong&gt;Instead of coupling across a layer, we couple vertically along a slice. Minimize coupling between slices, and maximize coupling in a slice.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, We can assume that the separation by features can be done simply by organizing the code with the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;|-- src
|   |-- OurProject.csproj
|   |-- Program.cs
|   |-- appsettings.json
|   |-- Feature1
|   |   |-- Controllers
|   |   |-- Services
|   |   |-- Models
|   |-- Feature2
|   |   |-- Controllers
|   |   |-- Services
|   |   |-- Models
|   |-- SharedLogic
|   |   |-- Services
|   |   |-- Models
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the problem with this -and I have always seen with backend APIs- is that we tend to build a lot of &lt;a href="https://martinfowler.com/eaaCatalog/serviceLayer.html" rel="noopener noreferrer"&gt;application/domain services&lt;/a&gt;, something like this:&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%2F6kr0u8kfurpid63n4cg3.jpg" 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%2F6kr0u8kfurpid63n4cg3.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This leads us to build a kind of &lt;em&gt;main service&lt;/em&gt; that acts as an orchestrator in a typical procedural way; at other hand, this makes us lose notion of which service we need to use when adding new functionality and, even, where to physically locate that service. After a while it becomes chaotic, and indirectly causes, just to mention an example, that our domain entities become into &lt;a href="https://www.martinfowler.com/bliki/AnemicDomainModel.html" rel="noopener noreferrer"&gt;anemic domain models&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Given that, the need to have an intermediary that works as an orchestrator and avoid the use of domain and/or application services for this purpose. One way to solve this is through &lt;a href="https://refactoring.guru/design-patterns/mediator" rel="noopener noreferrer"&gt;the mediator pattern&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%2Frefactoring.guru%2Fimages%2Fpatterns%2Fcontent%2Fmediator%2Fmediator.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%2Frefactoring.guru%2Fimages%2Fpatterns%2Fcontent%2Fmediator%2Fmediator.png" alt="Image from refactoring.guru"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, we find &lt;a href="https://github.com/jbogard/MediatR" rel="noopener noreferrer"&gt;Mediatr&lt;/a&gt;, which is a library that implements the mediator pattern by decoupling the in-process sending of messages from handling messages. The approach, considering the organization by features, is given by the following way:&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%2Fn42zockmz9bcmhnrik4e.jpg" 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%2Fn42zockmz9bcmhnrik4e.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Walkthrough
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Register handlers
&lt;/h3&gt;

&lt;p&gt;First of all, assuming we are using ASP.NET Core and its built-in injection dependency pattern, we need to &lt;a href="https://github.com/jbogard/MediatR/wiki#aspnet-core" rel="noopener noreferrer"&gt;configure the Mediatr dependencies&lt;/a&gt; to register our handlers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;ConfigureServices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddMediatR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Handlers
&lt;/h3&gt;

&lt;p&gt;We can think that the Handlers acts -in some way- &lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html" rel="noopener noreferrer"&gt;as the Use Cases of clean architecture&lt;/a&gt;. This is the entry point of our feature, from a business logic perspectie. A brief example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GetBy&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Query&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IRequest&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Guid&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Handler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IRequestHandler&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CancellationToken&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// our logic here&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you notice, there are two nested classes: &lt;code&gt;Query&lt;/code&gt; and &lt;code&gt;Result&lt;/code&gt;. This two types are scoped under &lt;code&gt;GetBy&lt;/code&gt; static class in order to -logically- structure the &lt;em&gt;use case&lt;/em&gt; of our feature. That means, this isn't a generic input/output, this is only used in a specific case &lt;code&gt;GetBy&lt;/code&gt;. With this, the inputs and outputs of our API are easily to identify and gives us more evident the use of &lt;a href="https://martinfowler.com/bliki/CQRS.html" rel="noopener noreferrer"&gt;CQRS&lt;/a&gt; pattern -which by the way is &lt;a href="http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/" rel="noopener noreferrer"&gt;more like conceptual pattern rather than archiectural pattern&lt;/a&gt;-. &lt;/p&gt;

&lt;p&gt;But, What's CQRS?. From Greg Young's &lt;a href="http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/" rel="noopener noreferrer"&gt;post&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;CQRS is simply the creation of two objects where there was previously only one&lt;/em&gt;. The separation occurs based upon whether the methods are a command or a query (the same definition that is used by Meyer in Command and Query Separation, a command is any method that mutates state and a query is any method that returns a value).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are &lt;a href="https://github.com/BrighterCommand/Brighter" rel="noopener noreferrer"&gt;some other libraries&lt;/a&gt; to implement this, even &lt;a href="https://blogs.cuttingedge.it/steven/posts/2011/meanwhile-on-the-query-side-of-my-architecture/" rel="noopener noreferrer"&gt;from scratch&lt;/a&gt;, but at this time I'm using the same Mediatr library, implementing &lt;code&gt;IRquest&lt;/code&gt; and &lt;code&gt;IRequestHandler&lt;/code&gt; interfaces.&lt;/p&gt;

&lt;p&gt;These concerns (Querys/Commands, Handler and DTO's) can be written in the same file. However, I prefer &lt;em&gt;-but not for all cases-&lt;/em&gt; to separate each of these into single files, namespaced by &lt;code&gt;static partial class&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Refactoring our controllers
&lt;/h3&gt;

&lt;p&gt;Then, our controller methods will take the following form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// obvious code here omitted for brevity&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OurController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IMediator&lt;/span&gt; &lt;span class="n"&gt;mediator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_mediatr&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mediator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{id}"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GetBy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_mediatr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;HttpPost&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Command&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_mediatr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Take note that the goal here, is to turn the controller into a logic-agnostic component that just represent a set of input/outputs points for our api.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With this approach, each vertical slice can decide how to manage their request/response:&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%2Ft6rc07osyas03akfgl9e.jpg" 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%2Ft6rc07osyas03akfgl9e.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pushing the domain
&lt;/h3&gt;

&lt;p&gt;Under this organization, the important thing is to take care the growth of our Handlers. Is extremely important consider the capabilities of our team, to timely detect code-smells and push logic down into domain layer and out of Handlers. There are some code-smells that I consider are very likely to occur with this approach and we must bear in mind.&lt;/p&gt;

&lt;p&gt;For example, this bad smells in logic and/or behavioral code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large Class&lt;/li&gt;
&lt;li&gt;Long Method&lt;/li&gt;
&lt;li&gt;Duplicated Code&lt;/li&gt;
&lt;li&gt;Combinatorial Explosion&lt;/li&gt;
&lt;li&gt;Repeated Switches&lt;/li&gt;
&lt;li&gt;Feature Envy&lt;/li&gt;
&lt;li&gt;Conditional Complexity&lt;/li&gt;
&lt;li&gt;Inappropriate Intimacy&lt;/li&gt;
&lt;li&gt;Middle Man&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can use refactoring techniques that are &lt;a href="https://refactoring.com/" rel="noopener noreferrer"&gt;very well documented by Martin Fowler&lt;/a&gt;, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract Class&lt;/li&gt;
&lt;li&gt;Extract Subclass&lt;/li&gt;
&lt;li&gt;Extract Interface&lt;/li&gt;
&lt;li&gt;Extract Method&lt;/li&gt;
&lt;li&gt;Replace Method with Method Object&lt;/li&gt;
&lt;li&gt;Move Function&lt;/li&gt;
&lt;li&gt;Compose Method&lt;/li&gt;
&lt;li&gt;Inline function&lt;/li&gt;
&lt;li&gt;Replace parameter with Query&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eventually, if we're on the right way, the approach will take on a domain-centric style.&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%2Fu90xo2sfgfbqtamyvkni.jpg" 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%2Fu90xo2sfgfbqtamyvkni.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, we can organize our input and output rules through pipelines around the core. This &lt;a href="https://github.com/jbogard/MediatR/wiki/Behaviors" rel="noopener noreferrer"&gt;pipelines can be implemented&lt;/a&gt; with the same Mediatr library:&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%2Fzl6n0avedjime10lizdf.jpg" 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%2Fzl6n0avedjime10lizdf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  So...
&lt;/h3&gt;

&lt;p&gt;This approach will helps us, in addition to orchestrating certain logic, to be able to recognize what we must push to the domain or to external layers, without worrying at the beginning of our project. And, mainly, it can guide to the team to work on independent features without conflicts and minimize problems to identify how the architecture works.&lt;/p&gt;

&lt;p&gt;My aim with this is to experiment another approach to organize our code and try to measure in order to find if this really brings productivity to the team; but, without losing sight of SOLID principles, keeping technical debt out and promoting refactoring as a daily practice.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;[WIP] The complete demo of this post &lt;a href="https://github.com/migsalazar/vertialslice-demo" rel="noopener noreferrer"&gt;can be found here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>architecture</category>
      <category>verticalslices</category>
      <category>designpatterns</category>
    </item>
    <item>
      <title>Creating a Vue module with Rollup and Typescript</title>
      <dc:creator>Jesús Escamilla</dc:creator>
      <pubDate>Tue, 02 Feb 2021 20:08:57 +0000</pubDate>
      <link>https://dev.to/htech/creating-a-vue-module-with-rollup-and-typescript-4igb</link>
      <guid>https://dev.to/htech/creating-a-vue-module-with-rollup-and-typescript-4igb</guid>
      <description>&lt;p&gt;Summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install vue-sfc-rollup for scaffolding.&lt;/li&gt;
&lt;li&gt;Create a Vue2 module setting with typescript support.&lt;/li&gt;
&lt;li&gt;Run for internal development.&lt;/li&gt;
&lt;li&gt;Pack and install in other local project.&lt;/li&gt;
&lt;li&gt;Publish to NPM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post is about a step by step guid for creating a Vue2 module with Rollup and setting typescript support. Finally is explained the basis for running, installing and publishing.&lt;/p&gt;

&lt;h1&gt;
  
  
  We start with Rollup
&lt;/h1&gt;

&lt;p&gt;I found in rollup a great tool for creating npm modules. Is particulary easy to understend, no need so much configuration but it's open for add more extras depending of your needs.&lt;/p&gt;

&lt;p&gt;And... exists &lt;a href="https://www.npmjs.com/package/vue-sfc-rollup" rel="noopener noreferrer"&gt;vue-sfc-rollup&lt;/a&gt; a cli module for scaffolding Vue SFC components, it may be for one component or a library.&lt;/p&gt;

&lt;h3&gt;
  
  
  1 - Install it globally
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g vue-sfc-rollup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows to work the cli on any location.&lt;/p&gt;

&lt;h3&gt;
  
  
  2 - Go to your project's folder and run:
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;The wizard ask for some options as follows.&lt;/p&gt;

&lt;h3&gt;
  
  
  3 - Is Single component or Library?
&lt;/h3&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%2F9qwto13bmbdcljdte7yu.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%2F9qwto13bmbdcljdte7yu.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We select the second.&lt;/p&gt;

&lt;h3&gt;
  
  
  3 - What's the name?
&lt;/h3&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%2Frhroxzrjjmknkfaikgcd.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%2Frhroxzrjjmknkfaikgcd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4 - Prefer Javascript or Typescript?
&lt;/h3&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%2F2k208eq6cem6kc5qmf9c.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%2F2k208eq6cem6kc5qmf9c.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course we select the second now.&lt;/p&gt;

&lt;h3&gt;
  
  
  5 - And the location?
&lt;/h3&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%2F5i669q62mf5e8q8w78wq.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%2F5i669q62mf5e8q8w78wq.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember don't need to create the project folder at first, is created with this prompt.&lt;/p&gt;

&lt;p&gt;And that's all, wizard ends, go to your new module folder.&lt;/p&gt;

&lt;h1&gt;
  
  
  The module guts
&lt;/h1&gt;

&lt;p&gt;vue-sfc-rollup create for us this structure.&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%2F66ldy35yeablze5ep6d8.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%2F66ldy35yeablze5ep6d8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I explain a little each one by folder:&lt;/p&gt;

&lt;h3&gt;
  
  
  build
&lt;/h3&gt;

&lt;p&gt;Host the rollup configuration and nothing else.&lt;/p&gt;

&lt;h3&gt;
  
  
  dev
&lt;/h3&gt;

&lt;p&gt;Here you can do everything you need to see works the module before installing in other place. As you can see contains a basic component to import the library code.&lt;/p&gt;

&lt;h3&gt;
  
  
  src
&lt;/h3&gt;

&lt;p&gt;Of course has the real library code organized in lib-components subfolder.&lt;/p&gt;

&lt;p&gt;That &lt;b&gt;index.ts&lt;/b&gt; file is specific to englobe all library components.&lt;/p&gt;

&lt;p&gt;The entry.ts file is big important. It expose the library to rollup build process. Generaly you don't need to modify entry.ts except for expose another type of file. I use for exporting Non-vue utilities usualy.&lt;/p&gt;

&lt;p&gt;The rest of the files are some browser, babel and typescript config. Update depending of your needs.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install and Run
&lt;/h1&gt;

&lt;p&gt;The scaffolding create this without installing node modules. Run &lt;b&gt;npm install&lt;/b&gt; and &lt;b&gt;npm run serve&lt;/b&gt; then.&lt;/p&gt;

&lt;p&gt;Is created a local server on 8080 port by default. The current configuration validates typescript syntax here.&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%2F4wo48t1wfhgcto0rapsv.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%2F4wo48t1wfhgcto0rapsv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open the url you can see the default component example.&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%2Fluqll3zw34t1e8pf5pha.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%2Fluqll3zw34t1e8pf5pha.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Add more components
&lt;/h1&gt;

&lt;p&gt;Here was created a library starting with a default component but more could be added.&lt;/p&gt;

&lt;p&gt;Only remember to add into index.ts like following.&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%2Fq2def05vy843uggfcof4.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%2Fq2def05vy843uggfcof4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The presented syntax is so cool. You may change this but the objective is to import and export in one line.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using Typescript
&lt;/h1&gt;

&lt;p&gt;As shown in the example you can implement Typescript, and it's specially useful in this case for validating the common options into the component, I recomend to create the interfaces, classes and other structures in specific files.&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%2Fzl0m136j0nxbjg8b57ks.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%2Fzl0m136j0nxbjg8b57ks.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also the default example shows a particular syntax to get data from component state. I recommend to change in &lt;b&gt;tsconfig.ts&lt;/b&gt; settings the &lt;b&gt;noImplicitThis&lt;/b&gt; property to false because we ussualy don't need to validate "this" in Vue with options api.&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%2F4qt1ye2txmm0o723hsoq.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%2F4qt1ye2txmm0o723hsoq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now simplificate the component as next.&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%2F96u6i73v3lw9cz1y5esg.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%2F96u6i73v3lw9cz1y5esg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is not the intention to create a complex library, that's for other post. So now go to local installation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Packing in a box
&lt;/h1&gt;

&lt;p&gt;Seeing the package.json, it has some commands to build the library in the dist folder depending of the distribution way.&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%2Fyfpxjxr2pfdc60hghgiv.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%2Fyfpxjxr2pfdc60hghgiv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;build:ssr, For Server Side Rendering.&lt;/li&gt;
&lt;li&gt;build:es, Build as Ecma Script module, this is usualy what we want on a common Vue/Spa project.&lt;/li&gt;
&lt;li&gt;build:unpkg, Use this if need to link directly in browser, by a CDN for example.&lt;/li&gt;
&lt;li&gt;build, You can use all of previews as one if preffered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also I recomend to add this script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"prepublish": "npm run build"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is becouse you need to create the bundles before publish (or pack if is the local scenario).&lt;/p&gt;

&lt;p&gt;Also in package json is found the configuration to set the correspondig entry point matching with distribution way. And the files to include into the packed module.&lt;/p&gt;

&lt;p&gt;As you can see the *d.ts file is include to provide typescript information about the library.&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%2Fdr6dlvn7uj6jwf66y45n.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%2Fdr6dlvn7uj6jwf66y45n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;b&gt;src&lt;/b&gt; folder may be not included except if you want to provide another way to import the components. With the bundles, the parent project only take care on implementing (if compatible). With the source code the parent project now need to asure to build correctly too, posiblelly you as library creator must know a little more about who will use your library in order to maintain compatibility.&lt;/p&gt;

&lt;p&gt;Finally we run &lt;b&gt;npm pack&lt;/b&gt;. This create a gziped file into the project (remember don't commit it).&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%2F07sm1uklke2w3raehqj8.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%2F07sm1uklke2w3raehqj8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to other project and install it pointing to the relative gziped file path.&lt;/p&gt;

&lt;p&gt;Each change you do in the source code, new pack and new install on to do, the pros of this is no need to update version neither expose uncompleted changes to public.&lt;/p&gt;

&lt;h1&gt;
  
  
  Publish to npm
&lt;/h1&gt;

&lt;p&gt;If it's ready, now publish to the public NPM repository or a private if case.&lt;/p&gt;

&lt;p&gt;Remember to login (&lt;b&gt;npm login&lt;/b&gt;) with your npm credentials&lt;/p&gt;

&lt;p&gt;Finally run &lt;b&gt;npm publish&lt;/b&gt;, keep calm and exhale too.&lt;/p&gt;

&lt;p&gt;As explained before the prepublish command runs before send to the repository.&lt;/p&gt;

&lt;p&gt;And it's over, now you have a Vue module made easy with rollup and well validated thanks to typescript.&lt;/p&gt;

&lt;p&gt;In the future we are going to create content to profundice on some areas about javascript, vue modules, and a something more.&lt;/p&gt;

&lt;p&gt;Thankyou for reading.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>rollup</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
