<?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 Moatez Bejaoui on Medium]]></title>
        <description><![CDATA[Stories by Moatez Bejaoui on Medium]]></description>
        <link>https://medium.com/@moatez.bejaoui?source=rss-5d9b1e50e0f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-eTOvNA7uCq5oat4G2hMPQ.png</url>
            <title>Stories by Moatez Bejaoui on Medium</title>
            <link>https://medium.com/@moatez.bejaoui?source=rss-5d9b1e50e0f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:35:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@moatez.bejaoui/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[MongoDB Pagination with an aggregation pipeline using Node js and express with TypeScript.]]></title>
            <link>https://medium.com/@moatez.bejaoui/mongodb-pagination-with-an-aggregation-pipeline-using-node-js-and-express-with-typescript-dc5311e15afc?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc5311e15afc</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[aggregation]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 22:41:45 GMT</pubDate>
            <atom:updated>2021-09-07T22:41:45.219Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tgcey1be_aOdbLvALkMJEg.jpeg" /></figure><p>In this topic, I will be showing you how to make dynamic pagination using the MongoDB aggregation pipeline.</p><p>First of all, we are needing schema and inserted data in our MongoDB database.</p><p>we be needing a large data structure In this example so we will be using the following Schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*Rd5e4QQie5e1w4aNKYmGQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKaLMC5LPcJEKU2bhDQHyg.png" /><figcaption>Schema and type</figcaption></figure><p>Next, we will start creating our pipeline in a helper because we want it to be dynamic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1211e339b8e1072cc509a19c300ace0a/href">https://medium.com/media/1211e339b8e1072cc509a19c300ace0a/href</a></iframe><blockquote><strong>1-Stage : </strong>So our helper will simply take a query as an argument that contains our page number and a filter query that will be passed in our<strong> $match </strong>stage, for example, if we want to search for all countries that belong to a certain region we can simply pass { region: ‘Africa’ } in our filter query.</blockquote><blockquote><strong>2-Stage : S</strong>orting , you can also pass a sort object and distructure it inside the pipiline like we did with filter.</blockquote><blockquote><strong>3-Stage : </strong>We will be using <strong>$facet</strong> to processes multiple <a href="https://docs.mongodb.com/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">aggregation pipelines</a> within a single stage on the same set of input documents. what i mean by that in our example counting how many document we have and returning data in the same stage you can usnig more stages if you need !</blockquote><blockquote><strong>4-Stage : </strong>Distructuring our total because $facet returns an array.</blockquote><blockquote><strong>5-Stage :</strong></blockquote><blockquote>Creating our returned object in form of</blockquote><blockquote><strong>{ items : ICountry[] , page : number , hasNextPage : boolean ,totalPage : number ,totalItems : number } </strong>To get this result we be using <strong>$project</strong> stage :</blockquote><p>First of all, we will be slicing our data that was returned from the <strong>$facet</strong> stage with our skip variable so each time we change the page number our skip changes and slice our data the way to want it.</p><p>The rest of our object is basically math to calculate on what page are we if there is a next page or not, total pages and total items that we already have from <strong>$count.</strong></p><p>To put our help in action, we will be using it in our service like the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afa71430a49fc6b0fb52fd075b1f4114/href">https://medium.com/media/afa71430a49fc6b0fb52fd075b1f4114/href</a></iframe><p>I just passed a filter object to filter all the countries that have a region which is Africa.</p><p>Ps: the correct way is to send that information from the query, but just for demo purposes I used it directly in the service.</p><p>Next, we will be creating our controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0a5b4728c6b173853f747682bd00a3/href">https://medium.com/media/6a0a5b4728c6b173853f747682bd00a3/href</a></iframe><p>And Finally, let&#39;s test it out after creating our router of course.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da2eeac528d8561ceb069f0488beeb96/href">https://medium.com/media/da2eeac528d8561ceb069f0488beeb96/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lmmQ_aRRcvB7lIgM8HPf3A.png" /><figcaption>Result</figcaption></figure><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc5311e15afc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a generic component with React TypeScript.]]></title>
            <link>https://medium.com/edonec/creating-a-generic-component-with-react-typescript-2c17f8c4386e?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c17f8c4386e</guid>
            <category><![CDATA[flatlist]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Mon, 28 Jun 2021 12:37:24 GMT</pubDate>
            <atom:updated>2021-06-28T12:37:24.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TG2ebQQMNS8_FH5MVKjq9w.jpeg" /></figure><p>In this topic we will be creating a generic component, so first of all we need to learn what are generic types?</p><blockquote><strong>Definition</strong></blockquote><p>TypeScript Generics is a tool that provides a way to create <strong>reusable</strong> components. It creates a component that can work with a <strong>variety of data types</strong> rather than a single data type. It allows users to consume these components and use their own types. Generics ensures that the program is flexible as well as scalable in the long term.</p><p>if you wanna see an example of how to use it check this <a href="https://medium.com/edonec/typescript-generic-types-364b8b324801?source=---------2----------------------------">article</a> that has been written by my colleague and friend <a href="https://medium.com/u/2b16fada057a">bursty</a> who inspired me to write an example about react usage!</p><p>So let&#39;s get started!</p><blockquote><strong>Issue</strong></blockquote><p>While working with react, we always map through arrays to display data which is perfectly fine! but what if I told you that we can create a component that can make you stop writing .map in jsx! awesome huh? , so let&#39;s start by creating our component!</p><blockquote><strong>Solution</strong></blockquote><p>First of all, we will be defining what our component will be taking as props!</p><p>if you are familiar with react-native you will know that this idea was inspired by FlatList component.</p><p><strong>Props :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*ap2Ed9R6C_RFHFXHIrSdEA.png" /></figure><p><strong>data: </strong>will be our array that will be taking a generic type T!</p><p><strong>renderItem: </strong>is a function that will be returning a react element of type T as well.</p><p><strong>keyExtractor</strong>: is a function to extract our key.</p><p><strong>Component :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Slraw9S5nMPrzrQskpdmaQ.png" /></figure><p>Our GenericList component will be extracting types from the data that will be passed in! , render item will automatically help you with the types because it relies on the data type that will be passed in!</p><p><strong>Usage :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*hOyok3TDJNlCJ514mRLL8A.png" /></figure><p><strong>Conclusion :</strong></p><p>As we saw in this article, using generic components helps us write less, more maintainable, and refactorable code as well it provides a very good experience with IntelliSense integration in the IDE.</p><p><strong>Code sandbox :</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fugz74&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fugz74&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fugz74%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/c061256e71eb7c49203d6b1452fb1f65/href">https://medium.com/media/c061256e71eb7c49203d6b1452fb1f65/href</a></iframe><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c17f8c4386e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/creating-a-generic-component-with-react-typescript-2c17f8c4386e">Creating a generic component with React TypeScript.</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animating an SVG with CSS.]]></title>
            <link>https://medium.com/edonec/animating-an-svg-with-css-bd6f1ac7f2ac?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd6f1ac7f2ac</guid>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[figma]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Fri, 04 Jun 2021 12:34:23 GMT</pubDate>
            <atom:updated>2021-06-04T12:34:23.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*4LKR4-QBwzB1F3FeTCW6bQ.png" /></figure><p>In this article, we will be animating an SVG so first of all, we simply take an SVG from <a href="https://undraw.co/illustrations">unDraw</a> and we will modify it with <a href="https://www.figma.com/downloads/">Figma</a>.</p><blockquote><strong>1- Editing and grouping what elements we will animate.</strong></blockquote><p>So we will be using Figma to group up our elements like the following!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9U6lkoLDQuThC5cmHRYTA.png" /></figure><p>You can simply select elements and use CRTL + G to group them up, in our case we will need to group the planet, locations, hand, and hair because that&#39;s what we will animate eventually.</p><p>Next, we will export our SVG and make sure you export id attributes as well</p><p>You need to select your SVG on the top left corner and export like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*yyD8RH8X_pROfHyUYW6xUg.png" /></figure><blockquote><strong>Animating the SVG</strong></blockquote><p>So the first step is copying our SVG code into our index.html!</p><p>Next, we will be creating a CSS file to start animating!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUd211w6nfollp_InBp2rw.png" /></figure><p><strong>Result :</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmoatezng%2Fembed%2Fpreview%2FyLMPwOG%3Fdefault-tabs%3Dhtml%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DyLMPwOG&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmoatezng%2Fpen%2FyLMPwOG&amp;image=https%3A%2F%2Fassets.codepen.io%2F6372584%2Finternal%2Fscreenshots%2Fpens%2FyLMPwOG.default.png%3Ffit%3Dcover%26format%3Dauto%26ha%3Dtrue%26height%3D540%26quality%3D75%26v%3D2%26version%3D1622451107%26width%3D960&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d9e250398a8f43e0e81bd97780284ce/href">https://medium.com/media/6d9e250398a8f43e0e81bd97780284ce/href</a></iframe><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote>This has been developed by myself at <a href="https://edonec.com/">eDonec</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd6f1ac7f2ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/animating-an-svg-with-css-bd6f1ac7f2ac">Animating an SVG with CSS.</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Layout with FlexBox in React Native]]></title>
            <link>https://medium.com/edonec/layout-with-flexbox-in-react-native-a24dbe678e75?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a24dbe678e75</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[flex]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Mon, 24 May 2021 14:07:55 GMT</pubDate>
            <atom:updated>2021-05-24T14:07:55.770Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Flex</strong></blockquote><p>Flex will define how your items are going to “fill” over the available space along your main axis. Space will be divided according to each element&#39;s flex property.</p><p>In the following example, the red, gold, and steel-blue views are all children in the container view that has flex: 1 set. The red view uses flex: 1 , the gold view uses flex: 2 and the steel blue view uses flex: 3 . 1+2+3 = 6 which means that the red view will get 1/6 of the space, the gold 2/6 of the space and the steel blue 3/6 of the space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*3XrXjZR95VT6nWCecu13sA.png" /><figcaption>Flex</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9115a762a4ab90660485e4d45540ffe6/href">https://medium.com/media/9115a762a4ab90660485e4d45540ffe6/href</a></iframe><blockquote><strong>Flex direction</strong></blockquote><p>Flex direction controls the direction in which the children of a node are laid out. This is also referred to as the <em>main axis</em>. The cross axis is the axis perpendicular to the main axis or the axis on which the wrapping lines are laid out.</p><ul><li>row Align children from left to right. If wrapping is enabled then the next line will start under the first item on the left of the container.</li><li>column (default value) Align children from top to bottom. If wrapping is enabled then the next line will start to the left first item on the top of the container.</li><li>row-reverse Align children from right to left. If wrapping is enabled then the next line will start under the first item on the right of the container.</li><li>column-reverse Align children from bottom to top. If wrapping is enabled then the next line will start to the left first item on the bottom of the container.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*EZPssvbSgo0zdJT2ygA2Cw.gif" /><figcaption>flexDirection</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cd045091293ea8f74db464e01f1c8b1/href">https://medium.com/media/5cd045091293ea8f74db464e01f1c8b1/href</a></iframe><blockquote><strong>Layout Direction</strong></blockquote><p>Layout direction specifies the direction in which children and text in a hierarchy should be laid out. Layout direction also affects what edge start and end refer to. By default React Native lays out with LTR layout direction. In this mode start refers to left and end refers to right.</p><ul><li>LTR (default value) Text and children are laid out from left to right. Margin and padding applied to the start of an element are applied on the left side.</li><li>RTL Text and children are laid out from right to left. Margin and padding applied to the start of an element are applied on the right side.</li></ul><h4>Justify content</h4><p>Justify content describes how to align children within the main axis of their container. For example, you can use this property to center a child horizontally within a container with flexDirection set to row or vertically within a container with flexDirection set to column.</p><ul><li>flex-start(default value) Align children of a container to the start of the container&#39;s main axis.</li><li>flex-end Align children of a container to the end of the container&#39;s main axis.</li><li>center Align children of a container in the center of the container&#39;s main axis.</li><li>space-between Evenly space of children across the container&#39;s main axis, distributing remaining space between the children.</li><li>space-around Evenly space of children across the container&#39;s main axis, distributing remaining space around the children. Compared to space-between using space-around will result in space being distributed to the beginning of the first child and end of the last child.</li><li>space-evenly Evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*h-D2OLzHj2UTri3fNyIyEw.gif" /><figcaption>justifyContent</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3ce9fc8f7685f9ac652eb95cc1fc4b6/href">https://medium.com/media/e3ce9fc8f7685f9ac652eb95cc1fc4b6/href</a></iframe><p><strong>Align items</strong></p><p>Align items describe how to align children along the cross axis of their container. Align items is very similar to justifyContent but instead of applying to the main axis, alignItems applies to the cross axis.</p><ul><li>stretch (default value) Stretch children of a container to match the height of the container&#39;s cross axis.</li><li>flex-start Align children of a container to the start of the container&#39;s cross axis.</li><li>flex-end Align children of a container to the end of the container&#39;s cross axis.</li><li>center Align children of a container in the center of the container&#39;s cross axis.</li><li>baseline Align children of a container along a common baseline. Individual children can be set to be the reference baseline for their parents.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*LRMal7uOq8hzvIOBPUYYOQ.gif" /><figcaption>alignItems</figcaption></figure><p>Note: The stretch does not work if the children have a fixed dimension along the secondary axis. In the above example, the alignItems: stretch will not work until we remove the width of the gold container.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52470d689994fedd6c960b4dea68ef89/href">https://medium.com/media/52470d689994fedd6c960b4dea68ef89/href</a></iframe><blockquote><strong>Align self</strong></blockquote><p><a href="https://reactnative.dev/docs/layout-props#alignself">alignSelf</a> has the same options and effect as alignItems but instead of affecting the children within a container, you can apply this property to a single child to change its alignment within its parent. alignSelf overrides any option set by the parent with alignItems.</p><p>since <a href="https://reactnative.dev/docs/layout-props#alignself">alignSelf</a> is like alignItemsfor the stretch to work u will need to remove the fixed-width that the gold container has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*OSAH4FDpgcWpukj3A_rkhQ.gif" /><figcaption>alignSelf</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9293e7f0117b154d5d5a6f99bbe543e/href">https://medium.com/media/f9293e7f0117b154d5d5a6f99bbe543e/href</a></iframe><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a24dbe678e75" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/layout-with-flexbox-in-react-native-a24dbe678e75">Layout with FlexBox in React Native</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced aggregation pipeline with MongoDB ,Nodejs.]]></title>
            <link>https://medium.com/edonec/advanced-aggregation-pipeline-with-mongodb-nodejs-9bf023e74892?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bf023e74892</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[aggregation]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mongoose]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Mon, 24 May 2021 14:06:34 GMT</pubDate>
            <atom:updated>2021-05-30T21:11:26.598Z</atom:updated>
            <content:encoded><![CDATA[<h3>Example of aggregation pipeline with MongoDB ,Nodejs.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xsujBmHYgSR5JPtCrxdMQ.jpeg" /></figure><p>In this topic, I will be talking about the aggregation pipeline in MongoDB and how good they are with having an example of how to use them.</p><blockquote><strong>Introduction</strong></blockquote><p>The aggregation pipeline is a framework for data aggregation modeled on the concept of data processing pipelines. Documents enter a multi-stage pipeline that transforms the documents into aggregated results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*5ZlDfUiM_uHPW6KwvszS_g.png" /><figcaption>Aggregation pipeline</figcaption></figure><p>If you wanna read about what stages you can use <a href="https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/">check this link</a>.</p><blockquote><strong>Issue</strong></blockquote><p>I will be taking an example of a list of countries and manipulate them to a wanted result using the aggregations.</p><p>As you can see here, we will be having a list of countries in this form we will be manipulating it using the aggregations in so many ways so bear with me.</p><p><strong>1</strong>-grouping these countries with their region, returning a count of countries in that region and also showing what the countries are with their states and cities!</p><p><strong>2</strong>- Returning a list of countries in a form of Country, city.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*e4kTklL0-UA1Bmt6p3eZVg.png" /><figcaption>countrys list with states and their cities</figcaption></figure><blockquote><strong>1 </strong>— Grouping countries with their region.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7LcujT2ZETgehqal-o1kWA.png" /></figure><p><strong>Result :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*hl4cR5s-6LZP_e6MFV0JLw.png" /></figure><blockquote><strong>2</strong> — Returning a list of countries in a form of Country, city.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JxLlbB8HXvzSgAaLKKQQdA.png" /></figure><p><strong>Result :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*LOGDEhPwHWhxE8r8k0BRwg.png" /></figure><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bf023e74892" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/advanced-aggregation-pipeline-with-mongodb-nodejs-9bf023e74892">Advanced aggregation pipeline with MongoDB ,Nodejs.</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build React Native Reanimated 2 Switch from scratch]]></title>
            <link>https://medium.com/edonec/build-react-native-reanimated-2-switch-from-scratch-3be827c324f2?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3be827c324f2</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[switch]]></category>
            <category><![CDATA[reanimated]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Thu, 20 May 2021 08:50:55 GMT</pubDate>
            <atom:updated>2021-05-20T08:50:55.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*uZFhuBjFDOeBJlkTOBrffw.png" /></figure><p>So basically Android switch is not exactly like IOS in this topic we will try to create an IOS switch for both platforms cuz it simply animates better and looks better!</p><blockquote><strong>Project setup</strong></blockquote><p>In this example, we will simply clone reanimated playground and add more dependencies.</p><pre>git clone git@github.com:software-mansion-labs/reanimated-2-playground.git</pre><p>if u wanna set up reanimated from scratch check their <a href="https://docs.swmansion.com/react-native-reanimated/docs/installation">documentation</a>.</p><p>next, we will be adding <a href="https://www.npmjs.com/package/react-native-redash">react-native-redash</a> for some helpers and <a href="https://www.npmjs.com/package/react-native-size-matters">react-native-size-matters</a> for scaling.</p><pre>yarn add react-native-redash<br>yarn add react-native-size-matters</pre><blockquote><strong>Design and animations</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*cHQeQjNNR5-7TjUApHWCTw.gif" /></figure><p>This example shows up what we will be needing exactly.</p><ul><li>The first animation is the circle moves on the X-axis.</li><li>The second animation is the background change.</li><li>The third is that the circle width changes when the circle moves.</li><li>Let’s keep in mind that these animations work on press and drag.</li></ul><p><strong>Lets code!</strong></p><p>We will start with creating our switch views (container and a circle).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bbfc6aa2e4c564900490f64c0190f27/href">https://medium.com/media/3bbfc6aa2e4c564900490f64c0190f27/href</a></iframe><p>Now we have a circle that we can animate, so let’s start animating!</p><blockquote><strong>X-axis animation</strong></blockquote><p>First of all, we will create a state of toggle and a shared value and onChange prop callback that takes toggle as an argument and an initial value which is a prop as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc8f55dbaa2df208c7b3333e36f3c427/href">https://medium.com/media/dc8f55dbaa2df208c7b3333e36f3c427/href</a></iframe><p>Next, we will be creating 2 functions (OnPress, OnGestureEvent) so we will be using TapGestureHandler for OnPress and PanGestureHandler for OnGestureEvent because we will be pressing and dragging as well!</p><p><strong>onPress :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ed994a7adffb8574605d014c558a939/href">https://medium.com/media/5ed994a7adffb8574605d014c558a939/href</a></iframe><p>So basically what we did here is we checked if the state of our press event is ACTIVE or not. if it’s ACTIVE we will toggle and translateX our circle to the end of our switch container</p><p><strong>OnGestureEvent :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5a47bca9c288970508719d2634acd05/href">https://medium.com/media/d5a47bca9c288970508719d2634acd05/href</a></iframe><p>In this function, we will be using useAnimatedGestureHandler , This hook allows us for defining a number of worklets (e.g., onStart or onEnd), each of these will be used to process a different state in the gesture recognition process. we will also be using some helpers like clamp and snapPoint from redash.</p><p><strong>onStart :</strong></p><p>we will simply initialize our ctx with translateX.value which will be 0 or TRACK_CIRCLE_WIDTH in this case because we will be creating a snapPoint onEnd to determine where the circle will go 0 or TRACK_CIRCLE_WIDTH.</p><p><strong>onActive :</strong></p><p>we will give our translateX.value a <a href="https://react-native-redash-docs.netlify.app/math/clamp/">clamp</a> function that takes a node as a first argument and lowerBound argument and upperBound as the last argument.</p><p><strong>onEnd :</strong></p><p>onEnd in our case is we should determinate where the circle will snap so we need to know our snap point, so we will use SnapPoint function that takes the translateX position and the velocityX and calculate where the circle should snap, in the end, we need to change our toggle state and since we r not running this on JS thread we will be using runOnJs function to change the state depending on our snap point.</p><blockquote><strong>BackGround animation</strong></blockquote><p>In this case, we will simply use interpolateColor from reanimated so our input range will be [0, TRACK_CIRCLE_WIDTH] and output range is [“white” , backgroundColor( which will be passed as a prop to our component) ]</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19ee0ba0d32ff252eabdd7b4177c3dbb/href">https://medium.com/media/19ee0ba0d32ff252eabdd7b4177c3dbb/href</a></iframe><blockquote><strong>Circle width animation</strong></blockquote><p>So this animation will be applied to the circle width so we will interpolate on the width, input range will be from 0 to 3rd TRACK_CIRCLE_WIDTH to TRACK_CIRCLE_WIDTH and we will only change the width on the 3rd TRACK_CIRCLE_WIDTH and that’s it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2002973bacfccdd7904aafd46380872a/href">https://medium.com/media/2002973bacfccdd7904aafd46380872a/href</a></iframe><blockquote><strong>Final code .</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/daf4eb2d5622cb43f8d0ba23cb0719f1/href">https://medium.com/media/daf4eb2d5622cb43f8d0ba23cb0719f1/href</a></iframe><blockquote><strong>Component usage</strong></blockquote><pre>&lt;SwitchComponent backgroundColor=&quot;green&quot; onChange={console.log} /&gt;</pre><blockquote><strong>Result</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*MrUCPAV9b3D0CGc_G46xYA.gif" /></figure><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3be827c324f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/build-react-native-reanimated-2-switch-from-scratch-3be827c324f2">Build React Native Reanimated 2 Switch from scratch</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to type your weird objects with TypeScript.]]></title>
            <link>https://medium.com/edonec/how-to-type-your-weird-objects-with-typescript-e69d60c22648?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e69d60c22648</guid>
            <category><![CDATA[record-type]]></category>
            <category><![CDATA[keys]]></category>
            <category><![CDATA[values]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[objects]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Thu, 20 May 2021 08:50:21 GMT</pubDate>
            <atom:updated>2021-05-25T08:30:17.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0dSSHf-8_NqW4CDr2kxTg.png" /></figure><p>In this topic I will be showing you some tricks that you can use to type some weird objects using only utility types so what are the <a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeystype">utility types</a>?</p><p>TypeScript provides several utility types to facilitate common type transformations. <strong>These utilities are available globally.</strong></p><blockquote><strong>Issue1:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*gG-y7raeZ3kUHjh0vtZ4_A.png" /></figure><p>Let’s say that we have an object that looks like an array and we want to type it!</p><p>If you are familiar with TypeScript it’s obvious that we can type this object like the following!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*lIf4EXkUCkMzabFYdCEETg.png" /></figure><p>This is correct but what if we don’t know the length of our object! so if we add to our object a 4th index we will need to update our type as well :(.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*LzH4s4LzBElL79LnEm8Y7g.png" /></figure><p>So how exactly we can fix this issue because our weird object always has different indexes! we will be using the first utility type Record which I will be explaining of course!</p><h3>Record&lt;Keys,Type&gt;</h3><p>Constructs an object type whose property keys are Keys and whose property values are Type. This <strong>utility</strong> can be used to map the properties of a type to another type.</p><p>This is how Record type was created using generic types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuLBSqa51GTd5jtoLSMJnQ.png" /></figure><p>K will be extending a string or a number or a symbol! but we will be using [P in K] which means [P in number for example] and our second argument T will be your value type.</p><p>so that&#39;s exactly what we need!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*uykKUYMLbEA3caci5x8Ppg.png" /></figure><p>And that&#39;s it! our Type now will always accept objects that have keys as number and values as a string</p><blockquote><strong>Issue 2 :</strong></blockquote><p>Let’s try to type something more complex now! I will be taking this issue from <a href="https://stackoverflow.com/questions/47363288/creating-a-weird-type-in-typescript">StackOverflow </a>as an example!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*sLRnFQ6QUiGKFBbcnmASgQ.png" /></figure><p>So what we can see here is that the first key of our object can only be one of those 3 what I mean is with_boolean_prop or object_prop or muliple_options</p><p>a second argument is also an object of string as a key and value as a boolean or an object with key options and a value with an array of strings.</p><p>so we know exactly what to do now!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*mEyA5srSpcC4M69OQLAjfw.png" /></figure><p>We will start with typing the first key of our object with can be “with_boolean_prop” or “with_object_prop” or “with_muliple_options’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*vtTAW01i6k_jnAY_N2BQOA.png" /></figure><p>next, we will type options which is an array of strings.</p><p>And the rest of the type will be done with Record of course!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lw_80S4F4yUNnPxcwqyyLw.png" /></figure><p>So what we did here is the first object key is of firstKeyType that we created, next is also an object of string boolean or string option type that we also created! and that&#39;s it our type is now correct!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*PNejY47m6RAQtc-29JQhvQ.png" /></figure><h3>Conclusion :</h3><p>What we learned here is that u can solve any weird object typing using Record only!</p><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e69d60c22648" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/how-to-type-your-weird-objects-with-typescript-e69d60c22648">How to type your weird objects with TypeScript.</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement Redux-Saga in your React TypeScript Project.]]></title>
            <link>https://medium.com/edonec/implement-redux-saga-in-your-react-typescript-project-1d79c4a2d726?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d79c4a2d726</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux-saga]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Mon, 12 Apr 2021 10:46:50 GMT</pubDate>
            <atom:updated>2021-04-12T10:46:50.919Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lo9qzTGviRcOtvjYMOyuNQ.png" /></figure><p>In this article, I will be explaining what is redux-saga and how to implement it in your personal project so what is redux-saga?</p><blockquote><strong>Introduction</strong></blockquote><p><a href="https://redux-saga.js.org/"><em>Redux-Saga</em></a><em> </em>is a library that aims to make application side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache) easier to manage, more efficient to execute, easy to test, and better at handling failures.</p><p>The mental model is that a saga is like a separate thread in your application that’s solely responsible for side effects so basically it is a redux middleware, which means this thread can be started, paused, and canceled from the main application with normal redux actions, it has access to the full redux application state and it can dispatch redux actions as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-e3KouNos-rfx4GSKGzxnQ.png" /></figure><p>It uses an ES6 feature called Generators to make those asynchronous flows easy to read, write and test. By doing so, these asynchronous flows look like your standard synchronous JavaScript code. (kind of like async/await, but generators have a few more awesome features we need) , if you don&#39;t know much about generator functions I did write an article about it so <a href="https://medium.com/edonec/basics-of-generator-functions-in-javascript-cbadb01c680a">click here.</a></p><p>Enough introductions let&#39;s Code!</p><p><strong>Note</strong>: in the next steps I will be avoiding creating types therefore I will link a code sandbox for if you are looking for types or you want to skip.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fupbeat-grass-45pco%3Ffile%3D%2F_redux%2Factions%2FpostsActions%2FpostsActions.ts%3A0-618&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fupbeat-grass-45pco%3Ffile%3D%2F_redux%2Factions%2FpostsActions%2FpostsActions.ts%3A0-618&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F45pco%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/cacb3d61c371077173d1e335a0f38cb8/href">https://medium.com/media/cacb3d61c371077173d1e335a0f38cb8/href</a></iframe><blockquote><strong>Step 1 : Create React App</strong></blockquote><p>So basically we will be creating a React Typescript project first!</p><pre>yarn create react-app my-app --template typescript</pre><blockquote><strong>Step 2 : Install Redux / Redux-Saga</strong></blockquote><p>So we will be installing redux / redux-saga and their types since we are using TypeScript.</p><pre>yarn add redux react-redux redux-saga @types/react-redux @types/redux-saga</pre><blockquote><strong>Step 3 : Creating store</strong></blockquote><p>So we will be creating a file called Store.ts.</p><p><em>A store holds the whole </em><a href="https://redux.js.org/understanding/thinking-in-redux/glossary#state"><em>state tree</em></a><em> of your application.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDPjORv-igNRw8cjhI3VCw.png" /></figure><p>the store is the result of executing the <strong>createStore </strong>function that takes as a first argument our <strong>rootReducer </strong>which is a combination of all the reducer in our app and of course our middleware as a second argument.</p><p><strong>rootSaga</strong> will be all of the combinations of all sagas that we will have in our application.</p><blockquote><strong>Step 4 : Creating reducers</strong></blockquote><p>As usual, we will start with creating our file rootReduer.ts inside a folder called reducers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mj4QgHAF38maZO2S9UjiLA.png" /></figure><p>as u can see we already imported a postReducer so we will be creating that as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7WYOS_5gB91e9EqVG1k0Fw.png" /></figure><p>As you can see we will be creating 3 cases in this reducer: fetch, success and failure.</p><blockquote><strong>Step 5 : Creating Actions</strong></blockquote><p>After creating our reducer we know how to create our actions, so we will be doing the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mDjfuNEe_UpTMl5I5uQPrg.png" /></figure><p>So if you are familiar with using redux-thunk, you will be wondering how to call all these 3 actions at once! Therefore we will move to the next step of creating our Saga.</p><blockquote><strong>Step 6 : Creating Sagas</strong></blockquote><p>So here comes the fun part where we will be using generator functions to handle side effects from our fetch request instead of using callback functions in redux-thunk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-D0WeWVnVOSk8ahiTBisTw.png" /></figure><blockquote><strong>Step 7 : Creating our root Saga</strong></blockquote><p>this is where we will import all the sagas needed in our applications so we will do the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXFWRIqw3X5Utd3BzvwiUg.png" /></figure><blockquote><strong>Step 8 : Testing it out</strong></blockquote><p>So we will be adding our store with a provider in our index.tsx.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*FRz1PFz8v7YUDnll5uAgIw.png" /></figure><p>and finally using it in our app.tsx so we will fetch the data using useSelector hook and dispatching our action which is fetching posts using useDispatch hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75CXwx-WZWUbqpZJXPcL-w.png" /></figure><p>And that&#39;s it you can check the app in actions in the provided code sandbox in the Introduction!</p><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d79c4a2d726" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/implement-redux-saga-in-your-react-typescript-project-1d79c4a2d726">Implement Redux-Saga in your React TypeScript Project.</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with React Navigation in React Native TypeScript.]]></title>
            <link>https://medium.com/edonec/getting-started-with-react-navigation-in-react-native-typescript-f4343bc7e373?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4343bc7e373</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[params]]></category>
            <category><![CDATA[react-navigation]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[navigation]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Mon, 12 Apr 2021 10:45:48 GMT</pubDate>
            <atom:updated>2021-04-12T10:45:48.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*DERwITeac7CG1RoFMoSiYA.png" /></figure><blockquote><strong>Introduction</strong></blockquote><p>In this article, we will be learning about react-navigation and how to implement it in our React Native app, so first of all what is React navigation?</p><p>React navigation is a standalone library that allows developers to set up the screens of an app with a few lines of code.</p><blockquote><strong>Installation and setup</strong></blockquote><p>So obviously we will be installing react-navigation but it also relies on other packages so we will need to install them as well!</p><pre>yarn add @react-navigation/native <br></pre><pre>yarn add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context <a href="http://twitter.com/react">@react</a>-native-community/masked-view </pre><p>To finalize the installation of <a href="https://www.npmjs.com/package/react-native-gesture-handler">react-native-gesture-handler</a>, add the following at the top (make sure it&#39;s at the top and there&#39;s nothing else before it) of your entry file, such as index.js or App.js:</p><pre>import &#39;react-native-gesture-handler&#39;;</pre><p>we will also be needing to install @react-navigation/stack which provides a way for your app to transition between screens and manage navigation history. If your app uses only one stack navigator then it is conceptually similar to how a web browser handles navigation state — your app pushes and pops items from the navigation stack as users interact with it, and this results in the user seeing different screens. A key difference between how this works in a web browser and in React Navigation is that React Navigation’s stack navigator provides the gestures and animations that you would expect on Android and iOS when navigating between routes in the stack.</p><pre>yarn add @react-navigation/stack</pre><p><strong>So let&#39;s code!</strong></p><blockquote><strong>Basic navigation</strong></blockquote><p>We will start with creating 2 screens and try to navigate between them!</p><p>First of all, we need to wrap our application which is our App.js file with a NavigationContainer and the 2 created screens will be wrapped with a Stack Navigator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/250c89f72b26dd51a9c6f0f3402e9458/href">https://medium.com/media/250c89f72b26dd51a9c6f0f3402e9458/href</a></iframe><p>Next will be creating our 2 screens and we will try to navigate from Home to details screen!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3eb1dbfbdfdde644e0a307b3daa3b9af/href">https://medium.com/media/3eb1dbfbdfdde644e0a307b3daa3b9af/href</a></iframe><p>Each Screen component in your app is provided with the navigation prop automatically. that&#39;s why in our case we could use the navigation prop to navigate to DetailsScreen, u will find more information about it <a href="https://reactnavigation.org/docs/navigation-prop">here</a>.</p><blockquote><strong>Passing parameters to routes</strong></blockquote><p>First of all, we will be changing our types cuz now our DetailsScreen will be accepting params (itemId and otherParam) from HomeScreen so DetailsScreen will be changing from undefined to :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72c5d33c1525e4dcbcb5a74e1111b477/href">https://medium.com/media/72c5d33c1525e4dcbcb5a74e1111b477/href</a></iframe><p>Next, we will be passing those params as the following!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd00513cdc2ab131999f09e172be32bd/href">https://medium.com/media/cd00513cdc2ab131999f09e172be32bd/href</a></iframe><p>and we will be accepting those params in our DetailsScreen!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7eb82feced791bc5d834b9421c82d4b9/href">https://medium.com/media/7eb82feced791bc5d834b9421c82d4b9/href</a></iframe><p>and that&#39;s it , if u need more information about React navigation visit their <a href="https://reactnavigation.org/docs/getting-started">Docs</a>!</p><p><strong>Code source: </strong><a href="https://github.com/MoatezNG/React-Navigation/tree/main">https://github.com/MoatezNG/React-Navigation/tree/main</a></p><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote><em>This has been developed by myself at </em><a href="https://edonec.com/"><em>eDonec</em></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4343bc7e373" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/getting-started-with-react-navigation-in-react-native-typescript-f4343bc7e373">Getting started with React Navigation in React Native TypeScript.</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of Generator functions in JavaScript]]></title>
            <link>https://medium.com/edonec/basics-of-generator-functions-in-javascript-cbadb01c680a?source=rss-5d9b1e50e0f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbadb01c680a</guid>
            <category><![CDATA[yield]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[iterators]]></category>
            <dc:creator><![CDATA[Moatez Bejaoui]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 09:05:11 GMT</pubDate>
            <atom:updated>2021-03-03T09:05:11.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNOJTNQHey_8ZfkPQiYVXg.jpeg" /></figure><p>In this article, I will be showing you the basics of generator functions in JavaScript and how you can use them to improve your code.</p><p><strong>What is a generator function?</strong></p><h3>Introduction</h3><blockquote><strong>Generator function</strong>.</blockquote><p>A generator is a function that <strong>can stop midway</strong> and then continue <em>from where it stopped. </em><strong>In short, a generator <em>appears</em> to be a function, but it <em>behaves</em> like an iterator.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*r9VkvgSUGciAQmzntuxB3Q.png" /></figure><p>So let&#39;s code!</p><p>We will be creating a generator function in this example.</p><pre>function* generatorFunction() {<br>  yield 1;<br>  yield 2;<br>  yield 3;<br>}</pre><p>Basically, yield is the return of a generator function in our case this function will be giving us 3 values of 1 &amp; 2 &amp; 3, next we need to retrieve a generator from this function like the following.</p><pre>const generator = generatorFunction();</pre><p>if we log our generator it will be giving us a generator object</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*x4KkDUISPJXjs8rE2GP-8A.png" /></figure><p>as you can see there is a next method that going to allow you to retrieve the values that you provided with yield but in an object that has <strong>{value: “the value”, done: “if the function is done or not”.}</strong></p><p>so here we will be logging this next() 4 times and let&#39;s see what happens.</p><pre>const generator = generatorFunction();</pre><pre>console.log(generator.next());<br>console.log(generator.next());<br>console.log(generator.next());<br>console.log(generator.next());</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*r2URkGABFVYtAUwAyb7u2g.png" /></figure><p>as we can see the yield ends at 3 so the 4&#39;th log will have an undefined value and done will be true.</p><p>Since our generator object implements the <strong>iterator </strong>and<strong> the iterable protocol</strong></p><p>so I will be logging our generator object once again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*eN30nL94TiA3HMsWbaFUhw.png" /></figure><p>if you need to know more about iterable protocol <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Iteration_protocols"><strong>click here</strong></a></p><p>A generator function simplifies the use of an iterator like the following</p><pre>for (const n of generatorFunction()) {<br>  console.log(n);<br>}</pre><p>And the result will be 1 &amp; 2 &amp; 3.</p><h3>Q&amp;A</h3><p>If something doesn’t work as expected or needs more details, just drop a comment below :) Happy coding!</p><blockquote>This has been developed by myself at <a href="https://edonec.com/">eDonec</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbadb01c680a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/edonec/basics-of-generator-functions-in-javascript-cbadb01c680a">Basics of Generator functions in JavaScript</a> was originally published in <a href="https://medium.com/edonec">eDonec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>