<?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: Andrea </title>
    <description>The latest articles on DEV Community by Andrea  (@longoandrea).</description>
    <link>https://dev.to/longoandrea</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%2F514079%2F00f976fe-30df-4f73-aad7-0f9c0a64fa13.png</url>
      <title>DEV Community: Andrea </title>
      <link>https://dev.to/longoandrea</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/longoandrea"/>
    <language>en</language>
    <item>
      <title>Vue component's props quirks while working with TypeScript</title>
      <dc:creator>Andrea </dc:creator>
      <pubDate>Sat, 27 May 2023 14:23:46 +0000</pubDate>
      <link>https://dev.to/longoandrea/vue-components-props-quirks-while-working-with-typescript-5doo</link>
      <guid>https://dev.to/longoandrea/vue-components-props-quirks-while-working-with-typescript-5doo</guid>
      <description>&lt;p&gt;Vue and TypeScript, such a complicated relationship! 🤯&lt;/p&gt;

&lt;p&gt;A common pitfall comes while defining component's props, which are defined through a structure that provide a sort of "lightweight" type checking for props validation.&lt;/p&gt;

&lt;p&gt;This can generate some misunderstandings, it doesn't actually work as type checker, since those type checks and validators are runtime guards, this explains why the type property supports just the native objects (&lt;a href="https://vuejs.org/guide/components/props.html#runtime-type-checks"&gt;Runtime Type Checks&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's add TypeScript
&lt;/h2&gt;

&lt;p&gt;What I said above it doesn't change if you add TypeScript on the equation, those runtime validators still exists and required. So, maybe you might expect to write something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script setup&amp;gt;
type MyCustomType = 'Hello' | 'World'
const props = defineProps({
  myProps: {
    type: MyCustomType
  }
})
// ...
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above will results in:&lt;/p&gt;

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

&lt;p&gt;This happens because you're trying to mix runtime validations with static type checking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution 1
&lt;/h2&gt;

&lt;p&gt;You can fully rely on TypeScript checking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MyCustomType = 'Hello' | 'World'
const props = defineProps&amp;lt;{
    test: MyCustomType
}&amp;gt;()
// ...
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way you have solved the error, but you won't be able to provide custom validators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution 2
&lt;/h2&gt;

&lt;p&gt;Rely on type assertions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MyCustomType = 'Hello' | 'World'
const props = defineProps({
  myProps: {
    type: String as PropType&amp;lt;MyCustomType&amp;gt;
    validator: (value: MyCustomType) =&amp;gt; {
       // your custom validation
    },
  }
})
// ...
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;As shown above, Vue might seem a little bit tricky while working alongside TypeScript, though it has taken steps onward, and still does.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How does it work Vue2 reactivity system?</title>
      <dc:creator>Andrea </dc:creator>
      <pubDate>Sun, 21 Feb 2021 16:50:30 +0000</pubDate>
      <link>https://dev.to/longoandrea/how-does-it-work-vue2-reactivity-system-3afg</link>
      <guid>https://dev.to/longoandrea/how-does-it-work-vue2-reactivity-system-3afg</guid>
      <description>&lt;p&gt;Quite often, as developers, we tend to use many frameworks and libraries as a black box, without really understanding what's going on under the hood. And that is okay, in fact is great we can effectively work with a library without worrying about how it works.&lt;/p&gt;

&lt;p&gt;But though this concept of abstraction is important, understanding the basic concepts behind how a library/framework works is equally important. &lt;/p&gt;

&lt;p&gt;Here we'll see which are the basic concepts behind Vue2 reactivity system. Believe or not, there's nothing magical on it, you can achieve the same behavior with plain JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object.defineProperty() method
&lt;/h2&gt;

