<?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: Martin Sotirov</title>
    <description>The latest articles on DEV Community by Martin Sotirov (@martinsotirov).</description>
    <link>https://dev.to/martinsotirov</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%2F185335%2F699254b9-3ff1-46ca-a7f2-3eaddd481f2a.jpeg</url>
      <title>DEV Community: Martin Sotirov</title>
      <link>https://dev.to/martinsotirov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/martinsotirov"/>
    <language>en</language>
    <item>
      <title>Vue 3 Composition API – The Wrong Solution To The Right Problem</title>
      <dc:creator>Martin Sotirov</dc:creator>
      <pubDate>Tue, 05 May 2020 10:25:25 +0000</pubDate>
      <link>https://dev.to/martinsotirov/vue-3-composition-api-the-wrong-solution-to-the-right-problem-1j6h</link>
      <guid>https://dev.to/martinsotirov/vue-3-composition-api-the-wrong-solution-to-the-right-problem-1j6h</guid>
      <description>&lt;h1&gt;
  
  
  Love at first Vue
&lt;/h1&gt;

&lt;p&gt;I was an early adopter of Vue.js in 2016, and my very first project with the framework was to port an existing Vue 1 app to the brand new Vue 2. As a React user I was skeptical at first. What I was seeing was a weird mixture of features “stolen” from all the major frontend frameworks.&lt;/p&gt;

&lt;p&gt;It took almost no time for me to permanently fall in love though.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This “weird mixture” seemed to represent the perfect balance between React’s flexibility, Angular’s structured modules and jQuery’s flat learning curve.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And from then on, I was an early evangelist for Vue. I did presentations on Vue at all the major JavaScript meetups in my area. I went to the Vue.js Amsterdam conference every year.&lt;/p&gt;

&lt;p&gt;I used Vue in all the projects where it made sense and in many where it was probably the wrong tool. I was even doing hybrid iOS apps with Cordova long before there were any solutions for Vue on mobile.&lt;/p&gt;

&lt;h1&gt;
  
  
  RFC shit storm
&lt;/h1&gt;

&lt;p&gt;Then in June 2019 came the &lt;a href="https://github.com/vuejs/rfcs/pull/42"&gt;RFC shit storm&lt;/a&gt; when the Composition API was &lt;del&gt;announced&lt;/del&gt; imposed.&lt;/p&gt;

&lt;p&gt;During the heated discussions on GitHub, Hacker News and Reddit I had a some rather unpleasant interactions with core team members where I and everyone else who was disagreeing were told that we need React style hooks because all the business logic &lt;strong&gt;must&lt;/strong&gt; be in components and they know best because it's their framework.&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;
      &lt;div class="ltag__twitter-tweet__media"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l4Xfbzrk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/D9489DAX4AAFk3F.jpg" alt="unknown tweet media content"&gt;
      &lt;/div&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--XkH67hDb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/803886637210075136/IvoS-l6__normal.jpg" alt="Martin Sotirov profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Martin Sotirov
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @unclemartycodes
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52oNvK_0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-ff4bdab814039c4cb172a35ea369e0ea9c6a4b59b631a293896ae195fa26a99d.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Sad to see the transition of my favorite &lt;a href="https://twitter.com/hashtag/FrontEnd"&gt;#FrontEnd&lt;/a&gt; framework &lt;a href="https://twitter.com/hashtag/VueJS"&gt;#VueJS&lt;/a&gt; to &lt;a href="https://twitter.com/hashtag/React"&gt;#React&lt;/a&gt; style hooks mishandled that badly. That's not how communication in an &lt;a href="https://twitter.com/hashtag/opensource"&gt;#opensource&lt;/a&gt; project should be. 
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      07:21 AM - 25 Jun 2019
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1143419046093889537" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1143419046093889537" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      0
      &lt;a href="https://twitter.com/intent/like?tweet_id=1143419046093889537" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      3
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Othv9wT_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/14b53s0ho3q2t9zk6n1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Othv9wT_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/14b53s0ho3q2t9zk6n1j.png" alt="GitHub Gist Comments"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the end, thanks to the huge developer outcry the initial plan to deprecate the old component syntax was abandoned, so v3 will still support the old Vue syntax we love. Yay!&lt;/p&gt;

&lt;h1&gt;
  
  
  The age-old problem of code reuse
