<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jesus Alvan on Medium]]></title>
        <description><![CDATA[Stories by Jesus Alvan on Medium]]></description>
        <link>https://medium.com/@jesusalvan2010?source=rss-e426288ff5c8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*smwqbUAGctawfwPYskfG4A.jpeg</url>
            <title>Stories by Jesus Alvan on Medium</title>
            <link>https://medium.com/@jesusalvan2010?source=rss-e426288ff5c8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:55:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jesusalvan2010/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building NPM  CLI Tool  to Encode whatever you want in a Single Encrypted File ]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@jesusalvan2010/building-npm-cli-tool-to-encode-whatever-you-want-in-a-single-encrypted-file-37e0b3e966f0?source=rss-e426288ff5c8------2"><img src="https://cdn-images-1.medium.com/max/1560/0*ms3ZgAG0n8ZDcaze.jpeg" width="1560"></a></p><p class="medium-feed-snippet">What if you could turn whatever you  want&#x2014; Images, Files, a Codebase project&#xA0;,etc&#x200A;&#x2014;&#x200A;into a single encoded.txt file?</p><p class="medium-feed-link"><a href="https://medium.com/@jesusalvan2010/building-npm-cli-tool-to-encode-whatever-you-want-in-a-single-encrypted-file-37e0b3e966f0?source=rss-e426288ff5c8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@jesusalvan2010/building-npm-cli-tool-to-encode-whatever-you-want-in-a-single-encrypted-file-37e0b3e966f0?source=rss-e426288ff5c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/37e0b3e966f0</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[esbuild]]></category>
            <dc:creator><![CDATA[Jesus Alvan]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 22:25:11 GMT</pubDate>
            <atom:updated>2025-04-17T22:25:11.775Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Creating a Tiny Window Manager with Electron and React]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@jesusalvan2010/creating-a-tiny-window-manager-with-electron-and-react-1ab81289dd52?source=rss-e426288ff5c8------2"><img src="https://cdn-images-1.medium.com/max/768/0*tFJm4pY6pTT-U1Ys.jpg" width="768"></a></p><p class="medium-feed-snippet">Has it ever happened to you that you have many windows on your screen (or screens) and want to organize them quickly and easily? Well is&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@jesusalvan2010/creating-a-tiny-window-manager-with-electron-and-react-1ab81289dd52?source=rss-e426288ff5c8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@jesusalvan2010/creating-a-tiny-window-manager-with-electron-and-react-1ab81289dd52?source=rss-e426288ff5c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ab81289dd52</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[electron]]></category>
            <dc:creator><![CDATA[Jesus Alvan]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 20:23:35 GMT</pubDate>
            <atom:updated>2025-04-17T22:33:35.667Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building a Tinder Swipe Cards in React Native ]]></title>
            <link>https://medium.com/@jesusalvan2010/making-a-tinder-swipe-cards-in-react-native-eaa290e92be2?source=rss-e426288ff5c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa290e92be2</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Jesus Alvan]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 17:37:00 GMT</pubDate>
            <atom:updated>2023-09-22T18:05:42.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VWHIgeVlz5_txjEP.png" /></figure><p>We’ve all seen these dating apps where show a list of users and if you like to stablish a conversation you have to swipe card to the right or left if you don’t like.</p><p>But how can we achieve it in React Native? Let see in the next sections!</p><ol><li><strong>Understanding about Animated and PanResponder API in React Native 🤓</strong></li><li><strong>Creating the SwipeCard Component 🙃</strong></li><li><strong>Using our SwipeCard into Discover People Tab 😁</strong></li><li><strong>Conclusion and what is next of our learning? 😅</strong></li></ol><h3>Understanding <strong>about Animated and PanResponder API in React Native</strong> 🤓</h3><p><strong>The Animated API</strong> is designed to add good animations in a performant way.Animated exports 6 animatable components: Views, Text, Image, ScrollView, FlatList and SectionList.However you can create your own components with Animated.createAnimatedComponent().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*CIfSjOyHZv7cjLzJl1JaXg.png" /></figure><p>In the example before. The FadeInView starts with:</p><pre>const fadeAnim = useRef(new Animated.Value(0)).current</pre><p>In this first Line we are creating our fadeIn animation with Value Zero. In our case we are going to fiddle with the opacity.</p><p>After that we have:</p><pre>   Animated.timing(fadeAnim, {<br>      toValue: 1,<br>      duration: 10000,<br>      useNativeDriver: true,<br>   }).start();</pre><p>In these lines we are adding a timer using the native Driver with 10secs duration and opacity of 1. That means when the component is rendered will apply the opactiy from 0 to 1.</p><p>For using this animation we’ll have to add an &lt;Animation.View&gt; component with the opacity style.</p><p>Now let’s suppose we want to bounce a ball with Animation API. In this case we are going to need using <strong>Animated.ValueXY({}). Let’s check it out!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*oWH5ev4BMwlrPX5mg8ajRg.png" /></figure><p>First thing to do is creating an animation with Animated.ValueXY({x: 10, y: 450}) :</p><pre>const bounce = useRef(new Animated.ValueXY({x: 10, y: 450})).current;</pre><p>This line set the position in X= 10 and Y=450 initially. After that when we press on Touchable Component it calls move function and runs Animated.spring with position values x: 250 and y: 10. This change the position from 10,450 to 250,10.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/0*NaV_7DmeWoVDWsK_.gif" /></figure><p><strong>The PanResponder API</strong> is designed to add good animations in a performant identifying gestures actions. Most React Native components, like View, can handle touch/click events. However, the APIs for doing this are fairly low level, so we rarely use them directly. Instead, we use the PanResponder API, which is a higher level abstraction for handling touch/click events.</p><p>Let see an example to drag an drop this element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*aC_RBQOS0axjL31xb8ZQUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*f_dyrfD2QW-XOZx2Ryhr1w.png" /></figure><p>For creating a component to drag and drop we will use PanResponder.create({…}). Let see the parameters:</p><p><strong>onMoveShouldSetPanResponder</strong>: This determines whether our pan responder should actuallly do anything. For this example we want the pan responder to be enabled on all the screen so we return true.</p><p><strong>onPanResponderMove</strong>: When a movement is detected , is executed this method. We are ignoring the raw event, which is the first argument, thus we pass null. The second argument is the gestureState which provides some helpful values, in our case dx and dy. Which are deltas (aka the changes) in how far the user has moved their finger from the beginning of the touch. <strong>We pass in our 2 animated values from an </strong><strong>Animated.ValueXY which our </strong><strong>Animated.event will take that configuration, traverse it, find the Animated values and call </strong><strong>setValue for us</strong>. Effectively when the user moves their finger our Animated values will be the delta positions.</p><p><strong>onPanResponderRelease</strong>: When a movement is done this method is executed.Pan.extractOffset() is adding the value to the offset and the offset is reseted to 0.</p><p>Finally is added the X and Y position from pan to the transform styles in &lt;Animated.View&gt;</p><h3><strong>Creating the SwipeCard Component 🙃</strong></h3><p>Now we can start checking our SwipeCard Component. Let’s take a look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*AA4v-xBxoBsE5KDlfMagzg.png" /></figure><p>First we create Animated.ValueXY() that will be swipe animation on each card. The other one is titlSign(create Animated.Value(1)) for card rotation.</p><p>After that PanResponder creates a reference with:</p><p><strong>onMoveShouldSetPanResponder</strong> return true to detect gesture action in every moment.</p><p><strong>onPanResponderMove</strong> set the swipe values and titlSign values when the user is touching the screen.</p><p><strong>onPanResponderRelease</strong> is called when the action is done.Here we validate in case of swipe is out the screen we animate the card and remove the card from the list. Otherwise if not out of the screen , this card go back to initial position.</p><p>Let’s continue with our <strong>SwipeCard Component</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*FAd-2EBpdLDZV07TyVPl2g.png" /></figure><p><strong>RemoveTopCard</strong> is used for removing the first card from the list and set the swipe value to x:0 and y:0.</p><p>Then <strong>rotate</strong> aims to add rotation in the transform style that is being applied in our cards component. Rotate uses Animated.multiply() to multiply the swipe.X value with titlSign value(this has the rotation value calculated when the user swipe the Card).</p><p>After that it is using interpolate. Interpolate allows you to add more equivalents in this case we are saying to react native: “I want to add a transform values range but also in the same timeline please add the degrees. Imagine the animation reach -100 position so the rotation degree will be 8deg”.</p><p><strong>Handle Choice Function</strong> aims to show and move the text inside the Card. If you swipe to the right or press like button the Like Text will be shown otherwise will be shown Nope Text.</p><p>Finally we are iterating each Item adding the transform styles and panResponder Handlers. Take into accout these will be applied only the first one item.</p><p>If you see almost at the end we are using <strong>Render Props Pattern</strong>.</p><p>First into the children we are accepting a children like a method that receives two parameters and this returns a React Node, Why are we doing this? Because we will need access to the swipe value, the item value and the index.</p><p>In the next section we’ll see the implementation. The same thing happens with renderActionBar method.</p><h3><strong>Using our SwipeCard into Discover People Tab 😁</strong></h3><p>Now, let’s take a look how we can use this SwipeCard Component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*A7EoD3n5BK2isCm9xNjZnA.png" /></figure><p>In this first part we can highlight the likeOpacity and nopeOpacity these guys aims to manage the opacity of Like Text in the right and NopeText in the left. After that we have the method to render these texts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*UcKSniT_-eG0FD9B2yWK8A.png" /></figure><p>Finally we are calling the SwipeCard Component also passing the Actions Bar(where are the like button, nope button and chat button). Then is rendering each Card getting the item, swipe and isFirst argument also returning the Card Component with each item info.</p><p>The result looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*RxZJeKXDHbhAEaJ1UdtC8Q.gif" /></figure><p>As always you can use these component for your own projects checking this component in the github repository.</p><p>Github Repo: <a href="https://github.com/Yei-Linux/dating-app">https://github.com/Yei-Linux/d</a>ating-app</p><h3><strong>Conclusion and what is next of our learning? 😅</strong></h3><p>Animations API and Pan API are so powerfull to make great things in react native. I tried to show you the theory and the practice part. I know that is missing more cases , more theory and more things but take the things that are more interesting for you and start coding!</p><p>In this post we developed a SwipeCard component, in future posts we are going to build the chat section in our app.Don’t miss the next post!</p><p>See you soon in the next one!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*1-D3aBpz1Y-r6wSS.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa290e92be2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Youtube Mixer with NextJS, Streams, Epress, Ytdl and FFMPEG [Part I — Searching and…]]></title>
            <link>https://medium.com/@jesusalvan2010/building-youtube-mixer-with-nextjs-streams-epress-ytdl-and-ffmpeg-part-i-searching-and-8e4cdb504b34?source=rss-e426288ff5c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e4cdb504b34</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Jesus Alvan]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 22:56:03 GMT</pubDate>
            <atom:updated>2023-08-31T14:12:59.597Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a YouTube Mixer Application with NextJS, Streams,SocketIO, Express, YTDL-core and FFMPEG 🤓[Part I — Searching and Downloading modules]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*SX_gLD_3I02mwzxZ.png" /></figure><p>As a music lover I like to get all my favorite music that I usually listen on Youtube, and as a content creator beginner I would like to generate a reel based on the original video generating the video, audio and the whole video.</p><p>So I thought … why not create an application where I can mix my favorite music, download it and in case of videos as a content creator beginner I would like to add a module to summarize the video and generate reels based on the video that user typed.</p><p>This would be the base of the platform, we can restrict the daily usage limit and add free plan, pro plan and business plan for example. Also, add new modules related to mix songs , create music as DJs and more useful features as a Youtuber content creator.</p><p>The search module, downloading module, and progress bar feature will be the focus of our discussion in this post. To take into account we are using nextjs13, expressjs, typescript, socketIO, streams and ytdl-core with ffmpeg libraries.</p><ol><li><strong>Learning about ytdl library and FFMPEG library 🤓</strong></li><li><strong>Creating the Searching Feature 🙃</strong></li><li><strong>Learning about Streams and Buffer </strong>🤓</li><li><strong>Creating the Downloading Feature with socketIO and streams😁</strong></li><li><strong>Conclusion and what is next of our learning? 😅</strong></li></ol><h3><strong>Learning about ytdl-core library 🤓</strong></h3><p>Ytdl-core is a Youtube downloader library using streams. We are going to use for getting meta information and download video filtering by itag(Youtube video format codes).</p><p>The response, when we get the information, has a format field. The next objects displayed are formats available related with the video information:</p><pre>...{<br>    &quot;mimeType&quot;: &quot;video/webm; codecs=\&quot;vp9\&quot;&quot;,<br>    &quot;qualityLabel&quot;: &quot;2160p&quot;,<br>    &quot;bitrate&quot;: 17672286,<br>    &quot;audioBitrate&quot;: null,<br>    &quot;itag&quot;: 313, ---&gt; Field used to filter<br>    &quot;width&quot;: 3840,<br>    &quot;height&quot;: 2160,<br>    &quot;initRange&quot;: {<br>      &quot;start&quot;: &quot;0&quot;,<br>      &quot;end&quot;: &quot;220&quot;<br>    },<br>    &quot;indexRange&quot;: {<br>      &quot;start&quot;: &quot;221&quot;,<br>      &quot;end&quot;: &quot;1108&quot;<br>    },<br>    &quot;lastModified&quot;: &quot;1613517410462477&quot;,<br>    &quot;contentLength&quot;: &quot;547880430&quot;,<br>    &quot;quality&quot;: &quot;hd2160&quot;,<br>    &quot;fps&quot;: 24,<br>    &quot;projectionType&quot;: &quot;RECTANGULAR&quot;,<br>    &quot;averageBitrate&quot;: 17508851,<br>    &quot;colorInfo&quot;: {<br>      &quot;primaries&quot;: &quot;COLOR_PRIMARIES_BT709&quot;,<br>      &quot;transferCharacteristics&quot;: &quot;COLOR_TRANSFER_CHARACTERISTICS_BT709&quot;,<br>      &quot;matrixCoefficients&quot;: &quot;COLOR_MATRIX_COEFFICIENTS_BT709&quot;<br>    },<br>    &quot;approxDurationMs&quot;: &quot;250333&quot;,<br>    &quot;url&quot;: &quot;https://rr4---sn-uqx2-aphel.googlevideo.com/videoplayback?expire=1693281373&amp;ei=_RftZN2kDbyc-LAPr4S_uA4&amp;ip=200.37.39.138&amp;id=o-AFBAgL-HIdd2miIU79g5bZ8o1hzUuFjdFScmvgLi6Ve5&amp;itag=313&amp;aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C271%2C278%2C313%2C394%2C395%2C396%2C397%2C398%2C399%2C400%2C401&amp;source=youtube&amp;requiressl=yes&amp;mh=w_&amp;mm=31%2C29&amp;mn=sn-uqx2-aphel%2Csn-nja7sner&amp;ms=au%2Crdu&amp;mv=m&amp;mvi=4&amp;pl=19&amp;initcwndbps=642500&amp;spc=UWF9fyyL3BTumbNwUXOpmH9fcm368Kwsu4-VKSRfPA&amp;vprv=1&amp;svpuc=1&amp;mime=video%2Fwebm&amp;ns=0A6X3HWyNfBZ7ND9iIWWC0MP&amp;gir=yes&amp;clen=547880430&amp;dur=250.333&amp;lmt=1613517410462477&amp;mt=1693259343&amp;fvip=1&amp;keepalive=yes&amp;fexp=24007246%2C51000023&amp;c=WEB&amp;txp=5532432&amp;n=gSTsychukfMQqQ&amp;sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&amp;lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&amp;lsig=AG3C_xAwRAIgbUo2n5ihaCvPr6Qk5_R1sl3yql6MwWoa7ETYsyCFT5gCIGrUvT5qZ-QEknpH1MNUMKS5B9MALUcTg_uVU4MToavp&amp;sig=AOq0QJ8wRQIgZLYSCBVoFYhy9hujpobPkViSeY-PNmAwSVvwykbRNuACIQCpFlDWxxOL6EzwEhiM1vb-hJ0ikt1H4nwcezbXqTjo1Q%3D%3D&quot;,<br>    &quot;hasVideo&quot;: true, ---&gt; Field used to filter<br>    &quot;hasAudio&quot;: false, ---&gt; Field used to filter<br>    &quot;container&quot;: &quot;webm&quot;,<br>    &quot;codecs&quot;: &quot;vp9&quot;,<br>    &quot;videoCodec&quot;: &quot;vp9&quot;,<br>    &quot;audioCodec&quot;: null,<br>    &quot;isLive&quot;: false,<br>    &quot;isHLS&quot;: false,<br>    &quot;isDashMPD&quot;: false<br>  },<br>  {<br>    &quot;itag&quot;: 401, ---&gt; Field used to filter<br>    &quot;mimeType&quot;: &quot;video/mp4; codecs=\&quot;av01.0.12M.08\&quot;&quot;,<br>    &quot;bitrate&quot;: 11829305,<br>    &quot;width&quot;: 3840,<br>    &quot;height&quot;: 2160,<br>    &quot;initRange&quot;: {<br>      &quot;start&quot;: &quot;0&quot;,<br>      &quot;end&quot;: &quot;700&quot;<br>    },<br>    &quot;indexRange&quot;: {<br>      &quot;start&quot;: &quot;701&quot;,<br>      &quot;end&quot;: &quot;1296&quot;<br>    },<br>    &quot;lastModified&quot;: &quot;1619713845247877&quot;,<br>    &quot;contentLength&quot;: &quot;365013893&quot;,<br>    &quot;quality&quot;: &quot;hd2160&quot;,<br>    &quot;fps&quot;: 24,<br>    &quot;qualityLabel&quot;: &quot;2160p&quot;,<br>    &quot;projectionType&quot;: &quot;RECTANGULAR&quot;,<br>    &quot;averageBitrate&quot;: 11664906,<br>    &quot;colorInfo&quot;: {<br>      &quot;primaries&quot;: &quot;COLOR_PRIMARIES_BT709&quot;,<br>      &quot;transferCharacteristics&quot;: &quot;COLOR_TRANSFER_CHARACTERISTICS_BT709&quot;,<br>      &quot;matrixCoefficients&quot;: &quot;COLOR_MATRIX_COEFFICIENTS_BT709&quot;<br>    },<br>    &quot;approxDurationMs&quot;: &quot;250333&quot;,<br>    &quot;url&quot;: &quot;https://rr4---sn-uqx2-aphel.googlevideo.com/videoplayback?expire=1693281373&amp;ei=_RftZN2kDbyc-LAPr4S_uA4&amp;ip=200.37.39.138&amp;id=o-AFBAgL-HIdd2miIU79g5bZ8o1hzUuFjdFScmvgLi6Ve5&amp;itag=401&amp;aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C271%2C278%2C313%2C394%2C395%2C396%2C397%2C398%2C399%2C400%2C401&amp;source=youtube&amp;requiressl=yes&amp;mh=w_&amp;mm=31%2C29&amp;mn=sn-uqx2-aphel%2Csn-nja7sner&amp;ms=au%2Crdu&amp;mv=m&amp;mvi=4&amp;pl=19&amp;initcwndbps=642500&amp;spc=UWF9fyyL3BTumbNwUXOpmH9fcm368Kwsu4-VKSRfPA&amp;vprv=1&amp;svpuc=1&amp;mime=video%2Fmp4&amp;ns=0A6X3HWyNfBZ7ND9iIWWC0MP&amp;gir=yes&amp;clen=365013893&amp;dur=250.333&amp;lmt=1619713845247877&amp;mt=1693259343&amp;fvip=1&amp;keepalive=yes&amp;fexp=24007246%2C51000023&amp;c=WEB&amp;txp=5532434&amp;n=gSTsychukfMQqQ&amp;sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&amp;lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&amp;lsig=AG3C_xAwRQIhAOlIBaBTMoIux9WewO4fEFjl5SDtLZph06-yjil0QuDIAiAWLPM33cJPCfbm-O_VxkrKo6ESIcOgkEqgpzrsp5fOCw%3D%3D&amp;sig=AOq0QJ8wRgIhAK2jMUqetz7JZnXrZ7j2iSzlAiTNKVz5_xqOflcihTPFAiEAs0ZBzi52I7g7LPAOLyb5Z2u5GufLDwjQjOjcAefXRhE%3D&quot;,<br>    &quot;hasVideo&quot;: true, ---&gt; Field used to filter<br>    &quot;hasAudio&quot;: false, ---&gt; Field used to filter<br>    &quot;container&quot;: &quot;mp4&quot;, <br>    &quot;codecs&quot;: &quot;av01.0.12M.08&quot;,<br>    &quot;videoCodec&quot;: &quot;av01.0.12M.08&quot;,<br>    &quot;audioCodec&quot;: null,<br>    &quot;isLive&quot;: false,<br>    &quot;isHLS&quot;: false,<br>    &quot;isDashMPD&quot;: false<br>  },<br>  {<br>    &quot;mimeType&quot;: &quot;video/webm; codecs=\&quot;vp9\&quot;&quot;,<br>    &quot;qualityLabel&quot;: &quot;1440p&quot;,<br>    &quot;bitrate&quot;: 6530340,<br>    &quot;audioBitrate&quot;: null,<br>    &quot;itag&quot;: 271, ---&gt; Field used to filter<br>    &quot;width&quot;: 2560,<br>    &quot;height&quot;: 1440,<br>    &quot;initRange&quot;: {<br>      &quot;start&quot;: &quot;0&quot;,<br>      &quot;end&quot;: &quot;219&quot;<br>    },<br>    &quot;indexRange&quot;: {<br>      &quot;start&quot;: &quot;220&quot;,<br>      &quot;end&quot;: &quot;1104&quot;<br>    },<br>    &quot;lastModified&quot;: &quot;1613517147483909&quot;,<br>    &quot;contentLength&quot;: &quot;185667788&quot;,<br>    &quot;quality&quot;: &quot;hd1440&quot;,<br>    &quot;fps&quot;: 24,<br>    &quot;projectionType&quot;: &quot;RECTANGULAR&quot;,<br>    &quot;averageBitrate&quot;: 5933465,<br>    &quot;colorInfo&quot;: {<br>      &quot;primaries&quot;: &quot;COLOR_PRIMARIES_BT709&quot;,<br>      &quot;transferCharacteristics&quot;: &quot;COLOR_TRANSFER_CHARACTERISTICS_BT709&quot;,<br>      &quot;matrixCoefficients&quot;: &quot;COLOR_MATRIX_COEFFICIENTS_BT709&quot;<br>    },<br>    &quot;approxDurationMs&quot;: &quot;250333&quot;,<br>    &quot;url&quot;: &quot;https://rr4---sn-uqx2-aphel.googlevideo.com/videoplayback?expire=1693281373&amp;ei=_RftZN2kDbyc-LAPr4S_uA4&amp;ip=200.37.39.138&amp;id=o-AFBAgL-HIdd2miIU79g5bZ8o1hzUuFjdFScmvgLi6Ve5&amp;itag=271&amp;aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C271%2C278%2C313%2C394%2C395%2C396%2C397%2C398%2C399%2C400%2C401&amp;source=youtube&amp;requiressl=yes&amp;mh=w_&amp;mm=31%2C29&amp;mn=sn-uqx2-aphel%2Csn-nja7sner&amp;ms=au%2Crdu&amp;mv=m&amp;mvi=4&amp;pl=19&amp;initcwndbps=642500&amp;spc=UWF9fyyL3BTumbNwUXOpmH9fcm368Kwsu4-VKSRfPA&amp;vprv=1&amp;svpuc=1&amp;mime=video%2Fwebm&amp;ns=0A6X3HWyNfBZ7ND9iIWWC0MP&amp;gir=yes&amp;clen=185667788&amp;dur=250.333&amp;lmt=1613517147483909&amp;mt=1693259343&amp;fvip=1&amp;keepalive=yes&amp;fexp=24007246%2C51000023&amp;c=WEB&amp;txp=5532432&amp;n=gSTsychukfMQqQ&amp;sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&amp;lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&amp;lsig=AG3C_xAwRAIgR7nTSQeeGDQph5nDWGMspFUt5ewUH_49phfKoGvOg1kCIACn6bGdxRvirV1xwO4a2ndUEtIWYEQZtlf97zvwl7tY&amp;sig=AOq0QJ8wRQIhAIuyliKTSzLQx8gkroRJHPfDcK83UxsemqGSiZL76liFAiAmCHlkDcT2MihlYZR7cjyDVx3Q4-iJ9hARner9UIVrPg%3D%3D&quot;,<br>    &quot;hasVideo&quot;: true, ---&gt; Field used to filter<br>    &quot;hasAudio&quot;: false, ---&gt; Field used to filter<br>    &quot;container&quot;: &quot;webm&quot;,<br>    &quot;codecs&quot;: &quot;vp9&quot;,<br>    &quot;videoCodec&quot;: &quot;vp9&quot;,<br>    &quot;audioCodec&quot;: null,<br>    &quot;isLive&quot;: false,<br>    &quot;isHLS&quot;: false,<br>    &quot;isDashMPD&quot;: false<br>  },...</pre><p>hasAudio and hasVideo indicates if that video format(for example a video with 360p resolution) has audio or video available, both or one of them.And the itag is a format code, every itag has a different resolution. If you want to learn more about itags see this gist:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6a394cfa419ae9f7d1d1bca2eb39368/href">https://medium.com/media/e6a394cfa419ae9f7d1d1bca2eb39368/href</a></iframe><p><strong>For getting meta video information we are using .getInfo() </strong>method and passing the youtube video url. The response is the meta information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SMCWGRaeV8kEF3wA76Zi3g.png" /></figure><p><strong>For Downloading video by format code we are calling the ytdl main method</strong>. This receive the link and options. In the options parameter we are passing a filter callback.This filter callback is executed and validate it by itag, hasAudio and hasVideo. If match video so is found it and downloaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNWED-BYU80pCk_63Av6ew.png" /></figure><p>In the code above we can see the <strong>filterYTDLVideo</strong> method is applying currying: “A process that allows you to transform a function with multiple arguments into a sequence of nesting functions…”.</p><p>The first function of filterYTDLVideo aims to get the moreOptions and the second function aims to get the format when the callback passed is executed by ytdl.</p><p>Finally as we can see we have <strong>filterByExtension</strong> object. This object aims to get the condition to apply by extension. For example if we want to get only the audio of the video and an specific quality we will execute the mp3 value from filterByExtension object. The condition says: “If video hasAudio and dont have video and itag is equal to the parameter passed so match it!”</p><h3><strong>Creating the Searching Feature 🙃</strong></h3><p>We have this UI(<strong>Frontend Side</strong>) for our searching module:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*8D_BCMs0MAgKy-YhxEHGbQ.png" /></figure><p>In the input will be typed youtube video url. Below of the input and search button are the thumbnail , title and video duration. For example let’s see what happened if we search the next video:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*bR-VcQ_lnfI6aZzWqEMPQw.png" /></figure><p>As we can see we have the main information.</p><p>Ok Let see how we can implement this feature! So the first step is building the UI. This is the main code of this feature(if you want to take a look all the code , at the end of the post I’ll put the github link)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ly3X6DpI445biyBfeMTtw.png" /></figure><p>This <strong>searchYtdlVideo</strong> method aims to call search endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOZzvVLoQqWmgFQIfH6MBg.png" /></figure><p>This <strong>useYoutubeSearch</strong> <strong>hook</strong> aims to get from the store the metaInfo, saved after get the info from the backend, search the video by the url and save it to the store.</p><p>As we can see we get the value from the input first with the FormData(this is <strong>uncontrolled form that means we are not saving any value changed in a state</strong>), after that is validated and if is valid calls to search endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbbHQclC6KHolLY-zuXSgQ.png" /></figure><p>And this is our TSX.</p><p>In the backend side we have this endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vj7MaGRChe2tVCUH_kcV6Q.png" /></figure><p>In the code above first we are getting youtube video info.After that we are getting thumbnail, video duration and formats grouped by extension. Finally we are returning the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qe6Q5bhL6Ec0jvmVU_8MgQ.png" /></figure><p>The <strong>groupFormatsByExtension</strong> method aims to group every format and resolution by extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNvTNjrQBXtbeQdVjmAEfg.png" /></figure><p>And finally the <strong>getYtInfo method </strong>for getting youtube video information as we mentioned before.</p><h3><strong>Learning about Streams and Buffer </strong>🤓</h3><p>NodeJS uses an event-driven, non-blocking I/O model. This allows us to create robust and scalable applications. Some of the main concepts that we can find are streams and buffers.</p><p>So what are Streams? … Is a way to process large mounts of data efficiently that enable reading and writing data in chunks instead of loading entire files into memory.</p><p>There are four different types of streams:</p><ul><li><strong>Readable streams </strong>: To create a stream of data for reading (reading a large file in chunks).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uzv8cIJLHE3oIYNDvRYExA.png" /><figcaption>We want to read the file content of test.txt so first we need to create a read stream passing file path. Then was added the event listeners: open, data, end. Open Event to detect when the file was open to start reading, Data Event for getting every chunk read. Finally we have the End Event to detect when the content was read and it proceed to end the process.</figcaption></figure><ul><li><strong>Writable streams :</strong> To create a stream of data for writing (writing a large amount of data to a file).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0xdJnmdLFGUSRvA9hIyWA.png" /><figcaption>In this example we are creating write stream.Then we use the .pipe method, this method allows transfer the data to the write stream created. So process.stdin.pipe transfers the input data from the terminal to the file stream. After that test.txt will have the input terminal.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zE-LzBk45PY_-pYyhb6RfA.png" /><figcaption>In this case we create a read stream for reading the file content and write stream for writting data. We use on(“data”) for getting each chunk and writting to the file by each one</figcaption></figure><ul><li><strong>Duplex streams :</strong> To create a stream that is both readable and writable at the same time. We can read and write to a duplex stream (a socket connection between a client and a server).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAimP8MbDzRmK-BMCwsfqQ.png" /><figcaption>In this example we create a tunnel with new PassThrough() ,this class allows pass the input bytes across to the output. This tunnel get the data passed from the file2 to the file.Also in the piping chain is added the throttle. As you can see, this Throttle extends from Duplex, overriding the write method adding the setTimeout.So the final process would be: first read the test2.txt file, then was added a throttling in the write process, after that when data arrives is saved, the amount of bytes processed.Finally is written the file content from test2.txt to test.txt</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*q7FQ1W3MTw44NVr3TpAY8g.png" /><figcaption>This graphic shows how duplex works. In two channels , both are independent and each have separate internal buffer. That’s the reason why you don’t get what you write.Because was sent to another source.</figcaption></figure><ul><li><strong>Transform streams :</strong> To create a stream that is readable and writable, but the data can be modified while reading and writing to the stream ( compressing data by the client and server before while requesting).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U21lqZhYZoIBJygdcL0kPw.png" /><figcaption>In this example we are using Transform for transforming the data read for writting to the file.In this case in the transform method we are adding .toUpperCase() to transform each word from the file.So the process would be: First read the file, add the uppercase transformer and finally is written to file with the text transformed.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*WqVJc9q8-5EpBRxHQxDI8A.png" /><figcaption>In this case we are using only one channel. So the text read manipulated is the same that we are writting.</figcaption></figure><p>We learned about streams but what about buffer? Buffer refers to the particular memory location in memory. Buffer and array have some similarities, but the difference is array can be any type, and it can be resizable. Buffers only deal with binary data, and it can not be resizable. Each integer in a buffer represents a byte.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pk7i9A4Y0-P3NSJf.png" /></figure><h3><strong>Creating the Downloading Feature</strong> with socketIO and Streams <strong>😁</strong></h3><p>We took a look into streams and buffer. So now we can start checking the downloading feature.</p><p>First take a look the downloader endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ByYGYuk7gm6mu-ne1eWZ4g.png" /></figure><p>So in this method first we are setting the parameters got and the socket instance initialized by a user.</p><p>Also set the ytdlUserPath and downloadUserPath for saving temporally the file in those directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8z1yYxDb5faTwfabndC0jA.png" /></figure><p>After that we are validating if any parameter or variable is empty or invalid.</p><p>Then we get the youtube info by url and the filter callback(as we explained at the beginning of the post). Then we proceed to pipe the readable content to the ytdlUserPath file.That means the youtube video content will be saved into a new file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4UHGQe1tkTACMcIJ2qn0zw.png" /></figure><p>The next method executed is this one. This method aims to read the file created before and transform this file with the extension that we want with ffmpeg(FFMPEG is library that allows to convert and stream audio and video) and save it into new file.</p><p>As you can see, we are emitting a message to the web socket connection. This message has the progress percent, progress time, status and operationId of the conversion process. This takes a place when FFMPEG is transforming our file.</p><p>Finally , at the end of the controller we are reading the file generated after ffmpeg conversion and it will pipe the file content to the response.</p><p>Before to move to the frontend side I would like to show you the socketIO initialization in the backend side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KYAZGQuMPvS0fLRXedqOww.png" /></figure><p>As you can see, it was added the connection event. When the client request, the websocket connection will be executed the connectInit event and passed the sessionId by the client. So this sessionId and the socketId will be saved in the socket object and this socket object will be set in the app.</p><p>Finally in the frontend side take a look the download feature:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*Bfm5B6GlT-yvxTnLtra7ug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*Qy8eSv0sydAgjOuQXFhMQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*7K8r65zAFaAAlDtvJzJ41A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*s302GrmTiqbaXetljbQHAQ.png" /></figure><p>This is the download flow. User can select MP4,MP3 and MP4 without audio. Also can download it.</p><p>The websocket is working when the status is updated while the audio and video are transforming.</p><p>The streaming is working when the file is got from Youtube, FFMPEG transform the file and it is downloaded to the client side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ty-NaN9epwyqrW5cSOuIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuQjVxPkvanGA09cwdA1oA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AO82_ATGDr9-qO8V5tLliQ.png" /></figure><p>The code above is related to the download feature. The useYoutubeDownload hook aims to download from the server and after that the blob is created into URL. This URL is saved into the a link element and click it to download in the browser. Finally, the link element is deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vtAkjpRTSQbCytkvUsBetA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZrpdtPSO7qm5VDfBhUDpVQ.png" /></figure><p>To take into account the operationId is retrieved from the server to difference from every download action.</p><p>The useProgress hook aims to handle the message of uploadProgress to update the progress bar in the UI through websocket connection.</p><p>Github Repo: <a href="https://github.com/Yei-Linux/youtube-mixer">https://github.com/Yei-Linux/youtube-mixer</a></p><h3><strong>Conclusion and what is next of our learning? 😅</strong></h3><p>Streams , buffers, ffmpeg, socketIO and YTDL-core are super interesting tools and libraries. I tried to show you the theory and the practice part. I know that is missing more cases , more theory and more things but take the things that are more interesting for you and start coding!</p><p>In this post we developed a YouTube manager platform, but we are at the beginning of the development more interesting things coming such as: summarize ,generate a reel, mixing of videos and more.Don’t miss the next post where we are going to continue building this tool!</p><p>See you soon in the next post!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*k8KK06J1dTlkoAQ4.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e4cdb504b34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning about Web Components (Introduction)]]></title>
            <link>https://medium.com/@jesusalvan2010/learning-about-web-components-introduction-d1f6b6f33600?source=rss-e426288ff5c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1f6b6f33600</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-components]]></category>
            <dc:creator><![CDATA[Jesus Alvan]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 22:13:57 GMT</pubDate>
            <atom:updated>2023-08-08T22:13:57.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r3f8hTKumXEPhTCA.png" /></figure><p><strong>As frontend</strong> developer we are accustomed to use libraries or frameworks to modularize our project as components and decrease the code size of files. Some libraries and frameworks that we can use are: “React”, “Angular”, “Vue”, etc. But sometimes its interesting know new options to take into account.</p><p>Today we are going to see what is needed to start working with web components. In this post we will learn about:</p><ol><li><strong>What are web components🙃</strong></li><li><strong>Three Main Technologies of Web Components🤔</strong></li><li><strong>Life Cycle of Web Components 🤔</strong></li><li><strong>Using Web Components without any library 😨</strong></li><li><strong>Web Components Libraries 😁</strong></li><li><strong>Advantages of Web Components 😁</strong></li><li><strong>Useful cases to start using Web Components in our projects </strong>😇</li><li><strong>Conclusion and what is next of our learning? 😅</strong></li></ol><h4>What are web components🙃</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*SNHkiwuzyNchu2-d.jpeg" /></figure><p>Web Components is a suite of technologies where we can create reusable custom element.</p><p>We can say is a way to <strong>create an encapsulated, single-responsibility code block that can be reused on any page.</strong></p><p>When we say <strong>encapsulation we are talking about b</strong>eing able to keep the markup structure, style, and behavior hidden and <strong>separate from other code on the page so that different parts do not clash</strong>, and the code can be kept nice and clean.</p><h4>Three Main Technologies of Web Components🤔</h4><p>The main technologies of web components are:</p><ol><li><strong>Custom elements:</strong> A set of web platform APIs that <strong>enable the creation of reusable and encapsulated HTML elements(using custom HTML tags and defined in JS)</strong>. They allow developers to define their own custom elements, complete with custom behaviors, properties, and styling, which can be used just like any other HTML element in web pages. For example in the next images we create a custom element defining in our HTML the &lt;my-custom-element&gt; tag. After that we need to create ,in our JS, the class to control the behavior of our custom tag. This class should extend from HTMLElement where in constructor we have to attach in the shadow dom our element’s content. Finally it will be defined in the DOM our my-custom-element.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*O7e3btH7vQcrNpfrlp9syQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*3UhI6_fcpikBtYjw1mfoYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*BFyPOO-8joaUQ7lJxtxHfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/97/1*_i88hiSBxAWhyzfDozUiPg.png" /></figure><p><strong>2. Shadow DOM:</strong> A set of JavaScript APIs for <strong>attaching an encapsulated “shadow” DOM tree to an element which is rendered separately from the main document DOM</strong>. As the main documentation says: <br>“<em>Shadow</em> DOM allows hidden DOM trees to be attached to elements in the regular DOM tree”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*mmIPlSwps1rQLdJsss5ajA.png" /></figure><p>3. <strong>Templates: </strong>Template HTML is <strong>a way for holding HTML that is not to be rendered immediately until you grab a reference to it with JS and then append it to the DOM</strong>. In the next images we can see first our template defined(along with id attribute) in HTML. After that in JS we proceed to get it with id and get the template’s content. Finally it ill be append it to the DOM. To take into account: we can see in the second to last image the <strong>#documentFragment</strong>. This indicates that the content has not parent with any element of HTML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*qj7E49uBfg7asSvyG7vmVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*a5NO7psgswlw7v07q_bRvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*TFhrwh0JhO6avOjKq7fXpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/153/1*Blukb6N1m0Ea9QV54O4hfw.png" /></figure><h4><strong>Life Cycle of Web Components 🤔</strong></h4><p>In the life cycle we have:</p><ol><li><strong>Constructor</strong>: The<strong> first method called once the web component is initialized</strong>. In this method should call super method(to execute parent’s constructor) and attach elements to the shadow dom.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*_8kouYZ9ZWsH4aRlrdP6cA.png" /></figure><p>2. <strong>ConnectedCallback</strong>: This method will be called once each time the web component is attached to the DOM. <br><strong>Since the shadow root was attached in the </strong><strong>constructor(), then </strong><strong>connectedCallback() can be used to access attributes, child elements, or attach event listeners.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*-xi1YHdu5tmXQXwxbffjpw.png" /></figure><p>3. <strong>AttributeChangedCallback</strong>: This method will be called every time that attribute is updated. Attributes are updated when this.setAttribute() is triggered. The attributes to be observed must first be defined in a static method called observedAttributes().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*vrWdsIiVetjC-8g1f4CDjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*1G7tt3ufhyqhYhRVV4Z8LA.png" /></figure><p>4. <strong>AdoptedCallback</strong>: Used to move a node from one document to another. This is often used when working with iFrame components. adoptedCallback() is triggered when document.adoptNode() is used to move the web component to a new document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*4eExsRCUSp0m-X09uqmOtA.png" /></figure><p>5.<strong>DisconnetedCallback</strong>: Will be called when the web component is removed from the DOM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*MiAuxzuEnTbJND14-CKrlQ.png" /></figure><h4><strong>Using Web Components without any library 😨</strong></h4><p>Ok let’s start making a tic tac toe but using Web Components. It will be interesting!.</p><p>First of all in our html we’ll have these two web components: &lt;board-wc&gt; and &lt;square-wc&gt;.</p><p>The board web component will have the logic of our board ang game also it will receive a slot(is a placeholder inside a web component), by other side, square web component will have the logic of each square of our board also receive two attributes row and col to identify each square at the moment of verify is player won or not.</p><p>Let’s see (<strong>HTML Content</strong>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*L_fk3qZz9OmTNDPjfRHPcQ.png" /></figure><p>Right now anything will be displayed … yeah but it’s still missing the definition of our web components.</p><p>Let’s see our board web component<strong>(Board Web Component)</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*ef7pEtQU-IoL4wdMfyqnow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*5Hf0dAetGZIS4MOZx8l3Sg.png" /></figure><p>As we can see the slot tag is defined with attribute name. This name will be the identifier to match the elements that will go inside of this slot.</p><p>In the <strong>connectedCallback </strong>it defined the HTML content of our web component.</p><p>After that we have the <strong>addEventListener</strong>. In this case we are using a <strong>CustomEvent </strong>to dispatch events between our store and web components.</p><p>This custom event will be explained in the store section! Ok, Let’s continue with this component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*Yx5or7QZg6ayx30_xhdZEw.png" /></figure><p>The next two methods are:</p><p><strong>updatePlayer</strong>: Update the player text to indicate whose the turn. <br>Also we can notice it was used <strong>this.shadowRoot.querySelector</strong>. This helps to select any element from the shadowRoot. <br>After that as you can see we are calling the store. This store is a custom store that we’ll check it in soon!<br>Content Rendered:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/1*0iK6kEstCAziu-n9oVqOpg.png" /></figure><p><strong>updateEndGame</strong>: Update the end game text to indicate if any player won or not. Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*FlXxBXyS36o4HLv1Fd5QRQ.png" /></figure><p>The next method is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*e2GiMtIGsNtW1gZkkBC0KA.png" /></figure><p><strong>handleStoreChanges</strong>: Is called by addEventListener method. So this event arrives when either the currentPlayer or matrix was changed. <br>When currentPlayer was updated(it means that round changed) will be updated round player. <br>When matrix was updated. Is executed isVictory method to analyze if there is any winner or not.</p><p>Let’s see isVictory method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*nNRFrowInVLMpElGL1_I4w.png" /></figure><p>I made this diagram to understand the three validations of this method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*0mrKC5uU273E_eOJEGQx-w.png" /></figure><p><strong>wonInRow </strong>means that last move of player win the game in the direction showed in the image above.<br><strong>wonInCol </strong>means that last move of player win the game in the direction showed in the image above.<br><strong>wonInDiagonal </strong>means that last move of player win the game in the direction showed in the image above.</p><p>Otherwhise the game continues until all tryes are completed.</p><p>Finally we define our web component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*BMFIx9DKo0VYA4BNDnbgfA.png" /></figure><p>Now we have our square web component <strong>(Square Web Component)</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*x6EwKxYIbBiqkFW5sex2UA.png" /></figure><p><strong>This web component aims manage when user click over the square of board</strong> to register the action in our store and dispatch the event to our board.</p><p>We can see the <strong>attributeChangedCallback </strong>of web component’s lifecycle to detect when attributes are updated and handler actions.</p><p>After that we have <strong>this.addEventListener</strong> to detect when user click and call the <strong>handlerSquare </strong>method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*NvUMfBKIbswj0t2q7gyBPw.png" /></figure><p>This method mentioned aims draw the cross or nought ,depends the player. After draw the icon over the square call to the store. It will update the matrix of tic tac toe and the player’s turn.</p><p>Finally in this web component we have the styles:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*dYFcQF7eOz8-aK4zf3fuqg.png" /></figure><p>Last but not least…the store:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*lU_Ik-XBp0gIlaNXfYYW0A.png" /></figure><p>This is our store. First we have an IIFE where inside its defined the store in the windows object to make it globally.</p><p>There is its defined fields and methods to manage our store. But the most important thing to highlight is the <strong>CustomEvent</strong>.</p><p>Basically a <strong>CustomEvent </strong>is an event that we can create and define it with an action handler to do. For example in this case every time the currentPlayer or matrix is updated , the custom event is dispatched with the payload. Our payload will be the key(field name updated from the store) and value updated.</p><p>This event dispatched is listened by our board and managed.</p><p>Also here you have the link of GitHub repository to see the project:</p><p><strong>GitHub: </strong><a href="https://github.com/GamiLife/BlogSample/tree/master/tictactoe">https://github.com/GamiLife/BlogSample/tree/master/tictactoe</a></p><h4>Web components Libraries 😁</h4><p>We can name some of them:</p><ol><li><a href="https://lit.dev/docs/">Lit</a></li><li><a href="https://hauntedhooks.netlify.app/">Haunted</a>(if you like react probably you will like this one)</li><li><a href="https://stenciljs.com/docs/introduction">Stencil</a>(if you like angular probably you will like this one)</li><li><a href="https://hybrids.js.org/#/">Hybrids</a></li></ol><h4><strong>Advantages of Web Components😁</strong></h4><p>Web Components has the following advantages:</p><ol><li>Faster and more memory efficient.</li><li>Supported by modern browsers.</li><li>Encapsulation(All the encapsulation styles is provided by Shadow DOM. It separates your components from the rest of the DOM)</li><li>Framework agnostic components( can be used with any frontend library or directly in HTML documents)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*2p3fF0gd1Vf7dUrB.gif" /></figure><h4><strong>Useful cases to start using Web Components in our projects </strong>😇</h4><p>Companies such as:</p><ol><li>Google</li><li>Amazon</li><li>Apple</li><li>Github</li><li>NASA</li><li>Netlify</li><li>Microsoft</li><li>Salesforce</li><li>SpaceX</li><li>Adobe</li></ol><p>Are using Web Components in their projects. These companies have their own use cases to use it. Some use cases where it can be used are:</p><ol><li>Building a design system using Web Components to be used in different frameworks.</li><li>Implementation of Web Components in a website where is using JQuery or VanillaJS.</li><li>Small and Medium Projects.</li><li>Create a reusable component used in any kind of framework.</li></ol><h4><strong>Conclusion and what is next of our learning? 😅</strong></h4><p>Web components are a useful tool from the advantages exposed until the use cases where you can start working on that. So take this post to expand your knowledge and have more possibilities at the moment to take a decision either in your job or personal projects.</p><p>In this post we talked about web components but we have to see how can we develop a tool using web components with a library. Don’t miss the next post where we are going to develop a tool(useful on my own) using web components!</p><p>See you soon in the next post!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*SDP_jxu0bBuFERL6.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1f6b6f33600" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding what the heck data structures are and when is needed to implement them?]]></title>
            <link>https://medium.com/@jesusalvan2010/understanding-what-the-heck-data-structures-are-and-when-is-needed-to-implement-them-620d2e31511f?source=rss-e426288ff5c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/620d2e31511f</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Jesus Alvan]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 03:22:36 GMT</pubDate>
            <atom:updated>2023-07-31T03:22:36.097Z</atom:updated>
            <content:encoded><![CDATA[<p>Every time I’m working in a project (whether in a huge project or not), personally the most of <strong>data structures</strong> that I found either in projects or implemented by me are:<strong> arrays and objects</strong> and that’s all even when the implementation could be better with a different data structure.</p><p>A little spam: Apologies for my bad English I’m on my way to improving it to bring better publications.</p><p>After this little spam… Let’s start!</p><p>In this post we will learn about:</p><ol><li><strong>What is Data Structure 🙃</strong></li><li><strong>When is needed a Non Primitive Data Structure (Example)🤔</strong></li><li><strong>Types and Classification of Data Structure 😁</strong></li><li><strong>Conclusion and what is next of our learning? 😅</strong></li></ol><h3>What is Data Structure?<strong> 🙃</strong></h3><p>Data structure is the study to understand <strong>how can we organize the data in our software</strong> and <strong>how the data flow is managed in our program</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*syooR--pGng7i372OWpOuQ.png" /><figcaption>Comparing Lego&#39;s blocks with data</figcaption></figure><p><strong>To take into account: </strong>Data structure is the structural representation of logical relationship between data elements.</p><h3><strong>When is needed a Non Primitive Data Structure(Example) 🤔</strong></h3><p>I use the next points to take into account of my decision to implement a non primitive data structure or not:</p><ol><li>Give a different level of data organization.</li><li>Fast searching and sorting data.</li><li>Manage huge amount of data efficiently.</li></ol><p>Take a look the next example and we will try to solve step by step taking into account any of three points mentioned.</p><blockquote>Exercise: We’re given an <strong>array</strong> and we know that 2 values within that array add up to our <strong>target</strong>. We have to <strong>find the locations of those 2 values</strong>.(From leetCode)</blockquote><p>So we have:</p><ol><li>Array of n values.</li><li>2 values of that array add up to our target.</li></ol><p>In this problem the key would be a good searching and finding values without a lot of computing. Based on this requirement we can see one of the points exposed is applied(point number 2). In this case we will use a Hash Map.</p><p>The thought process would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*k9G9sRB0yE_uvvY4o6SYqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kNufDTm5tcviOvQadObRQQ.png" /></figure><p>and the solution using Hash Map in JavaScript would be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*g4JfUCPJF9L7QHRNyJUrug.png" /></figure><p>In this solution the steps are:</p><ol><li>Create a Map Data Structure.(Our hash map)</li><li>Iterate the array of numbers.</li><li>Get the current number and desired number(difference between the target and current number)</li><li>Verify if the desired number is stored in our Map.</li><li>In case is not found we proceed to saved into Map with a key — value( current number — index )</li><li>Otherwise is found we proceed to return the index of current number and the index retrieved</li></ol><p>As you can see using a Hash Map the performance of our program is much better and the complexity is O(n) (Big O notation will be one of the next topics to talk about) that means our code is fast.</p><h3><strong>Types and Classification of Data Structure 😁</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/0*tRXy5ynHKlvjW864.png" /></figure><ol><li><strong>Primitive Data Structures:</strong></li></ol><p>Consist of the numbers and the characters which are built in programs. These can be manipulated or operated directly by the machine level instructions.</p><p>These data types are also known as simple data types because they consist of characters that cannot be divided.</p><p>2. <strong>Non Primitive Data Structures:</strong></p><p>Non-primitive data structures are <strong>those that are derived from primitive data structures</strong>.</p><p>These data structures <strong>cannot be operated or manipulated directly by the machine level instructions.</strong></p><p>They focus on formation of a set of data elements that is either homogeneous (same data type) or heterogeneous (different data type).</p><p><strong>2.1 Linear Data Structure</strong></p><p>A data structure that maintains a linear relationship among its elements is called a linear data structure.</p><p>Here, the data is arranged in a linear fashion. But in the memory, the<br>arrangement may not be sequential.</p><p>Example: Arrays, linked lists, stacks, queues.</p><p><strong>2.2 Non Linear Data Structure</strong></p><p>Non-linear data structure is a kind of data structure in which data elements are not arranged in a sequential order.</p><p>There is a hierarchical relationship between individual data items. Here, the insertion and deletion of data is not possible in a linear fashion.</p><p>Example: Trees ,graphs, tables and sets.</p><h3><strong>Conclusion and what is next of our learning? 😅</strong></h3><p>Data Structures are so useful to organize our data elements and improve the performance. In the next series of computer science posts I’m going to talk about Non Primitive Data Structures.</p><p>The first Data Structure will be Linked List with a real project and exercises when we can use this data structure (from leet code). After that , the upcoming topics will be Stacks, Queues, Trees ,Graphs, Tables and Sets.</p><p>So excited to talk about these useful topics. See you soon in the next post!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*W3aNN0OszvhWWvZxR_F-Aw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=620d2e31511f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>