&lt;p&gt;The main responsible for reactivity is a static method in &lt;code&gt;Object&lt;/code&gt; class,  &lt;code&gt;defineProperty()&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This method was introduced by &lt;a href="https://it.wikipedia.org/wiki/ECMAScript"&gt;ES5&lt;/a&gt;, and allows us to add a new object property, or define a new one, the difference from a simple assignment is that you can define some more details about the property.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Object.defineProperty(obj, propertyName, descriptor)&lt;/code&gt; accepts three arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;obj&lt;/code&gt;, the object on which to define the property&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;propertyName&lt;/code&gt;, the name of the property to be defined or modified&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;descriptor&lt;/code&gt;, the descriptor for the property being defined or modified&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;obj&lt;/code&gt; and &lt;code&gt;propertyName&lt;/code&gt; should not require any further explanations,  instead &lt;code&gt;descriptor&lt;/code&gt; does.&lt;/p&gt;

&lt;p&gt;There are two types of descriptors: &lt;strong&gt;data descriptors&lt;/strong&gt; and &lt;strong&gt;accessor descriptor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Data descriptors are meant to define regular properties, so beyond the property value, you can define three additional flags: which define which actions are allowed on a specific object property.&lt;/p&gt;

&lt;p&gt;Accessor descriptor, are more interesting for our purpose. Such descriptor is defined by a getter/setter pair of functions, and supports the following flags: configurable and enumerable. Inside get/set the value of this is set to object through which the property is accessed.&lt;/p&gt;




&lt;p&gt;💡 You can dive deeper on how descriptor flags affect the property on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty"&gt;MDN&lt;/a&gt;.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How that can be useful for reactivity?
&lt;/h2&gt;

&lt;p&gt;You may asking how this &lt;code&gt;Object.defineProperty()&lt;/code&gt; might be useful for reactivity purpose, it's quite normal, with such simple example. So let me explain in words what is going on here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;get&lt;/strong&gt;, let you define a custom function to read a property, no big computation here... most of the times you'll simply return a  property's value&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;set&lt;/strong&gt;, let you define a custom functions to set a property... when you land here, two things are given for sure: the property's value has been changed and you can run whatever you want.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The set definition should have hint you something... &lt;/p&gt;

&lt;p&gt;Let's say we have a function, named &lt;strong&gt;renderFunction&lt;/strong&gt;, which automatically  retrieve the value of every needed property in order to render our templated HTML, then, every time a setter is accessed &lt;strong&gt;renderFunction&lt;/strong&gt; is called again, and performs the update of our document.&lt;/p&gt;

&lt;p&gt;That is the basic logic behind reactivity explained to a 5 years old kid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vue2 reactivity in concrete
&lt;/h2&gt;

&lt;p&gt;Okay, let' see an overview about how Vue2 use all this to make things reactive.&lt;/p&gt;

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

&lt;p&gt;Let's break the components of this diagram down.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VirtualDOM&lt;/strong&gt;, represents our document to be rendered, we don't need to understand how it works for the purpose&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component Render Function&lt;/strong&gt;, is the function responsible for update the VirtualDOM after every data changes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watcher&lt;/strong&gt;, is a core element for the component reactivity. It records all component's dependencies (all the properties involved during rendering process)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data,&lt;/strong&gt; is a property registered as dependency for the component, which has its own getter and setter (the ones we talked earlier)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's see the flow of the above diagram.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;First render:&lt;/strong&gt; if a data is accessed, its getter calls the component's watcher which register this data as a dependency. In this way every change on the property will run the code inside its setter function.&lt;/li&gt;
&lt;li&gt;The component render function &lt;strong&gt;perform the render&lt;/strong&gt; of the document. A lot more complexity is hidden behind this statement, but it's not the purpose of the article, so a definition like that it's fine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A data is updated&lt;/strong&gt; somewhere (no matters where), its setter notify all the watchers which include the data as dependency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-render is triggered&lt;/strong&gt; by the watcher and performed by render function.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;We have seen an overview of Vue2 reactivity system, its workflow, and how it takes advantage of the &lt;code&gt;Object.defineProperty()&lt;/code&gt; built-in method. Actually the same logic is behind a lot of modern libraries/frameworks, so take this article as a starting point to understand on your own how your favorite framework's reactivity works.&lt;/p&gt;

