<?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 Alien Padilla Rodriguez on Medium]]></title>
        <description><![CDATA[Stories by Alien Padilla Rodriguez on Medium]]></description>
        <link>https://medium.com/@alien-padilla?source=rss-1e33c280d343------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*pRWV-tX2kDfJyKmTENHRdQ.jpeg</url>
            <title>Stories by Alien Padilla Rodriguez on Medium</title>
            <link>https://medium.com/@alien-padilla?source=rss-1e33c280d343------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 23:53:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alien-padilla/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[Creating a React Toolchain from Scratch. Part2.]]></title>
            <link>https://alien-padilla.medium.com/creating-a-react-toolchain-from-scratch-part2-6b70bc364535?source=rss-1e33c280d343------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b70bc364535</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[toolchain]]></category>
            <category><![CDATA[babel]]></category>
            <dc:creator><![CDATA[Alien Padilla Rodriguez]]></dc:creator>
            <pubDate>Mon, 24 Jan 2022 01:24:49 GMT</pubDate>
            <atom:updated>2022-01-24T01:24:49.267Z</atom:updated>
            <content:encoded><![CDATA[<p>Some time ago in an interview, the interviewer asked me about Clean Code, Good Practices and some kind of questions about how to keep our code understandable and maintainable for everyone in the team, so one tool come to my mind: “Eslint”. Yes, yes, I know that “Clean Code” is more than code format and envolve a lot of rules that dictate the way to keep a code, clean. But Eslint allow us to follow the standard conventions and ensure the same code style throught all the project and this contributes with the code readability and understability, and they are part of the clean code concept because a clean code is a code easy to understood and maintain by a developer other than its original autor.</p><p>In this second part, I want to show you how to configure Eslint in our toolchain created from scratch and it is the second part of a serie of tutorials. Here you can find the <a href="https://alien-padilla.medium.com/creating-a-react-toolchain-from-scratch-36cab8827c58">Part#1</a>. So, let me started.</p><p><strong>Step #1.</strong> Clone the repository <a href="https://github.com/alienpr84/react-toolchain-scratch">Creating a React toolchain from scratch</a>, to do this we are going to run the command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f47002e78ce30a40df85f5682c9c172/href">https://medium.com/media/9f47002e78ce30a40df85f5682c9c172/href</a></iframe><p>go to the folder “<strong>react-toolchain-scratch</strong>” on your Command Line Terminal (CLT) and install de project’s dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4816d2602b163fcc34960b93e3f4476/href">https://medium.com/media/e4816d2602b163fcc34960b93e3f4476/href</a></iframe><p>the result must be the project made in the first part of this tutorial series, if you want to test if the project is working correctly you can run de script</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abbdcdecde78ff476ec9592901722b6a/href">https://medium.com/media/abbdcdecde78ff476ec9592901722b6a/href</a></iframe><p>a new tab of your default browser is open</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b70bc364535" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a React Toolchain from Scratch. Part1.]]></title>
            <link>https://alien-padilla.medium.com/creating-a-react-toolchain-from-scratch-36cab8827c58?source=rss-1e33c280d343------2</link>
            <guid isPermaLink="false">https://medium.com/p/36cab8827c58</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[babel]]></category>
            <dc:creator><![CDATA[Alien Padilla Rodriguez]]></dc:creator>
            <pubDate>Sat, 15 Jan 2022 17:02:04 GMT</pubDate>
            <atom:updated>2022-01-23T13:45:26.585Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TTxs4ZjqimQv2LoL" /><figcaption>Photo by <a href="https://unsplash.com/@knowniko?utm_source=medium&amp;utm_medium=referral">Stefano Ciociola</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When we start a new React’s project we usually pick one of the most popular toolchains that exist in the React ecosystem:</p><ul><li><a href="https://create-react-app.dev/"><strong>Create React App</strong></a> (single page application)</li><li><a href="https://nextjs.org/"><strong>Nextjs</strong> </a>(server side application with nodejs)</li><li><a href="https://www.gatsbyjs.com/"><strong>Gatsby</strong> </a>(static contet-oriented website)</li></ul><p>but this toolchains bring with them a lot of implementation that you don’t use or you don’t want to use. So, what about if you want to make your own toolchain? This tutorial is about how to make your react toolchain, but we are going to divide it in 4 parts:</p><p><strong>1-</strong> Creating a React Toolchain from scratch with vanilla JavaScript.</p><p><strong>2-</strong> Adding Eslint.</p><p><strong>3-</strong> Adding Jest.</p><p><strong>4-</strong> Support Typescript.</p><h4>Part 1. Creating a React Toolchain from scratch with vanilla JavaScript.</h4><p>According to the <a href="https://reactjs.org/docs/create-a-new-react-app.html#creating-a-toolchain-from-scratch">React documentation</a> for build our toolchain we need:</p><ul><li>A <strong>package manager</strong>, such a <a href="https://yarnpkg.com/">yarn </a>or <a href="https://www.npmjs.com/">npm</a>. It lets you to use third-party packages .</li><li>A <strong>bundler</strong>, such a <a href="https://webpack.js.org/">Webpack </a>or <a href="https://parceljs.org/">Parcel</a>. It lets you to write modular code and bundle it together into small packages to optimize load time.</li><li>A <strong>compiler</strong>, such <a href="https://babeljs.io/">Babel</a>. It lets you to write modern JavaScript code that still works in older browsers.</li></ul><p>Well, is time to start. So we are going to follow the nexts steps:</p><p><strong>Step #1</strong> <em>Init the project</em></p><ul><li>Create a new folder, for this example we are going to name it <strong>react-toolchain-scratch.</strong></li><li>Open the Command Line Terminal (CLT) in the folder directory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*DdZgln0nN2iOV_yu5PGFXw.png" /><figcaption>Command Line Terminal open in the react-toolchain-scratch directory</figcaption></figure><p>For init a new project we are going to run:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d66e2e6c29d3dbe6000526dcf0dec209/href">https://medium.com/media/d66e2e6c29d3dbe6000526dcf0dec209/href</a></iframe><p>this command is going to create a new package.json that contain information about the project. The <strong>-y</strong> option avoid us to fill out all the questions about the project and gives us a quick start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*B-mW1cLLLIoCjnEz5zfV-w.png" /></figure><p><strong>Step #2</strong> <em>Create folder structure</em></p><p>Into our <strong>react-toolchain-scratch </strong>folder we are going to create the follow folders and files structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*oChDZckAkxSFDTMmhUl8RQ.png" /><figcaption>Folder structure on Visual Studio Code</figcaption></figure><p><strong>Note:</strong> I use Visual Studio Code to write my code, but you can use the code editor of your preference.</p><p><strong>src </strong>— Contain all our source code.</p><p><strong>public </strong>— Contain all our public content, here we can have the assets folder with images and other content, and the index.html.</p><p><strong>index.html</strong> —Our application is going to be rendered and embedded into this file.</p><p><strong>App.jsx </strong>— Is the aplication itself. Usually here we put the router or our layout component, all depend of our project’s configuration and structure.</p><p><strong>index.jsx</strong> — Is the entry point of our application, here the App is rendered.</p><p>Now we are going to put some code into these files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df9182c45b85e02704b8005bcb9880fe/href">https://medium.com/media/df9182c45b85e02704b8005bcb9880fe/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3ba02bffd1e6f7f1f257181fff015ed/href">https://medium.com/media/f3ba02bffd1e6f7f1f257181fff015ed/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35a3b9884f3acb57251c6dcc0e4d3868/href">https://medium.com/media/35a3b9884f3acb57251c6dcc0e4d3868/href</a></iframe><blockquote><strong>Note: </strong>“<em>StricMode” is a tool for highlighting potential problems in an application. It activates aditional checks and warnings for its descendants.</em></blockquote><p><strong>Step #3</strong> <em>React</em></p><p>In order to use React we need to install it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d82ab49421cf23798c1d485a0c5111a/href">https://medium.com/media/5d82ab49421cf23798c1d485a0c5111a/href</a></iframe><p><a href="https://reactjs.org/"><strong>react </strong></a>— Is a JavaScript library for building user interfaces.</p><p><a href="https://reactjs.org/docs/react-dom.html"><strong>react-dom</strong></a> — Is a library that allow React to interact with the dom.</p><p><strong>Step #4</strong> <em>Babel configuration.</em></p><p>Babel is mainly used to transform ECMAScript 2015+ into a backwards compatible versions of JavaScript in current and older browsers or environments. So, at the end when we parse and compile our code with Babel we are going to have a code that can be used in newer and old browser or JavaScript environments. That is it.</p><p>So, we are going to install our babels presets that is going to be used on the transpilation proccess:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d331dc16c7601e98bdb2be771b1941d/href">https://medium.com/media/0d331dc16c7601e98bdb2be771b1941d/href</a></iframe><p><a href="https://babeljs.io/docs/en/babel-preset-env"><strong>@babel/preset-env </strong></a><strong>—</strong> Takes any <a href="https://babeljs.io/docs/en/babel-preset-env#targets">target environments you’ve specified</a> and checks them against its mappings to compile a list of plugins and passes it to Babel.</p><p><a href="https://babeljs.io/docs/en/babel-preset-react"><strong>@babel/preset-react</strong> </a>— Enables Babel to parse and compile the jsx sintax.</p><p><a href="https://babeljs.io/docs/en/babel-core"><strong>@babel/core</strong></a><strong> — </strong>It is the core of Babel.</p><p><strong>Step #5 </strong><em>Install Webpack.</em></p><p>We need to install a bundler, we have some options here: <a href="https://webpack.js.org/">Webpack</a>, <a href="https://browserify.org/">Browserify</a>, <a href="https://parceljs.org/">Parcel</a> and more. For this project we are going to use <a href="https://webpack.js.org/">Webpack </a>because is the most popular. To install webpack we need to run the following commands in your CLT:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7010d0177a3f7d741b267ea32550fce8/href">https://medium.com/media/7010d0177a3f7d741b267ea32550fce8/href</a></iframe><p><a href="https://webpack.js.org/"><strong>webpack</strong> </a>— Is the core of webpack.</p><p><a href="https://webpack.js.org/api/cli/"><strong>webpack-cli</strong> </a>— Provide a flexible set of commands for developers to improve the setup of custom webpack configuration.</p><p><a href="https://webpack.js.org/configuration/dev-server/"><strong>webpack-dev-server</strong> </a>— Gives you a single command that starts a static server with build-in live reload. Needs of webpack-cli to run correctly.</p><p><a href="https://www.npmjs.com/package/webpack-merge"><strong>webpack-merge</strong></a><strong> </strong>— Allow us to combine webpack’s configuration. It lets us to combine the webpack common configuration with the develop or production configuration, this is very useful because avoid repeat unnecesary configuration or make a big webpack configuration with ternary expression.</p><p><a href="https://webpack.js.org/plugins/html-webpack-plugin/"><strong>html-webpack-plugin</strong> </a>— This plugin generate a HTML5 for you that include all your webpack bundles in the body using &lt;script&gt;&lt;/script&gt; tag.</p><p><a href="https://www.npmjs.com/package/@pmmmwh/react-refresh-webpack-plugin/v/next"><strong>@pmmmwh/react-refresh-webpack-plugin</strong></a><strong> — </strong>This plugin enable fast refresh also known as a hot reload. This feature allow you to see the change made in the code reflected instantly in the browser.</p><p><a href="https://www.npmjs.com/package/babel-loader"><strong>babel-loader</strong></a> — Allow us to use Babel with Webpack.</p><p><a href="https://webpack.js.org/loaders/style-loader/"><strong>style-loader</strong></a> — Takes the css imported in the JavaScript files and injects them as &lt;style&gt;&lt;/style&gt; into the DOM</p><p><a href="https://webpack.js.org/loaders/css-loader/"><strong>css-loader</strong></a> — Help Webpack to collect CSS from all the css files referenced in the application and put it into a string.</p><p><a href="https://v4.webpack.js.org/loaders/file-loader/"><strong>file-loader</strong></a> — Resolves <strong>import /</strong> <strong>require </strong>in a file into a url and emits the file in the output directory</p><p><strong>Step #6</strong> <em>Configure Webpack</em></p><p>A good practice is to create individual config file for every environment and another one for a common configuration in order to avoid to repeat code, so we are going to have these 3 webpack config files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*xjBHcWvg2xyvtYnVuLVPQQ.png" /><figcaption>webpack confing files</figcaption></figure><p><strong>webpack.common.js </strong>— Contain the webpack common configuration.</p><p><strong>webpack.dev.js </strong>— Contain the webpack development configuration.</p><p><strong>webpack.prod.js </strong>— Contain the webpack production configuration.</p><p>Now we are going to put some code into these files and explain it in details:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e6c4791c208b9551191c65f992916b5/href">https://medium.com/media/9e6c4791c208b9551191c65f992916b5/href</a></iframe><p>In this config file we are going to put all the common configuration.</p><ul><li><strong>Line #1.</strong> The join function allow us to normalize the path directory, this is very important because linux, macos and window use diferents delimiters (\ or /) in their paths.</li><li><strong>Line #4</strong>. Webpack is going to start to bundle the application from this file that is going to be the entry point of our application.</li><li><strong>Line #6.</strong> Tell webpack what directories would be searched when resolving modules.</li><li><strong>Line #7.</strong> Attemp to <a href="https://webpack.js.org/configuration/resolve/">resolve</a> these extensions in order. If multiple file share the same name but have different extensions, webpack will resolve the first one listed.</li><li><strong>Line #10.</strong> Here we declare the <a href="https://webpack.js.org/concepts/loaders/">loaders</a>. The loaders are transformation that are applied to the source code of a module. Is recomended to combine style-loader and css-loader.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ac552353a28d3adab8470d9048f6c9c/href">https://medium.com/media/5ac552353a28d3adab8470d9048f6c9c/href</a></iframe><ul><li><strong>Line #8. </strong>Providing the mode configuration option tells webpack to use its build-in optimizations accordingly.</li><li><strong>Line #9.</strong> Because JavaScript can be written for both server or browser, offers multiple deployment targets (node or web).</li><li><strong>Line #10.</strong> Some development options are declare as the port and that the server has hot reload, this is posible thanks to <strong>webpack-dev-server</strong> and <strong>@pmmmwh/react-refresh-webpack-plugin, </strong>because both are using behind scenes<strong>.</strong></li><li><strong>Line #14</strong>. Here we declare the plugins to be used, in our case we are going to use: <strong>html-webpack-plugin</strong> and <strong>@pmmmwh/react-refresh-webpack-plugin. </strong>Both were explained above.</li><li><strong>Line #22.</strong> This rule allow us to check the <strong>.js </strong>and <strong>.jsx </strong>files and apply them the declared presets for the correct transpilation.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49cdbcf7384280fa54c60b7e28b31c5c/href">https://medium.com/media/49cdbcf7384280fa54c60b7e28b31c5c/href</a></iframe><p>This webpack production config is for generate the final code to be served by our server.</p><ul><li><strong>Line #8.</strong> Generate source-map files. Source maps are basically files generated while building for production that can help revert a combined/minified file to the original state.</li></ul><p><strong>Note:</strong> source-map is only downloaded if we have open the browser developer tools.Therefore shipping source maps to production will not affect your end-users and will help your team with the debugging.</p><ul><li><strong>Line #16.</strong> Here we set the configuration for our ouput folder, in this folder we are going to get have all our transpiled code and ready to be served by our server.</li></ul><p><strong>Step #7</strong> <em>Polyfills</em></p><p>A polyfill is a piece of code (usually Javascript on the web) used to provide modern functionality on older browsers that do not natively support it.</p><p>First of all we are goin to run this code in your CLT:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb6d3d339f0879311eeef9e7f09e5f89/href">https://medium.com/media/cb6d3d339f0879311eeef9e7f09e5f89/href</a></iframe><p><a href="https://github.com/zloirock/core-js"><strong>core-js</strong></a> — Modular standard library for JavaScript. Includes polyfills for <a href="https://github.com/zloirock/core-js#ecmascript">ECMAScript up to 2021</a>: <a href="https://github.com/zloirock/core-js#ecmascript-promise">promises</a>, <a href="https://github.com/zloirock/core-js#ecmascript-symbol">symbols</a>, <a href="https://github.com/zloirock/core-js#ecmascript-collections">collections</a>, iterators, <a href="https://github.com/zloirock/core-js#ecmascript-typed-arrays">typed arrays</a>, many other features, <a href="https://github.com/zloirock/core-js#ecmascript-proposals">ECMAScript proposals</a>, <a href="https://github.com/zloirock/core-js#web-standards">some cross-platform WHATWG / W3C features and proposals</a> like <a href="https://github.com/zloirock/core-js#url-and-urlsearchparams">URL</a>. You can load only required features or use it without global namespace pollution.</p><p><a href="https://www.npmjs.com/package/whatwg-fetch"><strong>whatwg-fetch</strong></a><strong> </strong>— Is a polyfill that implements a subset of the standard <a href="https://fetch.spec.whatwg.org/">Fetch specification</a>, enough to make fetch a viable replacement for most uses of XMLHttpRequest in traditional web applications.</p><p><a href="https://www.npmjs.com/package/raf"><strong>raf</strong> </a>— RequestAnimationFrame polyfill for node and the browser.</p><p>Then we are going to create a new file named <strong>polyfills.js</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*-wqLXRLiS1rZI7_FaoxGfg.png" /><figcaption>polyfills.js</figcaption></figure><p>and put this piece of code into it</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9d86158dc3ce8709634d986b523907f/href">https://medium.com/media/e9d86158dc3ce8709634d986b523907f/href</a></iframe><p>now import it on the top of the<strong> index.jsx</strong> file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jUbqepQXLqZ2SnMsoh-dEA.png" /><figcaption>index.jsx with polyfills included</figcaption></figure><p><strong>Step #8</strong> <em>Scripts</em></p><p>Now is time to create our scripts for develop and production:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d015b52fa26fd80b6daf7e2dd5d2efe6/href">https://medium.com/media/d015b52fa26fd80b6daf7e2dd5d2efe6/href</a></iframe><p>For development we can use de <strong>dev</strong> script, so you can run it writing in the CLT <strong>npm run dev, </strong>this open a new tab in your current default browser and use the configuration of our <strong>webpack.dev.js </strong>file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7V9_6Yv6dql-J4OqZvh5EQ.png" /><figcaption>Project compiled</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*xMJ4dYznluBQEenvM2IVCw.png" /><figcaption>Project open in a new tab</figcaption></figure><p>For production we can run the script <strong>npm run build </strong>that is going to generate a folder named dist as we set in our <strong>webpack.prod.js</strong> configuration file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BiIE7WzuPmhGybQEuQdMlw.png" /><figcaption>Project’s code generated</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*7uPOdJvySHMJgipFkljEiA.png" /><figcaption>dist folder</figcaption></figure><p>If you want to test it you can use the live server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhTezK30LeCD37ofKvh7Ow.png" /><figcaption>Live Server</figcaption></figure><p>and then run the <strong>index.html</strong> file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*cthrMejHlh0YZq8cENc8uQ.png" /><figcaption>Running our project with Live Server</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*GmYu8HNoo6CQioFQZLkX_w.png" /><figcaption>Project of production open in a new tab</figcaption></figure><p><strong>Git Repository</strong><br>- <a href="https://github.com/alienpr84/react-toolchain-scratch">React toolchain from scratch with vanilla JavaScript</a>.</p><p><strong>Git Branch<br></strong>- example1 (Here you have an example with some components + css + image)</p><h4>Conclusions</h4><p>With this small tutorial I wanted to show you how to make your own react toolchain from scratch step by step according to <a href="https://reactjs.org/docs/create-a-new-react-app.html#creating-a-toolchain-from-scratch">React documentation</a>. I don’t encompass all the posibilities of configuration that you can make with webpack, I only used the most common and necessary configuration for our small project, but there are a lot of configuration that can be done. I hope that this tutorial be useful for you. Enjoy it….. Happy code :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36cab8827c58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grab and Pull Carousel Slides on Bootstrap.]]></title>
            <link>https://alien-padilla.medium.com/grab-and-pull-carousel-slides-on-bootstrap-dbe433ff3af7?source=rss-1e33c280d343------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe433ff3af7</guid>
            <category><![CDATA[bootstrap]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[slides]]></category>
            <category><![CDATA[carousel]]></category>
            <dc:creator><![CDATA[Alien Padilla Rodriguez]]></dc:creator>
            <pubDate>Fri, 02 Apr 2021 13:44:13 GMT</pubDate>
            <atom:updated>2021-04-10T13:03:17.120Z</atom:updated>
            <content:encoded><![CDATA[<p>Some times we need to add a little behavior to our Bootstrap carousel like for example a grab and pull slides feature. Bootstrap by default doesn’t have this behavior and maybe you as me think about just to change the carousel by other one that support this feature like <a href="https://kenwheeler.github.io/slick/">Slick Carousel</a>, for example. But to me doesn’t was possible just changed because I’ve need to keep compatibility with other dependencies and didn’t make sense to me do a big change only to support this little behavior, so I implemented this little code in order to support this feature and I want to share it with you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*68tgkhTvyyzBspwb4GpxAg.gif" /><figcaption>Grab and Pull Bootstrap Slide Carousel on Desktop</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*5tpsQ7ZEDFD_i8P9cCSb1A.gif" /><figcaption>Grab and Pull Bootstrap Slide Carousel on Mobile</figcaption></figure><h4><strong>Laguages, libraries and framework used:</strong></h4><ul><li>Javascript</li><li>CSS</li><li>HTML</li><li><a href="https://jquery.com/">JQuery (v3.6.0)</a></li><li><a href="https://hammerjs.github.io/">Hammerjs (v2.0.7)</a></li><li><a href="https://getbootstrap.com/docs/4.6/getting-started/introduction/">Bootstrap (v4.6.0)</a></li></ul><h4>Well, hands to work:</h4><p><strong>1- HTML code</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/226f25342aca7303209a1ea10eb3418f/href">https://medium.com/media/226f25342aca7303209a1ea10eb3418f/href</a></iframe><p>The important here to highlight is the data attribute: <strong>data-touch</strong> on line 15. Setting this data attribute to<strong> false</strong> is very important because remove the swipe from Bootstrap that provoke a side effect in the slide’s transition.</p><p><strong>2- CSS code</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a66e989ea5935fc19a2a00c51d53b535/href">https://medium.com/media/a66e989ea5935fc19a2a00c51d53b535/href</a></iframe><p>The most important css sytles here are the <strong>.visible-carousel-item</strong> class on the 58 line and the styles from 65 to 73 line, the first one allow us to make the prev and next item visible on the carousel and the second one avoid to drag the image and anchor element with undesirable results, as you can see in this image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c754FauzKEcWbZOOzkAf4A.png" /><figcaption>Image drag effect when we to try grab and pull the slide on the carousel</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBjeaDrz4RZcg_6MDaZRhw.png" /><figcaption>Anchor drag effect when we to try grab and pull the slide on the carousel</figcaption></figure><h4>3- Javascript code. Well, is time to become serious</h4><p>Now is time to write the javascript code. So first of all we are going to declare our global variables.</p><h4><strong>Global Variables</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e9535f5cbeb997c763a46142b132cea/href">https://medium.com/media/1e9535f5cbeb997c763a46142b132cea/href</a></iframe><p>Explanation:</p><p>The three firts variables (<strong>$carousel</strong>, <strong>$carouselInner</strong>, <strong>$carouselItems</strong>) are JQuery object instancies, the <strong>carouselInnerWidth</strong> has the carousel’s width, the <strong>startXCoord</strong> is going to allow us to save the start position where you started to grab the slide, the <strong>imageLeftCoord</strong> reflect how much you move the cursor respect to the left and the <strong>lastMoveType</strong> allow us to know the moviment direction (right or left). A good practice in javascript respect to the resize event is avoid to execute the code bind to this event in each resize event, so the idea behain this is only execute the code when the resize was done, so the <strong>resizeTimeout</strong> is going to save the id of the setTimeout function and c<strong>arouselHammer</strong> is going to save the hammer instance.</p><h4><strong>Responsive carousel support</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bad80f35f0126d6440ae28caae4d387/href">https://medium.com/media/6bad80f35f0126d6440ae28caae4d387/href</a></iframe><p>Explanation:<br>In order to support a responsive carousel we are going to keep updated the <strong>carouselInnerWidth </strong>variable.</p><h4><strong>Starting Carousel cycle</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/927552e215c1bb01ffda76f56fd397c9/href">https://medium.com/media/927552e215c1bb01ffda76f56fd397c9/href</a></iframe><p>Explanation:<br>Can be sound crazy and at first time you could be inclinated to use <br><strong>data-ride=carousel </strong>to init the carousel cycle; <strong>please don’t do it</strong>, at least for Bootstrap 4.6 version, for some reasons you are not be able to pause the carousel cycle forward; is for this reason that I use the Bootstrap’s method carousel.</p><h4>Hammer events on carousel and helper functions</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d54d8c673b856b53ccebfc964186f69/href">https://medium.com/media/1d54d8c673b856b53ccebfc964186f69/href</a></iframe><p>I think the most important about this code is know the events that we use, so here you have a brew explanation.</p><blockquote><strong>Panstart</strong> is when you do click and start to move the cursor over the carousel (for this case).</blockquote><blockquote><strong>Pantleft</strong> is when a Panstart was done and you move the mouse to the left.</blockquote><blockquote><strong>Panright</strong>is when a Panstart was done and you move the mouse to the right.</blockquote><blockquote><strong>Panend</strong> is whe a Panstart and a Panleft or Panright was done and then you stop pressing the mouse over the carousel (for this case).</blockquote><blockquote><strong>Press </strong>and <strong>Pressup</strong> are the same as the mouse event. A mouse click is considered a Press event for Hammerjs, if the mouse isn’t moved and transcur a little time (250 miliseconds).</blockquote><p>The rest of the code is very auto explantory an ease to understand if you know the events mentioned above.</p><p>I hope that you enjoy and find this solution useful. Here you have the github repository link to two branch, the first one is related to this explanation and the second one is a solution when the first child of element the carousel-item is an anchor element that envolve the whole slide:</p><p><a href="https://github.com/alienpr84/grab-and-pull-bootstrap4-carousel/tree/grab-and-pull">1- Grab and Pull Bootstrap Slide Carousel</a><br><a href="https://github.com/alienpr84/grab-and-pull-bootstrap4-carousel/tree/carousel-item-image-with-anchor-element">2- Grab and Pull Bootstrap Slide Carousel with an Anchor as element parent.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe433ff3af7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope, Lexical Scope and Closure in JavaScript]]></title>
            <link>https://alien-padilla.medium.com/scope-lexical-scope-and-closure-in-javascript-d225da6cda83?source=rss-1e33c280d343------2</link>
            <guid isPermaLink="false">https://medium.com/p/d225da6cda83</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Alien Padilla Rodriguez]]></dc:creator>
            <pubDate>Tue, 17 Sep 2019 19:43:22 GMT</pubDate>
            <atom:updated>2019-09-18T20:56:14.139Z</atom:updated>
            <content:encoded><![CDATA[<p>When you start to learn a programing language is very important to know about the scope of variables and functions, no matter if you know others programing languages or not, I mean, the scope of variables and functions are the first thing that you need to know. In this article we want to discuss the concepts of “scope”, “lexical scope” and “closure” in JavaScript including examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d2NAzut9z3Dg-XqMUmjrFQ.jpeg" /><figcaption>The road</figcaption></figure><h3><strong>What’s Scope</strong></h3><p>Scope define where the variables and functions are available for use in your program. In javascript there are three scopes: Global Scope, Function Scope (Local Scope) and Block Scope.</p><h4>1- Global Scope.</h4><p>It is global scope when the variable or function is declared outside a function. This means that you can access and use this function or variable in any place in your program.</p><p>Example:</p><pre><em>/*<br> In this case the variable &quot;message&quot; and the <br> function &quot;computer&quot; have global scope because they <br> were declared outside a function.<br>*/</em></pre><pre>var message = &#39;Hi, I am a computer&#39;;</pre><pre>function computer() {<br>   console.log(&#39;RAM Capacity: 16gb&#39;);<br>}</pre><pre>/* <br> This meaning that I can access and use them in any<br> place in my program. <br>*/</pre><pre>function showData() {<br>   console.log(message);<br>   computer();<br>}</pre><pre>var myComputer = {<br>   sayMessage: message,<br>   ram: &#39;16gb&#39;,<br>   hdd: &#39;1tb&#39;<br>};</pre><pre>showData();</pre><pre>console.log(`${myComputer.sayMessage} and I have RAM: ${myComputer.ram} and HDD: ${myComputer.hdd}.`);</pre><h4>2- Function Scope. (Local Scope)</h4><p>It is function scope when the variable or function is declared inside a function. This means that you can access and use them only inside the function where they were declared and you can’t access or use them outside.</p><p>Example:</p><pre><em>/*<br> In this case the variable &quot;ram&quot;, the function &quot;message&quot; and <br> &quot;ramInfo&quot; have function scope because they are declare inside a <br> function, in this case &quot;computer&quot;. This meaning that you can <br> access and use them only inside the function computer and you <br> can&#39;t access them outside the computer function.<br>*/</em></pre><pre>function computer() { <em>// global scope</em></pre><pre>   var ram = 24; <em>// function scope</em></pre><pre>   function message() { // function scope<br>      return &#39;Hi my RAM capacity is: &#39;;<br>   }<br> <br>   function ramInfo() { <em>// function scope</em><br>      console.log(`${message()} ${ram}gb.`);<br>   }<br> <br>   ramInfo(); <br>}</pre><pre>computer();</pre><pre><em>/* <br> If you try to access the variable and the functions outside the  <br> function computer you go to get an error.<br>*/</em></pre><pre>console.log(ram); <em>// Uncaught ReferenceError: ram is not defined</em><br>message(); <em>// Uncaught ReferenceError: message is not defined</em></pre><h4>3- Block Scope.</h4><p>When you use the keywords “let” or “const” for declare a variable, it is only exist in the block that it was declared, so you can access and use it only there.</p><p>Example:</p><pre><em>/*<br> You can access or use the variable only inside the block where it<br> was declared. So, you can&#39;t access or use the variable outside the<br> block where it was declared.<br>*/</em></pre><pre>{ <br>   let message = &#39;Hello, I am here.&#39;; <em>// block scope</em><br>   console.log(message);<br>} <em>// block limit for &quot;message&quot;</em></pre><pre>console.log(message); <em>// Error: message is not defined</em></pre><pre>if(true) {<br>   const counter = 10;</pre><pre>  for(let i=0; i&lt;counter; i++) { <br>      console.log(i);<br>  }<br>} <em>// block limit for &quot;counter&quot;</em></pre><pre>console.log(counter); <em>// Error: counter is not defined</em></pre><h3>Lexical Scope</h3><p>The lexical scope of function is the function scope of the outer function, if the function doesn’t have outer function, then its lexical scope is the global scope. That is the same:</p><p><strong>function scope of outer function === lexical scope of inner function</strong></p><p>Example:</p><pre><em>/* <br> How the &quot;computer&quot; function doesn&#39;t have outer function then its <br> lexical scope is the global scope. So, global scope === lexical <br> scope of &quot;computer&quot; function.<br>*/</em></pre><pre>function computer() {<em> // outer function</em><br>  var ram = &#39;16gb&#39;;<br>  var hdd = &#39;2tb&#39;;<br> <br>   <em>// computer function scope === lexical scope of showData function</em><br>   return function showData() { <em>// inner function </em><br>    console.log(`This computer has: RAM = ${ram} and HDD = ${hdd}`);<br>   }<br>}</pre><h4>Closure</h4><p>When you know what is “Scope” and “Lexical Scope” in JavaScript, then is easy to understand what is Closure:</p><p>Closure is when a function can remember and access its Lexical Scope event when it’s invoked outside its Lexical Scope.</p><p>Easy ….truth?</p><p>Example:</p><pre><em>/* <br> How the &quot;computer&quot; function doesn&#39;t have outer function then its <br> lexical scope is the global scope. So, global scope === lexical <br> scope of &quot;computer&quot; function.<br>*/</em></pre><pre>function computer() { // outer function<br>  var ram = &#39;16gb&#39;;<br>  var hdd = &#39;2tb&#39;;<br> <br>  <em> // computer function scope === lexical scope of showData function</em><br>   return function showData() { // inner function <br>    console.log(`This computer has: RAM = ${ram} and HDD = ${hdd}`);<br>   }<br>}</pre><pre>var myComputer = computer();</pre><pre><em>// We invoke the showData function outside its lexical scope</em><br>myComputer();</pre><p>Well, I hope that you see this post useful and help you to improve your JavaScript skills and understand this beautiful programing language.</p><p>Console.log(“ :-) Enjoy it ”);</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d225da6cda83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ngx-rocket and Route Reusable Strategy]]></title>
            <link>https://alien-padilla.medium.com/ngx-rocket-and-route-reusable-strategy-ac33ecd7933e?source=rss-1e33c280d343------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac33ecd7933e</guid>
            <category><![CDATA[angular-7]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[route-reusable-strategy]]></category>
            <category><![CDATA[ngx-rocket]]></category>
            <dc:creator><![CDATA[Alien Padilla Rodriguez]]></dc:creator>
            <pubDate>Sun, 11 Nov 2018 04:59:05 GMT</pubDate>
            <atom:updated>2018-11-11T13:41:11.335Z</atom:updated>
            <content:encoded><![CDATA[<h3>ngxRocket and Route Reusable Strategy</h3><p>A few weeks ago, I had the need to use “ngx-rocket” generator, which I thought was really good, but I was surprised when I discover that by only adding `data: {reuse: true}` to the route params (as highlighted in the documentation) didn’t worked. My objective here is to present an alternative solution for you to understand how to fix this problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3jyYCE1rhv7oSpzfY7nFlw.png" /></figure><p>Using in my example code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tgx8nAhJLQX5QLKPj07SVg.png" /><figcaption>src/app/app-routing.module.ts</figcaption></figure><p>Since reusing some routes was of vital importance to me, I set myself the task of implementing a solution.</p><p><strong>That’s the result:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n73Mh3tk4PUUU37d-FSNhg.png" /><figcaption>src/app/core/route-reusable-strategy.ts</figcaption></figure><p>Now I can reuse the routes by adding “data: {reuse: true}” in the route definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yohAkPC-Y5al8ruMiT1sHg.png" /><figcaption>src/app/app-routing.module.ts</figcaption></figure><p>If you comment my code and uncomment the ngx-rocket, and try to navigate from House1 to any of the other houses (house2, house3, house4 or house5), even though the id in the browser’s url changes, you will notice that the data of the house does not change and this is given because the route is not being reused.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FdwOGDOZrR9heiqsoByLZA.png" /></figure><p>Here is the repository with the sample code:</p><p><a href="https://github.com/alienpr84/ngx-RocketRouteReuseStrategy">alienpr84/ngx-RocketRouteReuseStrategy</a></p><p>console.log(“enjoy it”);</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac33ecd7933e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loading data from API before component render with httpClient in Angular]]></title>
            <link>https://alien-padilla.medium.com/loading-data-from-api-before-component-render-with-httpclient-in-angular-4-fa87b8452750?source=rss-1e33c280d343------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa87b8452750</guid>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[resolve]]></category>
            <category><![CDATA[angular-4]]></category>
            <dc:creator><![CDATA[Alien Padilla Rodriguez]]></dc:creator>
            <pubDate>Mon, 28 May 2018 22:56:05 GMT</pubDate>
            <atom:updated>2018-11-08T21:09:28.133Z</atom:updated>
            <content:encoded><![CDATA[<p>Loading data from API before component render with httpClient in Angular</p><p>In some cases it is necessary to recover the data from the API before the component is ready to be used. Below I will show you how to do it.</p><p>This is the github repository with the code of the example:</p><p><a href="https://github.com/alienpr84/LoadingDataBeforeComponentRender.git">https://github.com/alienpr84/LoadingDataBeforeComponentRender.git</a></p><p>Problem situation:</p><p>I need to retrieve data about a school and load it before the component render and I have an API that provide me this json.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CnDEuk0g8x-heCIiVL8_gQ.png" /><figcaption>school.json</figcaption></figure><p>1- The first thing that we need to do is to create model classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NfBBYGaT-jjEwLLnEPPqnQ.png" /><figcaption>student.model.ts</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRjHYmSeNkNCQHmWGR5tUA.png" /><figcaption>school.model.ts</figcaption></figure><p>2- Now I create my service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQsWEDupk4BOOfX_w-1ugA.png" /><figcaption>home.service.ts</figcaption></figure><p>It’s very important to import HttpClientModule in the app.module.ts for using httpClient anywhere in the aplication and to import the service and add it to the providers array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHduNq2oUH7keHa5wX9JFg.png" /><figcaption>app.module.ts</figcaption></figure><p>3- Now I create the resolver</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0xhbm5CHqReIjRH5D-rRtw.png" /><figcaption>school.resolver.ts</figcaption></figure><p>4- I prefer to create my routes in a separate module. Then I create a new module for the routes. In that module I’m going to call my resolver to load the data from the API before the component render. It’s very important to import the resolver and add it to the providers and exports the routerModule to use it into AppModule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a3ujEnc5J9k0j6LoocJMaA.png" /><figcaption>app-routing.module.ts</figcaption></figure><p>5- The end step, create the component and call the resolver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1AzO9oUAcj-_W3ZJSDU5sQ.png" /><figcaption>home.component.ts</figcaption></figure><p>Here is very important import the ActivatedRoute to access to the loaded data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa87b8452750" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>