&lt;/h1&gt;

&lt;p&gt;The Composition API came about as a solution to the age-old problem of &lt;strong&gt;code reuse&lt;/strong&gt; and &lt;strong&gt;encapsulation of business logic&lt;/strong&gt;. Multiple programming languages have been born as a solution to this problem and in fact the whole discipline of &lt;em&gt;Object Oriented Programming&lt;/em&gt; can be traced back to the dream of code reuse.&lt;/p&gt;

&lt;p&gt;That problem has already been solved, and just because suddenly it's OK to have CSS in our JavaScript files, it doesn't mean we have to completely throw out 30 years of programming knowledge and completely reinvent everything.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ygr9qfZQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5olpqs0flfjcqjpfmyct.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ygr9qfZQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5olpqs0flfjcqjpfmyct.jpg" alt="Design patterns books"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In fact, if you read &lt;a href="https://012.vuejs.org/guide/"&gt;old versions of the Vue.js docs&lt;/a&gt;, you will see that it is advertised as the ViewModel in the MVVM design pattern (or &lt;a href="https://martinfowler.com/eaaDev/uiArchs.html"&gt;MVP&lt;/a&gt; as Martin Fowler initially called it).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Technically, Vue.js is focused on the ViewModel layer of the MVVM pattern. It connects the View and the Model via two way data bindings.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reuse of the ViewModel was never a goal for MVVM frameworks though! Neither is the encapsulation of &lt;em&gt;"renderless"&lt;/em&gt; business logic not tied to a specific view. The ViewModel's sole job is to manage the state of a specific part of the app (a single &lt;em&gt;component&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Thankfully, there are still sane voices in the JavaScript community which sadly aren't heard loud enough.&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;
      &lt;div class="ltag__twitter-tweet__media"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6_1AyNnk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/DzYXRFqXcAAkrgL.jpg" alt="unknown tweet media content"&gt;
      &lt;/div&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--XkH67hDb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/803886637210075136/IvoS-l6__normal.jpg" alt="Martin Sotirov profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Martin Sotirov
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @unclemartycodes
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52oNvK_0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-ff4bdab814039c4cb172a35ea369e0ea9c6a4b59b631a293896ae195fa26a99d.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Amen! Someone had to say this today with everyone in &lt;a href="https://twitter.com/hashtag/VueJS"&gt;#VueJS&lt;/a&gt; and &lt;a href="https://twitter.com/hashtag/JavaScript"&gt;#JavaScript&lt;/a&gt; throwing &lt;a href="https://twitter.com/hashtag/DesignPatterns"&gt;#DesignPatterns&lt;/a&gt; and old coding best practices out the window.  Serverless this, renderless that, &lt;a href="https://twitter.com/hashtag/GraphQL"&gt;#GraphQL&lt;/a&gt; queries in the templates 😢 &lt;a href="https://twitter.com/jakecodes"&gt;@jakecodes&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/vuejsamsterdam"&gt;#vuejsamsterdam&lt;/a&gt; 
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      16:50 PM - 14 Feb 2019
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1096089185524596736" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1096089185524596736" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      3
      &lt;a href="https://twitter.com/intent/like?tweet_id=1096089185524596736" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      7
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;h1&gt;
  
  
  The wrong solution to the right problem
&lt;/h1&gt;

&lt;p&gt;Code reuse and encapsulation of business logic absolutely are valid problems but bending a technology focused on the view layer of an application to do additional things is not the right solution.&lt;/p&gt;

&lt;p&gt;The Composition API supposedly solves the problems with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mixins&lt;/li&gt;
&lt;li&gt;Renderless Components&lt;/li&gt;
&lt;li&gt;Higher Order Components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you absolutely must use some kind of component inheritance and breaking your components down or extracting common functionality in service classes is not an option, that means you are either structuring your app's architecture the wrong way or Vue.js simply isn't the right tool for the project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vue.js is not a silver bullet that's applicable in 100% of the use cases, and that's ok.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is simply unfortunate that when the Vue.js Core Team tried to solve the age-old problem of code reuse and business logic encapsulation, they decided to find inspiration in React rather than Angular.&lt;/p&gt;

&lt;p&gt;This, in my opinion, disrupts the very delicate balance Vue.js had between the diametrically opposed approaches of Angular and React, which is precisely what made Vue appealing to many of us in the first place.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