&lt;p&gt;Some useful resources to dive deeper in this topic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To better understand the &lt;code&gt;Object.defineProperty()&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://javascript.info/property-descriptors"&gt;Property flags and descriptors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/property-descriptors"&gt;Property getters and setters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty"&gt;Object.defineProperty()&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Understand the reactivity in Vue2:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.vuemastery.com/blog/Reactivity-Vue2-vs-Vue3/"&gt;Reactivity: Vue 2 vs Vue 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://deepsource.io/blog/reactivity-in-vue/"&gt;How Reactivity works in Vue.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://it.vuejs.org/v2/guide/reactivity.html"&gt;Reactivity in Depth&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


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

</description>
      <category>vue</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to get organized with Notion</title>
      <dc:creator>Andrea </dc:creator>
      <pubDate>Fri, 13 Nov 2020 21:14:31 +0000</pubDate>
      <link>https://dev.to/longoandrea/how-to-get-organized-with-notion-kh2</link>
      <guid>https://dev.to/longoandrea/how-to-get-organized-with-notion-kh2</guid>
      <description>&lt;h1&gt;
  
  
  What is Notion?
&lt;/h1&gt;

&lt;p&gt;Notion is an all-in-one workspace, which provides a tool to take notes, plan and get organized. It can be used either for personal use and team collaboration.&lt;/p&gt;

&lt;p&gt;Notion is quite simple to use, no high skills are required, you can use it as simple notes taking app or you can use it to plan things in your life and set reminders. Actually it can be seen as a white canvas which you can paint as you want. You can decide to start using it simple and the evolve based on your needs.&lt;/p&gt;

&lt;p&gt;The core elements in Notion are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blocks, everything in Notion is a block! With blocks you can build almost whatever you want from simple things like text, headers, lists, etc… until advanced stuff like databases, tables and more.&lt;/li&gt;
&lt;li&gt;Page, which is were the blocks are placed, and allow you to define your notebooks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing is definitive, for example you can transform a text block, or a database into a page!&lt;/p&gt;

&lt;p&gt;The possibilities is almost endless.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the main competitor of Notion?
&lt;/h1&gt;

&lt;p&gt;Evernote is one of the most popular note taking application, you can use it to take note, collect several type of resources: documents, images, etc…&lt;/p&gt;

&lt;p&gt;With Evernote you can create an entire system of notebooks and append tags to categorize your notes into topics.&lt;/p&gt;

&lt;p&gt;Evernote has its strengths:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it can rely on a wide community support&lt;/li&gt;
&lt;li&gt;integration with several apps like Google Drive, Gmail, Microsoft Teams, etc…&lt;/li&gt;
&lt;li&gt;useful feature like document scanning, web clipper, etc…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Evernote doing a great job as block notes, but it doesn't help to improve your productivity and its plans it pricey.&lt;/p&gt;

&lt;p&gt;With Notion you can do the same you can do with Evernote and more!&lt;/p&gt;

&lt;p&gt;Note that either Notion and Evernote are just tools, none of them two do magic! To get organized and improve your productivity you have to get a method to follow. Given that, you can choose the software which fit more your needs, even a paper notebook if you prefer!&lt;/p&gt;

&lt;h1&gt;
  
  
  What can you do with Notion?
&lt;/h1&gt;

&lt;p&gt;As said in a previously Notion comes without presets, at first it's a simple white page with no hints. It could be seems useless, but it isn't… That is a the strength of Notion, you can do whatever you want with no limits.&lt;/p&gt;

&lt;p&gt;If you don't know how to start, don't worry, start simple! Create some pages to use as notebooks, and put your notes inside. You can always add complexity and move your notes around the pages, nothing will be loss. So it isn't required to find the perfect setup at the first time.&lt;/p&gt;

&lt;p&gt;If you are searching ideas to use Notion, here some:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Journaling. You can set up a database (a table for example, you can add as many views as you want) to store your daily journal. It can be useful to create a standard template (yes you can define even templates) to have some commons properties between each day.&lt;/li&gt;
&lt;li&gt;Habit tracker. Same thing as Journaling, you can create a database of habits, and track the progress.
-Reading list, to keep track of all the books you've read and which you wish to read.&lt;/li&gt;
&lt;li&gt;Calendar. Notion provides even calendar, so you can schedule your tasks, view your due dates, set reminders.&lt;/li&gt;
&lt;li&gt;Life goals. You can set up a workspace to manage all life goals you are pursuing and plan how to reach them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These above are only some examples, but you can actually do whatever you want, so don't give yourself limits.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's get deeper
&lt;/h1&gt;

&lt;p&gt;Now I want to go a step further, and show how you can use Notion to keep tracked all the projects you are working on and their related resources.&lt;/p&gt;

&lt;p&gt;This part isn't meant only for freelancers that have a lot of projects running at the same time, but you can set up your workspace as you want. For example by tracking your life goals.&lt;/p&gt;

&lt;p&gt;PARA is an information management system created by Tiago Forte. PARA stands for Projects Areas Resources Archive.&lt;/p&gt;

&lt;p&gt;Let's see what means each category:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Projects, a series of tasks linked to a goal, with a deadline. (Hint: I use it to list only the projects I am currently working on and have defined another database which contains all the tasks).&lt;/li&gt;
&lt;li&gt;Areas, a sphere of activity with a standard to be maintained over time. (Here you can list the areas of your life, such as Finances, Health, Hobbies, etc…)&lt;/li&gt;
&lt;li&gt;Resources, a topic or theme of ongoing interest. (Here you can list all your interests and ideas)&lt;/li&gt;
&lt;li&gt;Archive, contains inactive items from the other three categories. (Here you can put all the projects you no longer working on)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PARA is just a framework, it can be adjusted to fit your needs. So if is not for you, don't be afraid and try to apply some changes.&lt;/p&gt;

&lt;h1&gt;
  
  
  More resources
&lt;/h1&gt;

&lt;p&gt;I've talked about Notion, its basics and PARA a useful method to keep your resources organized. I hope all the info I shared have been useful to someone!&lt;/p&gt;

&lt;p&gt;This article is just an overview of Notion, so I encourage you to go deeper and explore yourself the tool and all the productivity methods. If you need info don't be afraid to contact me.&lt;/p&gt;

&lt;p&gt;I want to leave you with some useful resources!&lt;/p&gt;

&lt;p&gt;Beginners guides to Notion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://thesweetsetup.com/a-beginners-guide-to-notion/"&gt;The Sweet Setup -  Beginners guide to Notion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.keepproductive.com/blog/notion-for-beginners#:~:text=What%20is%20Notion?,toolkit%20to%20get%20work%20done"&gt;Keep Productive - Notion for beginners&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Insights PARA method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://fortelabs.co/blog/para/"&gt;Forte Labs - The PARA method&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://radreads.co/para-notion/"&gt;RadReads- How to set up PARA in Notion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modernmakerseng.substack.com/p/how-to-use-notion-and-the-para-method"&gt;Modern Makers - How to use Notion and the P.A.R.A method to build a second brain&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An alternative of PARA mehtod:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://radreads.co/notion-gtd/"&gt;RadReads - How to implement GTD in Notion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;YouTube channels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/user/simulacrumsquared"&gt;Tiago Forte YouTube Channel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/user/marieisanerd"&gt;Marie Paulin YouTube Channel&lt;/a&gt;, she is a master of Notion and make absolutely great videos about it.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/results?search_query=keep+productive"&gt;Keep Productive&lt;/a&gt;, do amazing videos to improve your prouctivity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want read more about Notion, let me know in the comments!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>ideas</category>
      <category>notion</category>
    </item>
  </channel>
</rss>
