<?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[Kaliop - Medium]]></title>
        <description><![CDATA[A series of articles made by techs for techs. Writers share their experience and best practices for a more beautiful digital world. - Medium]]></description>
        <link>https://medium.com/kaliop?source=rss----50deb79dca0c---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Kaliop - Medium</title>
            <link>https://medium.com/kaliop?source=rss----50deb79dca0c---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 11:44:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/kaliop" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up Cypress.js in gitlab CI, the complete journey (Part 1/2)]]></title>
            <link>https://medium.com/kaliop/setting-up-cypress-js-in-gitlab-ci-the-complete-journey-part-1-2-c6856d18ef24?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/c6856d18ef24</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[test-automation]]></category>
            <dc:creator><![CDATA[Pierre Cavalet]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 09:26:16 GMT</pubDate>
            <atom:updated>2020-06-22T09:26:16.668Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T28FVpt21aa85SMC4CalOw.png" /></figure><p>This guide is divided into two parts. The first part shows how to setup Cypress end-to-end tests in a simple application with some cool features along the way. The second part (still in writing) will show you how to integrate these tests in Gitlab CI, from setting up your first jobs and pipelines to the different test workflows you can use.</p><p>Cypress.js has been a revolution for us. We had been using Nightwatch.js for a long time. It did the job back then, and we were happy about it, but when we tried out Cypress.js, we knew we had to make the switch for two reasons:</p><ul><li><strong>Stability: </strong>we have experienced multiple weird behaviors with end-to-end testing frameworks, and I am not saying that Cypress.js is perfectly stable, but it is much much more stable than what we have tested so far. The fact that <strong>it does not use selenium</strong> is probably what makes such a difference.</li><li><strong>Developer experience: </strong>video recording, test progression, logger, debugger, automatic waiting, time travel, automatic reloads and so on. Cypress.js has a complete developer tool set and it is a real pleasure to work with.</li></ul><p>I like to work on small projects to try things out, so we will be working on the following (fake) website for this article:</p><p><a href="https://workshop-cypress-kaliop.netlify.app/">https://workshop-cypress-kaliop.netlify.app/</a></p><p>Let’s pretend we are helping a developer named Jordan to test his application. Jordan is a great developer but never had the chance to get his hands dirty on Cypress.js.</p><h3>Cypress.js</h3><p>So Jordan has his website ready to test, already in (kind of) production. The first thing he needs to do is simply to install Cypress.</p><pre>npm install cypress --save-dev</pre><p>He adds the following script to his package.json file:</p><pre>&quot;scripts&quot;: {<br>  &quot;cypress:open&quot;: &quot;cypress open&quot;   <br>}</pre><p>He can then run</p><pre>npm run cypress:open</pre><p>And voilà! Jordan is ready.</p><p><strong>Note: </strong>Cypress generates a lot of tests. If you want to check them out, you can but for this tutorial we will just get rid of them. And so Jordan deletes all the generated tests file in the integration folder.</p><p>This is just the setup so let’s get into the real stuff.</p><h4>Writing your first test</h4><p>So Jordan asks himself:</p><blockquote>What do I want to test?</blockquote><p>Some people have tons of ideas, while others have none. So let’s break down what this website does and see what we need to test.</p><p>Jordan knows that most of his traffic lands directly on the homepage, because he uses analytics to his advantage. Then, a user might try to log in or sign up. That’s it. Pretty simple website.</p><blockquote>I first need to test my homepage, because it’s where most of my traffic lands.</blockquote><p>Alright Jordan. Good call.</p><p>With some help, Jordan creates a new file named homepage.spec.js and fills it with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff06bd5b45d1095e01af0af478b4e49b/href">https://medium.com/media/ff06bd5b45d1095e01af0af478b4e49b/href</a></iframe><ul><li>cy.visit() is used to navigate to a specific url.</li><li>cy.get() is used to get an element in the DOM and .should(&#39;exist&#39;) is pretty self-explanatory.</li></ul><p><strong>Note: </strong>cy.get() uses query selectors. data-cy is a data attribute (data-*) that you can put on any html tag. It’s best to use data attribute because if you use tags, ids or classes, your tests would not be as stable: any modification in the code could break the selector. And bonus points because we know exactly what it is used for (<a href="https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements">cf. Cypress.js Best practices</a>).</p><p>Now Jordan can run his test directly from the Cypress UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*MxICg-USbtPWjwV2RXaKPA.png" /></figure><p>So far so good.</p><h4>Tests with user interaction</h4><blockquote>Ok. I can test if my home page is displayed correctly. Now let’s move to my login.</blockquote><p>When it comes to testing features (like the login) which are data dependant, we want to be sure that what we are testing exists. For example, Jordan is going to try to log in to an account specifically created for this purpose. Another example would be if you had articles. You would want to test a specific <em>stable </em>article and not pick randomly the first one on your home page. Ideally you would want to work on fixtures. Let’s move back to Jordan’s login.</p><p><strong>Note: </strong>this login accepts every email address and password (yes it is fake).</p><p>So Jordan needs to find which login workflow(s) he wants to test.</p><blockquote>My users mainly land on my homepage and navigate to the login page when they try to log in, so I want to test the following workflow:</blockquote><blockquote>- the user lands on the home page<br>- the user navigates to the login page with the menu link<br>- the user enters his credentials<br>- the user is logged in</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fce3ff04a40dba1a323f4bf75b6b60d2/href">https://medium.com/media/fce3ff04a40dba1a323f4bf75b6b60d2/href</a></iframe><p>Commands in cypress are pretty easy to understand but let’s break down the new ones.</p><pre>cy.url().should(&#39;eq&#39;, &#39;XXX&#39;)</pre><p>This one is used to retrieve the current URL and then the should asserts that the URL is equal (&#39;eq&#39;) to the second parameter.</p><p>type and click can be used with get to either type something in an input or click on an element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*IN3OcRIuw1qeTvdkUqmy0Q.png" /></figure><p>It just works. 😃</p><p>I want to stop at this point and ask a simple question. Looking at the code above which (I think) is not that difficult to produce, how valuable do you think it is for your website and how difficult it would be to implement such test suites on <strong>your core functionalities </strong>?</p><p>I personally think that it is very valuable for the time invested. I am going to continue on cypress functionalities because I want to keep this article structured, but at this point, if I were Jordan, I would stop developing test suites and try to integrate them in my CI.</p><p>The most important thing is not to cover all your website functionalities but rather to cover the most important workflows for your product <strong>to make sure it does not break</strong>. You can add other test suites later on. Moving back to Jordan’s website.</p><h4>Cypress custom command</h4><blockquote>I don’t really like to hard code my URL. What if I want to have different configuration (dev, UAT, production), what if my url changes in my router?</blockquote><p>Don’t worry Jordan, we got you. Now let’s say we are using a router. We might want to type something like this:</p><pre>cy.goTo(&#39;home&#39;)<br>cy.goTo(&#39;login&#39;)<br>cy.goTo(&#39;signup&#39;)</pre><p>We can create a custom command goTo for this. We will create a fake router that returns the url when we pass the route name. Obviously the implementation will vary depending on the router you use but the logic is always the same. Let’s create a new file services/router.js :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7234f0bd1a1cab5a0c9f1d8bbc15adb0/href">https://medium.com/media/7234f0bd1a1cab5a0c9f1d8bbc15adb0/href</a></iframe><p>Now that we have a router we can use it in the support/commands.js file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/feeebe338a36c0ed5ba952736ee6b5a8/href">https://medium.com/media/feeebe338a36c0ed5ba952736ee6b5a8/href</a></iframe><p>And we can now use the command in our test suites (you don’t need to require it).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2afa852769ac1e02b4463f2f7f2808d6/href">https://medium.com/media/2afa852769ac1e02b4463f2f7f2808d6/href</a></iframe><p>This example is pretty simple because it does not handle path parameters, query parameters, etc. The idea is still the same even if you add more parameters. Just pass them through the command’s parameters.</p><h4>Cypress tasks</h4><blockquote>Well now that my log in process is tested, let’s do the same for the sign up process.</blockquote><blockquote>My users mainly lands on my homepage and navigates to the sign up page when they try to sign up, so I want to test the following workflow:</blockquote><blockquote>- the user lands on the home page<br>- the user navigates to the signup page with the menu link<br>- the user enters his information<br>- he fills the code he received by e-mail<br>- the user is signed up</blockquote><p>Hold on. This process looks like the login process but there is a catch.</p><blockquote>he fills the code he received by e-mail</blockquote><p>Now we could just open up a gmail client in the browser and retrieve the code. Right ? Right ? <strong>No.</strong></p><p>First of all, Cypress <a href="https://docs.cypress.io/guides/guides/web-security.html#Limitations">won’t let you change the domain</a>. You can still bypass it but the point here is that we do not want to test the gmail interface <strong>because it may change and break your test</strong>.</p><p>What we want to do instead, is use the gmail API (or another provider API) to retrieve the email, parse the content to retrieve the code and inject it in our test suite. This can be achieve using <strong>cypress tasks</strong>.</p><p>A cypress task is just a function that will be executed when it is triggered. But what is so special about a task is that it is not executed in the browser. Instead, it is executed in a Node.js environment, which means you can do whatever you want (more or less), because you have access to the Node.js API. You can for example read a file with the fs package…</p><p>…or you could install a library which allows you to read your email through an API and retrieve the code you want in the e-mail. 😃</p><p><strong>Note: </strong>Because it is a bit long to set up, we won’t actually be fetching the code from gmail. Instead we will fake it with an API endpoint that directly returns the code (always the same).</p><p>If you want to do it, you can go through the setup of <a href="https://github.com/levz0r/gmail-tester">this library</a> and do pretty much the same. Retrieve the code through the library instead of the API call and the rest is the same.</p><p>After reading the <a href="https://docs.cypress.io/api/commands/task.html">documentation</a>, Jordan writes his task in the plugins folder, making sure to install axios in order to call the API.</p><pre>npm install axios</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a467c1deccde708a80020c4136712aa/href">https://medium.com/media/7a467c1deccde708a80020c4136712aa/href</a></iframe><p>Since we returned a promise, Cypress will wait for this promise to be resolved (or rejected).</p><p>Now he can use it in his test suite:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b698476c4c8dea96fcdbbbd9e3f9394/href">https://medium.com/media/2b698476c4c8dea96fcdbbbd9e3f9394/href</a></iframe><p>And yes, Cypress will type the code before clicking on the submit button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*r_Z_kxZLHL8hjvIY29rffA.png" /></figure><p>This was just an introduction to Cypress.js. You can do a <strong>lot of things </strong>with this tool. Don’t fall into the trap of creating something too big. Start small, make it work and then try to move on to something bigger. Remember that the most important thing is to test what has the biggest value in your website.</p><p>In the next article we will reuse the code we produced and integrate our tests in gitlab CI. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6856d18ef24" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/setting-up-cypress-js-in-gitlab-ci-the-complete-journey-part-1-2-c6856d18ef24">Setting up Cypress.js in gitlab CI, the complete journey (Part 1/2)</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is going on in a front’s mind ?]]></title>
            <link>https://medium.com/kaliop/what-is-going-on-in-a-fronts-mind-93b85205d833?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/93b85205d833</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[coworking]]></category>
            <dc:creator><![CDATA[Jordan Dey]]></dc:creator>
            <pubDate>Fri, 07 Feb 2020 07:49:39 GMT</pubDate>
            <atom:updated>2020-02-10T09:56:05.734Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is going on in a front’s mind ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-31aa5uxNMV6rb0ZqtW6A.jpeg" /></figure><p>“Frontends… What a fun species !” Often considered as artists, their work is pretty mysterious for many people. You call them and they use their magic to make your forms look beautiful. We are about to try to enter their world to know them better. Make exchanges with them easier will make you save time if you work after them and improve your code quality if you work before them. For this, we will study the work conventions set up by the frontends, in order to understand and apply them.</p><p>The following subjects will be approached: CSS construction, The HTML structure, and finally the structure of the data. In each one of these points the good practices you need to know will be exposed. These things are easy to set up and will not make your developing time longer. Promised !</p><h3>I - CSS structure:</h3><h4>Notion of component / sub-component/ Element</h4><p>“How to name your classes?” The class naming is very important, because it must reflect the architecture of the component. For a front, everything is component. When he is visiting a website, he cannot help but separate the parts that look alike. This separation helps him identify the component he will be able to use again (or make possible to use again).</p><p>Let’s take the following example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m_P0lZD85b60pvw_" /><figcaption>Netflix interface</figcaption></figure><p>First, you can recognize a former Netflix interface. There were only two<em> Stranger Things</em> seasons at the time.</p><p>On this page two components can be identified. The first one would be the full width teaser on the top of the page. The second one, present twice, would be a contents list with a title. They are illustrated below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eqAoQWntoi9anhBp" /><figcaption>Netflix interface components</figcaption></figure><p>How would you call them ? Here, .FullTeaser is present on the top of the page so you may try to call it .TopTeaser. However, it is better to avoid putting the component position in its name, because it could be used on a different place on another page. It is the same about colours. I will avoid calling .MyRedComponent a component, because if I have to use it again with a different colour, I will end up with a class like .MyRedComponent--blue . The general rule is not to give pieces of information likely to vary in the class calling. Do not hesitate to ask the client how he is going to use the component so you can name it correctly. It will allow to have in mind the full website, to share the idea of the client to name and reuse well the components.</p><p>The component separation permits to coherently split you code. For each component identified, you will get a style file associated. In our example, the associated style will be find at .FullTeaser in _FullTeaser.scss ( if you are using SASS).</p><p>It may be useful to notice the elements that repeat themselves inside one component. It will be sub-components.</p><p>It is important to come to an agreement with the front team about a calling convention for your classes. Here, I’m using a calling system internal to Kaliop, inspired by the <a href="http://getbem.com/naming/">BEM</a> convention, for Block Element Modifier, which is the most common to the frontends. As you have maybe noticed, to call a component I am using the PascalCase. It permits to indicate that it is a component, not an utilitarian class which would be in CamelCase. Such as the utilitarians, the sub-components or elements must be written in CamelCase.</p><p>In code :</p><pre>.MyComponent // a component<br>.MyComponent-myElement // an element contained in .MyComponent<br>.text-red // an utilitarian which turns my text red</pre><p>In this example, this could be suggested:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Du16WWKOFQpSAQRw" /><figcaption>Netflix interface elements</figcaption></figure><p>In case of interlocked component, do not hesitate creating components instead of sub-component. In our example, it appears that the .FullTeaser-info block contents many pieces of information. If you need to stylise the title you will end up with .FullTeaser-info-title . However, for maintainability and clarity reasons, it is better to avoid going below three interlocking levels. You must always try to get an abstraction level as high as possible. This block could become a distinct component. So it would be possible to use it again in another context, independently. My selector .FullTeaser-info-title would become .MovieInformation-title . Of course the splitting will change dépending on the frameworks or your development team.</p><h4>Notion of modifier:</h4><p>A modifier is an element which has a different posting in a specific context. A modifier can be created to change a size, a colour, a position or something else. For this, indicate it in CSS by a double dash (--). Your .TeaserList-item become .TeaserList-item--large .</p><h4>Some #id and a lot of .class !</h4><p>The frontend developer avoids using an ID: As this one is supposed to be unique, it is a bad candidate for a reusable component. But that is not all ! On an ID, a style is very hard to override because of the weight of the CSS.</p><p>The weight of the css is the thing that permits to understand which rule is applied, because this rule is considered as the most important. For this, a weight is given to every possible selector. It is presented below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*C_KTveXitJu5UY8ccIO2KQ.png" /></figure><p>The style that will be applied will be the one with the higher weight. If all of the links, selected with the a tag, are blue and if a .red class is added on one of them, it will be red. The class is ten times more important than the tag. This is why you should not add a !important without having thought about it. It will be very hard to override … One last thing to know: in case of equality, the last selector wins.</p><p>These values are combinable in a selector, in this case they can be added. A selector such as div.myClass img can be considered as the addition: 1 + 10 + 1. Its weight will be 12 ! Got it ? Then, what is the value of these selectors ?</p><pre>1. div.myClass {...}<br>2. div#MyId p.myClass {...}<br>3. .myClass, .otherClass {...} //Watch out, there is a comma.<br>4. &lt;span style=&#39;...&#39;&gt;<br>5. div img {... !important}<br>6. &lt;a style=&#39;... !important&#39;&gt;</pre><p>1. 11 | 2. 112 | 3. 10 | 4. 1000 | 5. 10002 | 6. 11000</p><h3>II - Html Structure:</h3><h4>No useless tags</h4><p>When you are preparing your HTML code, you must take care of minimizing the quantity of tags. There are two main reasons to avoid using useless tags. First, it make the code easier to read. For a human being a tag bring few information, whereas a well called class gives a clear idea of the code that you are reading. Second, in order to get better performances. When you refer to the subject, lighthouse, the Google tool for the performance analyses, gives the following recommendations:</p><blockquote>Have less than 1500 nodes.</blockquote><blockquote>Have a maximum depth of 32 nodes.</blockquote><blockquote>Have no parent node with more than 60 child nodes.</blockquote><p>Then it is explained that the transfert performances will be better. A spring code with less tags is easier to load for the client. The performances would be have a better runtime because the virtual DOM creation would be quicker. Finally, the memory performances would be better to because the virtual DOM would be lighter during its analyses. If you want to study this subject more closely, here is the documentation: <a href="https://developers.google.com/web/tools/lighthouse/audits/dom-size">https://developers.google.com/web/tools/lighthouse/audits/dom-size</a></p><p>In practice, this means not to use tags for style, such as &lt;u&gt; or &lt;b&gt;. The style must be made up from the files provided. A tag is not understandable for a human being while a class name is. .text-underline is clearer than a &lt;u&gt; tag. Caution, here is about style only, not about the semantic that a tag can bring. In practice, a &lt;h1&gt; is useful for the structure of its document and of its SEO, so it must be kept.</p><h4>One component per file</h4><p>In the best case, a component should be able to live in an autonomous way. Whatever the context, it must be able to render correctly.</p><p>With one file per component it is easier to find out the code that is linked to it if the names of all the files linked to this component are harmonized. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tKyYKHu89l7ph6lR" /><figcaption>Component structure</figcaption></figure><p>In the case you have to modify or correct a component, you would be able to directly find again the file with an inspection with the development tools. Everything linked with this component has is name: structures, actions, style or data sources.</p><p>This methodology could have, as inconvenient, the need to load a lot of files to display a page made up from several components. This could create some performance issues. Fortunately, the code bundle tools make possible to get one single exit file. This one will be heavier, but it will be loaded only one time by the browser then cached. Moreover, these tools permit to set up splitting code, too. In this case, it is possible to split the final file into several files loaded only when needed. If you are interested in this subject, you can read this article: <a href="https://medium.com/kaliop/react-js-reduce-your-javascript-bundle-with-code-splitting-f2d24abd42b8"><em>reduce your javascript bundle with code splitting</em></a><em>.</em></p><h3>III - Data structure.</h3><p>In this last part will be tackled the subject of data sources and their format. A generic component should be able to depend on every kind of data. This means that it does not have to know the data structure. It defines its own structure from the pieces of information it uses. For this a DAO (Data Access Object) can be set up. It is an object which offers an abstract interface to a data spring.</p><p>Below, the component movie.vue expect to receive an object with the title property. But a service like Contentful sends a different structure. The controller in charge of the page finish will have to use a DAO to format the movie object into a structure that will be exploitable for the front. This structure must absolutely be discussed and known by all of the developers who work on the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s7aXjWb6QNgGpGUv" /></figure><p>The DAO is not the responsibility of one or the other part. Either frontends or backends can maintain it and make it evolve. Each team can how to organize to do it. For instance, the rule may be: the last to work on a new type of content is the one who set up the data formatting. In this case, if the front creates a component to display a new type of content it will expose all of the data it expects to receive. So the backend will have to format the data he sends to use the component.</p><p>Other conventions can be set up, like adding a .readme file to each component to expose the data it can receive, the events it can send back, and this without needing to open the code.</p><p>The DAO also allows to format the display of the data. It means that it is the DAO which, for example, is going to format a date depending on the current country. The only role of the component will be to display the piece of information.</p><p>So, to be friends with frontends you just need to understand how they see a web page and in particular how they name each part of it in the HTML and CSS code. You also need to maintain a clean code by reducing it as much as possible. No useless tags and also knowing enough of the CSS overrides. Finally, always open the dialogue to share the same vision of the components and their properties or expected data.</p><p><strong>Original article (FR): </strong><a href="https://www.kaliop.com/que-se-passe-t-il-dans-la-tete-dun-front/"><strong>https://www.kaliop.com/que-se-passe-t-il-dans-la-tete-dun-front/</strong></a></p><p><strong>Traduction: Lalie Landry / Dey Jordan</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93b85205d833" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/what-is-going-on-in-a-fronts-mind-93b85205d833">What is going on in a front’s mind ?</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XP Feedback — File architecture for our projects]]></title>
            <link>https://medium.com/kaliop/xp-feedback-file-architecture-for-our-projects-6e743a8158e1?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/6e743a8158e1</guid>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Clement “Snowji” D]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 09:22:17 GMT</pubDate>
            <atom:updated>2020-01-09T09:22:17.479Z</atom:updated>
            <content:encoded><![CDATA[<h3>XP Feedback — File architecture for our projects</h3><p>Firstly, if you prefer to read french version, find it here : “coming soon”</p><p>I was able twice to experience a heavy refactor, the one of the architecture of projects files.<br>The first one, thus the oldest (2016), was on a <strong>Symphony (PHP)</strong> project. The second one was some time ago (late 2018) on a <strong>React Native (Javascript)</strong>.</p><p>You might tell me : “but what is the link between these two technologies and their files architecture ?” Precisely ! Their documentation, most of tutorials and more lead us on the same way in terms of files organisation.</p><p>The objective here is to give you a feedback, what I learned of my experience, not to feed a never-ending debate to find which is best. You are free to choose what suits you best. I still wish to raise the fact that even if this part doesn’t seem very important, it is nevertheless structuring and it has an impact to the development of a project.</p><h3><strong>State of play :</strong></h3><p><em>Nb : Do not consider my project trees as fully realistic, these are examples created only for the sake of writing this article.</em></p><p>In both cases, whether for React Native or Symfony, the potential problem is the same for both, and the same goes for the solution. Let’s take a look for now at the architectures offered by these frameworks.</p><p>Symfony : the official documentation and the standard source code suggest that we arrange the files by type. For example, controllers will be in a Controller folder, forms in a Form folder, etc.<br>React Native : just like Symfony, if you start a React Native project, the basic architecture will propose you to organize your code by type as well. Put all components together in a Components folder, the same goes for others such as selectors, reducers, etc.<br>These architecture proposals also apply to <strong>VueJS</strong>, a framework frontend that I particularly like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*ISbG50BsTS1LUAgRhPLxng.jpeg" /><figcaption>files organization by type</figcaption></figure><p>We will agree that this architecture provides a good readability of the file structure because the grouping is quite logical. However, we don’t encounter it often because it lacks organization and it looks quite basic. Yet, this architecture becomes even more convenient if you add sub-folders for each type in order to provide some value and business logic. Below, you can find a standard organization that is found in most projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*mPorSABs42BS_y83qArXVQ.jpeg" /><figcaption>files organization by type and sub folders</figcaption></figure><p>Now, let’s push this logic further, or rather the other way around : put the profession on the first level and the types on the second.</p><h3><strong>Moving forward to improve productivity and readability</strong></h3><p>Rather than organizing files by type, try to highlight the profession of your project. It is this business aspect that represents a project, which structures it.</p><p>The discourse of this architecture can be found in some documentation or articles, but is rarely highlighted. Example on the documentation of Symfony, which advises to create only one Bundle and which finally suggests to highlight the profession in its “best practices” :</p><p><a href="https://symfony.com/doc/current/best_practices.html#don-t-create-any-bundle-to-organize-your-application-logic">https://symfony.com/doc/current/best_practices.html#don-t-create-any-bundle-to-organize-your-application-logic</a></p><p>The goal is therefore to gather all the files related to the “articles” of your project, or everything related to the “user”, or to the “products”, for example.</p><p>Through my experience so far and after testing both architectures, the latter (and I will illustrate it to you) is much easier to use, facilitates the readability and logic of your code, and therefore the understanding and productivity in your project.</p><p>Here is what it can give for the frameworks mentioned today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*tVQyouYSEsJQSNBqYrGDfw.jpeg" /><figcaption>files organization by profession</figcaption></figure><p>As you can see, it is still quite trivial and can be applied to a wide range of frameworks.<br>However, you have to remain pragmatic. This is why in my previous example, there are times when some files remain at the root of a folder and have no parent “type” folder. That is because if they are alone, it is useless to create a folder for a single file. This architecture is very well suited for large projects. It will provide less readability for a micro project with a relatively low business value.</p><p>Finally, I will have no more arguments than this illustration above showing you the final result of this type of architecture, inviting you to try it out in order to build your own opinion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e743a8158e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/xp-feedback-file-architecture-for-our-projects-6e743a8158e1">XP Feedback — File architecture for our projects</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a personalized newsletter with AWS cloud services and ElasticSearch]]></title>
            <link>https://medium.com/kaliop/build-a-personalized-newsletter-with-aws-cloud-services-and-elasticsearch-8d655f340594?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d655f340594</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Pierre Cavalet]]></dc:creator>
            <pubDate>Tue, 15 Oct 2019 07:58:08 GMT</pubDate>
            <atom:updated>2020-01-17T09:35:09.464Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eH9cLro2DrenX_8NOnr11w.png" /><figcaption>Image by <a href="https://pixabay.com/users/ribkhan-380399/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3249062">Muhammad Ribkhan</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3249062">Pixabay</a></figcaption></figure><p>For a french version of this article, <a href="https://www.kaliop.com/newsletter-personnalisee-avec-les-services-cloud-aws-et-elasticsearch/">click here</a>.</p><p>I am part of a team that develops a content platform which is accessed essentially from our newsletter. Our platform is built with a lot of cloud services, and some of them are used to generate our newsletter.</p><p>We’ll go trough our newsletter specifications and then dive in its implementation.</p><h3>Requirements</h3><ol><li>Our users are interested in different topics, and our content is very specific. We need to be able to send interesting content for a <strong>specific </strong>user based on the information we have. We don’t want to send a generic newsletter that would not be interesting for a user looking for specific content in his/her field.</li><li>Our implementation needs to <strong>scale</strong> well, as our platform is regularly deployed in new countries, and our user pool grows accordingly.</li><li>The newsletter needs to have a <strong>manual trigger</strong> in a web interface, with a debugging tool.</li><li>We need to be able to explain <strong>why</strong> a specific content has been picked over another.</li></ol><h3>Architecture</h3><p>We use multiple services. The following diagram shows how they interact with each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLjl79fkGoMhAwe7JIatIA.png" /></figure><ol><li>We trigger an <a href="https://aws.amazon.com/lambda/">AWS lambda</a> from our back-office.</li><li>The lambda fetches users that are eligible to the newsletter (depending on their consents and other criteria).</li><li>The lambda pushes a message in the <a href="https://aws.amazon.com/sqs/">AWS SQS</a> queue for each newsletter that we want to send. The message contains everything needed to send the newsletter (email, topic of interests, etc…).</li><li>A lambda is listening to the SQS queue. Every time a message is pushed, a lambda is triggered to handle it. This resolves our <strong>scaling problem</strong>, as we can trigger as many lambda as we need to process our newsletters.</li><li>When this lambda is triggered, we send a request to ElasticSearch to determine which content has to be sent to the user. (more on this later in the article).</li><li>Now that we have the content IDs, we send a request to <a href="https://www.contentful.com/">Contentful</a> (the headless CMS where our content is hosted) to get the actual content (and not just the IDs).</li><li>With the Contentful data, we generate the newsletter template using <a href="http://mandrill.com/">Nunjucks</a> (a templating library that we use with <a href="https://tech.kaliop.com/en/technologies/node-js/">Node.js</a>).</li><li>With the message information (email, …) and the email template, we send a request to <a href="http://mandrill.com/">Mandrill</a> (a transactional email service from <a href="https://mailchimp.com/">Mailchimp</a>) that handles the rest for us.</li><li>[OPTIONAL] We push records regarding the newsletter stats (and potential errors) in DynamoDB in order to give a feedback to the user who triggered the newsletter from the back-office (number of newsletter sent, errors, etc …).</li></ol><p>That’s a lot of things to do, but thankfully, it’s also just a chain of small tasks to perform. What is great about this architecture is that everything is broken down to simple steps and you can easily change things without breaking everything.</p><h3>Initial trigger</h3><p>The architecture uses a back-office that triggers a lambda trough API gateway to push the SQS messages. We chose this because it was simple for us, but you can use anything you want to push the messages (script, web hooks, etc …).</p><h3>Handling personalization</h3><p>This is a brief explanation of how we use ElasticSearch as a recommendation system. If you want the full details, check out my article on <a href="https://medium.com/kaliop/how-we-built-a-reversible-recommendation-system-using-elasticsearch-d34a82b4893e">How we built a reversible recommendation system using ElasticSearch</a>.</p><p>The idea is that we define a list of criteria and we order them. For example:</p><ol><li>the user has not read the article</li><li>the article matches the user topics</li><li>Any boolean criterion you want to test</li></ol><p>We then use <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html">ElasticSearch function score</a> to give a weight to each criterion.</p><p>When we send a query to ElasticSearch, the response contains the articles ordered by their score. It also includes the article score itself in the response. This score can be reversed to obtain the criteria.</p><h3>Final thoughts</h3><p>Using lambda and an SQS queue to handle our newsletter process worked out well for us. Writing in dynamoDB allows to us to know what happened for each newsletter batch.</p><p>We used <a href="https://serverless.com/">Serverless framework</a> to deploy both the “trigger lambda” and the “SQS-listening Lambda”, which simplified the deployment process. We also used <a href="https://github.com/dherault/serverless-offline">serverless-offline</a> and s<a href="https://github.com/CoorpAcademy/serverless-plugins/tree/master/packages/serverless-offline-sqs#readme">erverless-offline-sqs</a> to develop the newsletter, allowing us to simulate everything that would happen on AWS without deploying.</p><p>Overall, we are satisfied with the solution and will continue to use these <a href="https://tech.kaliop.com/en/technologies/amazon-web-services/">AWS</a> services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d655f340594" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/build-a-personalized-newsletter-with-aws-cloud-services-and-elasticsearch-8d655f340594">Build a personalized newsletter with AWS cloud services and ElasticSearch</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 ways to automatically renew an user session per token (JWT)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/kaliop/3-ways-to-automatically-renew-an-user-session-per-token-jwt-552616e1f094?source=rss----50deb79dca0c---4"><img src="https://cdn-images-1.medium.com/max/2600/0*uZ0zK8V9fT6pAZnV" width="5302"></a></p><p class="medium-feed-snippet">Explore with me 3 ways to renew your user sessions with a web application.</p><p class="medium-feed-link"><a href="https://medium.com/kaliop/3-ways-to-automatically-renew-an-user-session-per-token-jwt-552616e1f094?source=rss----50deb79dca0c---4">Continue reading on Kaliop »</a></p></div>]]></description>
            <link>https://medium.com/kaliop/3-ways-to-automatically-renew-an-user-session-per-token-jwt-552616e1f094?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/552616e1f094</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Andréas Hanss]]></dc:creator>
            <pubDate>Fri, 13 Sep 2019 12:29:12 GMT</pubDate>
            <atom:updated>2020-04-24T10:44:40.934Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How we built a reversible recommendation system using ElasticSearch]]></title>
            <link>https://medium.com/kaliop/how-we-built-a-reversible-recommendation-system-using-elasticsearch-d34a82b4893e?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/d34a82b4893e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Pierre Cavalet]]></dc:creator>
            <pubDate>Mon, 15 Jul 2019 12:48:04 GMT</pubDate>
            <atom:updated>2020-01-17T09:30:33.297Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fwx8zMnky3_5RsCiiLSVqA.png" /></figure><p>For a french version of this article, <a href="https://tech.kaliop.com/creer-un-systeme-de-recommandation-reversible-avec-elasticsearch/">click here</a>.</p><p>Recommendation engines are everywhere. There are a lot of complicated techniques to recommend content, but sometimes, what you need is just a recommendation system to propose specific content to your users using simple rules.</p><h3>A bit of context</h3><p>We are building content related features where we need to be able to explain everything that is displayed to a specific user. For exemple, if you go to your home page, and an article called <em>My thoughts on</em> <em>the last season of Game of Thrones</em> is displayed, we need to be able to explain why.</p><p>When your recommendation algorithm is basically ordering content based on publication date, this is pretty simple to do. But when it uses user information and stuff like this, that’s when it becomes harder to explain results.</p><h3>How it works</h3><p>The algorithm is pretty simple. We define a list of criteria that a content could match, and then we order them by priority. Each criterion must be a boolean.</p><p>Let’s say we are recommending articles. In order of priority:</p><ol><li>the user has not read the article</li><li>at least an article tag matches the user tags</li><li>the article is flagged <em>important</em></li></ol><p><strong><em>Note:</em></strong><em> This is just an example, and you can define a way bigger list, as long as you order them. The order is purely arbitrary for example purposes.</em></p><p>Now we want to assign a score to each criterion. The scores we will use are <em>powers of 2</em>. We will start assigning from bottom to top.</p><ul><li>the user has not read the article: 2³ = <strong>8</strong></li><li>at least an article tag matches the user tags: 2² = <strong>4</strong></li><li>the article is flagged <em>important</em>: 2¹ = <strong>2</strong></li></ul><p>Let’s consider a user called John.</p><p>John has not read <em>My thoughts on</em> <em>the last season of Game of Thrones, </em>but the article tags do not match any of John’s tags. Finally, the article is flagged <em>important</em> by the content team.</p><p>Our algorithm will sum the score of each criterion that matches to give a final score to the article for the calculation of John’s home page: 8+ 2= 10.</p><p>Repeating this process for each article, we can <strong>rank articles based on their scores</strong>. The highest articles will be displayed on John’s home page.</p><p>If you are wondering why we use <em>powers of 2</em>, we will come to that later in the article.</p><h3>ElasticSearch implementation</h3><p>Let’s say I have the following documents in my index:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a05551cd1056bb0e52433f88b1a1cab9/href">https://medium.com/media/a05551cd1056bb0e52433f88b1a1cab9/href</a></iframe><p>ElasticSearch gives us a wonderful tool called <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html">function score query</a>. It allows us to modify the score of the documents retrieved by a query, based on filter queries.</p><p>For example, I can do a first query that will retrieve all the articles, and then use a filter query on those results to change the score of the articles that John has not read. Let’s say that John has read the article with the ID <em>articleId2.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf4d840e90aa669930e311ed3ac08a97/href">https://medium.com/media/bf4d840e90aa669930e311ed3ac08a97/href</a></iframe><p><strong><em>Note:</em></strong><em> If your query filters documents instead of a match_all, you can use </em><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html"><em>constant_score</em></a><em> so that your query score does not alter the final score.</em></p><p>Now we can just add the other functions for the tags and the <em>important</em> flag and we are all set !</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/281eed3e384dca3efb8145d6e0cc77f6/href">https://medium.com/media/281eed3e384dca3efb8145d6e0cc77f6/href</a></iframe><p>Here is the result returned by ElasticSearch:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ddda995fc11d0e47a2f26710e2ed8f/href">https://medium.com/media/e2ddda995fc11d0e47a2f26710e2ed8f/href</a></iframe><p>As you can see, ElasticSearch returns the score of each documents in its query, which is perfect for what is next: <strong>Reversing ElasticSearch score</strong>. So let’s answer this question:</p><h3>Why the hell are we using powers of 2 ?</h3><p>We did not choose to use <em>powers of 2</em> just because they are cool (but they are). We chose them because they are ideal to store boolean information. 0 stands for false, 1 stands for true. Storing information with <em>powers of 2 </em>is called a <a href="https://en.wikipedia.org/wiki/Bit_field">bit field</a> (or a bit flag).</p><p>Additionally, this technique will produce a one-to-one relation between the input (boolean information) and the output (flag value). It means that we are able to re-create the input data from the output, which is also known as <a href="https://en.wikipedia.org/wiki/Reversible_computing">reversible computing</a>.</p><p><strong><em>Note: </em></strong><em>We are skipping the first byte, because the default score when ElasticSearch matches nothing is 1, so the first power of two: 2⁰ = 1 is already taken.</em></p><p>This is how it works for our article (the red one is skipped):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*ItitL9ptspu0XpOjGQ5mYA.png" /></figure><p><em>So … if I convert my score (10) to its binary value (1010), then I can see which boolean information were set to true ?</em></p><p>Yes. But there is a better trick. You can use <a href="https://en.wikipedia.org/wiki/Bitwise_operation">bitwise operator</a> to extract the information. More specifically the bitwise-AND. What it does is basically what its name means. It applies a AND operation between every bits of two given number. For example 7 &amp; 6 = 6:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*J9oimZ-EPfixpQhnNb0R-A.png" /></figure><p>Now if we <strong>only use one specific bit</strong> with the bitwise-AND, we can determine if the flag contains this information because all the other bits will evaluate to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*NMLCsAKGoEGgxLiypdRCHQ.png" /></figure><p>Here we only extract one single information. Because 10 &amp; 2 ≠ 0, the article is tagged <em>important.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*QjCr95x-U9IIf8j5H5wkIA.png" /></figure><p>Because 10 &amp; 4 = 0, the user tags does <strong>not</strong> match the article tags.</p><p>Using this technique we can easily write a script that would decode a given score, which is exactly what we wanted !</p><p>This is a small example of how we could decode the score in javascript, but it is easily reproductible in a different language:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f4ae3d331863449fdfea18014f29237/href">https://medium.com/media/8f4ae3d331863449fdfea18014f29237/href</a></iframe><h3>Recap</h3><ul><li>By using powers of 2 to score documents, we can represent a one-to-one relationship between boolean information and a score.</li><li>We can use this score to rank documents in order to give John the articles that he wants to read.</li><li>We can reverse the score into the boolean information in order to explain John’s home result if we ever need to.</li><li>To implement this technique, we use ElasticSearch function score queries.</li><li>John has interesting recommendation. John is happy.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d34a82b4893e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/how-we-built-a-reversible-recommendation-system-using-elasticsearch-d34a82b4893e">How we built a reversible recommendation system using ElasticSearch</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React.js: reduce your javascript bundle with code splitting]]></title>
            <link>https://medium.com/kaliop/react-js-reduce-your-javascript-bundle-with-code-splitting-f2d24abd42b8?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/f2d24abd42b8</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Pierre Cavalet]]></dc:creator>
            <pubDate>Fri, 24 May 2019 14:07:45 GMT</pubDate>
            <atom:updated>2019-11-18T13:59:09.689Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smNMGplrR-jhaE5TBqr-zw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/ZTAhoW9W3ms?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tanalee Youngblood</a> on <a href="https://unsplash.com/search/photos/slices?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I’m technical expert at Kaliop and today I speak about react.js. If you want to know more about this subject, <a href="https://tech.kaliop.com/technos/react-native/">click here</a>.</p><p>Users care more and more about performance. We are building rich applications, and as an application grows, <strong>so does the javascript bundle</strong>.</p><p>When developing a single page application, we create a lot of components. Each of these components has its own dependencies, util librairies and so on. We keep developing features and at some point, we realise that our website is slow 🙀. While investigating, we realise that our javascript bundle is too big. There are different ways to find this out:</p><ul><li>It takes too much time to load when using a slow network. We can test this easily using the <a href="https://developers.google.com/web/tools/chrome-devtools/">chrome dev tools</a> and the network tab.</li><li>Webpack itself tells us that our bundle is too big:</li></ul><pre>WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance<em>.</em></pre><ul><li>Tools to analyze your website (such as <a href="https://developers.google.com/web/tools/lighthouse/">lighthouse</a>) tell us to reduce your bundle size:</li></ul><pre>Consider reducing the time spent parsing, compiling and executing JS. You may find delivering smaller JS payloads helps with this.</pre><p>If you came to one of these situations, the next question you may ask yourself is:</p><blockquote>Fine, I have a performance problem because of my bundle size. But how do I deal with it?</blockquote><p><strong>Mesure. Analyze. Take action.</strong></p><p>We will use a simple <a href="https://tech.kaliop.com/en/technologies/react-js/">react</a> application with a <em>Home</em> and <em>Heavy</em> routes, with react router. The Heavy component will use <a href="https://lodash.com/docs/4.17.11">lodash</a> and <a href="https://momentjs.com/">moment</a> libraries just to make it as large as possible (in terms of bundle size).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45618ed50439f74f5afeb452fd02a40d/href">https://medium.com/media/45618ed50439f74f5afeb452fd02a40d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89d02811e6db9ec3cb8fef79ec574c23/href">https://medium.com/media/89d02811e6db9ec3cb8fef79ec574c23/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9264dcbf08a8d89d91af6002ae233abe/href">https://medium.com/media/9264dcbf08a8d89d91af6002ae233abe/href</a></iframe><h3>Mesure</h3><p>You should always<strong> </strong>mesure the impact of a problem <strong>before</strong> diving into some premature optimisations. We can use <a href="https://github.com/danvk/source-map-explorer/releases">source-map-explorer</a> to inspect our javascript bundles and then take actions accordingly.</p><p><strong><em>Note:</em></strong><em> I am using source-map-explorer because it is the recommended tool for react and we don’t need to eject the configuration. For those who find it difficult to read (like myself), you can use webpack-bundle-analyzer but you might be forced to eject.</em></p><pre>npm install --save source-map-explorer</pre><p>We need to add a new script in the <em>package.json.</em></p><pre>&quot;scripts&quot;: {<br>  &quot;analyze&quot;: &quot;source-map-explorer &#39;build/static/js/*.js&#39;&quot;,<br>  ...<br>}</pre><p>We can then run:</p><pre>npm run build<br>npm run analyze</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BIjwUhh-l0rct0Oms5BD0g.png" /></figure><h3>Analyze</h3><p>By looking at the analyzer output, we can see that <em>lodash</em> and <em>moment</em> take a big place in our bundle. When we load the home page, we actually send lodash and moment unnecessarily. The home page component does not need those libraries.</p><p>Here, if we split the Heavy component from the main bundle, it would remove the lodash and moment libraries, reducing the bundle to just above half its size.</p><p>This is the kind of things that can drastically reduce your javascript bundles, but you have to keep in mind that it needs to require as little effort as possible, and it should have a significant effect on the bundle size. Do not optimise chunk that weigh 3KiB, aim for the big fish.</p><h3>Take action</h3><p>The goal here is to separate the Heavy component (and its dependencies) from the rest of the bundle. We will use the webpack code splitting feature. First let’s see how the feature works <strong>outside the react context</strong>.</p><p><strong><em>Note:</em></strong><em> When using create-react-app, webpack is already configured to support code splitting with the dynamic import.</em></p><p>Webpack supports the dynamic import syntax. It uses promises internally. Here is the difference between a static import and a dynamic import:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bccad65c721cdc96aed31aec129caf0d/href">https://medium.com/media/bccad65c721cdc96aed31aec129caf0d/href</a></iframe><ul><li>The static import returns what is exported by the module as the <strong>default export</strong>.</li><li>The dynamic import returns a promise that resolves an <strong>object with a</strong> <strong>default property</strong>. This property value is what is exported by the module as the <strong>default export</strong>. When webpack sees a dynamic import, it bundles what is not statically imported in the main bundle into its own chunk.</li></ul><h4><strong>Back to our application context</strong></h4><p>First let’s see what the network traffic looks like before splitting the component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*xKpQV-zSJWa-Bsi57qQRXw.png" /></figure><p>We can see that the chunk 2.xxxx weights 263kb (as we saw in the analyzer) and takes 7.36s to load in slow 3G. Now let’s split the heavy component and see what happens.</p><p>We can use <strong>lazy</strong> and <strong>Suspense</strong>. Lazy allows you to render a dynamically imported component as a regular component and Suspense allows you to define a fallback while the component is loading.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c132789d904d4c0f4b33d29458fe2e6/href">https://medium.com/media/5c132789d904d4c0f4b33d29458fe2e6/href</a></iframe><p>Then we’ll use this component in our router.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b77f7789f66f8dd7c52057a1a14a0ada/href">https://medium.com/media/b77f7789f66f8dd7c52057a1a14a0ada/href</a></iframe><p>Now let’s rebuild and analyze the bundle again.</p><pre>npm run build<br>npm run analyze</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isXAyFJovQ9VnshF1eLnpQ.png" /></figure><p><em>This one is a little bit more detailed on the main chunk because the zoom did something different, but that’s not important.</em></p><p>The most important thing to look at is that there are now two different chunks (2.xxxx and 3.xxxx). 3.xxxx has been created because we used a dynamic import, as we saw in the previous section. The 3.xxxx chunk contains the Heavy component and won’t be loaded if we don’t need it. Thanks to the split, our 2.xxxx chunk only weighs 148kb, which is a lot smaller than our previous 263kb.</p><p>This is what happens if we load the home page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*zw_SbHDfjRYUA8b2YCf8UA.png" /></figure><p>The page loads more than 2 seconds faster because the chunk is lighter. Now if we navigate to the heavy route, the chunk is automatically downloaded:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*aj2MQj_au3KwjRnySDVTrg.png" /></figure><h3>Recap</h3><ul><li>Code splitting is useful to reduce your bundle size by splitting big parts and loading them only when you need it.</li><li><strong>lazy</strong> and <strong>Suspense</strong> helps you to split your components, but it is based on dynamic import which is a webpack feature. You can use this technique anywhere as long as you use webpack, even in non react application.</li><li>Always analyze before trying to improve your performance and focus on the easiest tasks that have the biggest impact on performance.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2d24abd42b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/react-js-reduce-your-javascript-bundle-with-code-splitting-f2d24abd42b8">React.js: reduce your javascript bundle with code splitting</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End-to-end testing with Nightwatch.js]]></title>
            <link>https://medium.com/kaliop/end-to-end-testing-with-nightwatch-js-a821ad787fa4?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/a821ad787fa4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Pierre Cavalet]]></dc:creator>
            <pubDate>Wed, 06 Mar 2019 13:59:20 GMT</pubDate>
            <atom:updated>2020-01-17T09:31:39.092Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*PMx1-QDiFpgPkP4n-o6NyQ.png" /></figure><p>For a french version of this article, <a href="https://tech.kaliop.com/comment-faire-des-tests-end-to-end-avec-nightwatch-js/">click her</a>e.</p><p>Testing an application is so important. I can’t stress that enough. Nobody wants an application full of bugs. Nobody wants to fix the same bug over and over again. You must have, at the very least, end-to-end testing on large applications. And it is not that difficult. Remember that you can always start small and then get your test suites bigger to cover a larger part of your application.</p><p>This article will guide you through the set up of a simple end-to-end stack and performing simple operations, using hooks, adding custom commands and using shared variables across your test suites.</p><p>Nightwatch.js is a simple end-to-end testing framework that allows you to test your application through simple commands in a <a href="https://tech.kaliop.com/en/technologies/node-js/">node.js</a> environment. It uses a WebDriver server under the hood to perform the different operations you describe.</p><p>We are going to set up a simple end-to-end stack. Nightwatch.js is the framework to write the tests and Chromedriver is the browser driver we will use to perform the tests.</p><p>The website we are going to test is this one: <a href="https://nightwatch-demo.netlify.com/">https://nightwatch-demo.netlify.com/</a></p><p>It is a simple website with an input asking you your name and then displays it with a welcome message.</p><h3>Installation</h3><pre>mkdir nightwatch-tests &amp;&amp; cd nightwatch-tests<br>npm init -y<br>npm install nightwatch --save-dev<br>npm install chromedriver --save-dev</pre><p>Create a file named <em>nightwatch.json </em>and put the following the configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/621926005acb925bed4b9e260c9e0f2e/href">https://medium.com/media/621926005acb925bed4b9e260c9e0f2e/href</a></iframe><h3>Writing the first test</h3><p>Create a directory named <em>tests. </em>This directory is your entry point, as specified in the configuration file (src_folders). Each file in this folder represents a <strong>test suite</strong>. Create a file named <em>home.js </em>inside the <em>tests </em>directory, as we are testing the home page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab48d2e2ab9a5cd1a83a775969836297/href">https://medium.com/media/ab48d2e2ab9a5cd1a83a775969836297/href</a></iframe><p>In each test suite,<strong> </strong>we export an object with <em>module.exports. </em>Each object property represents a step in the test suite.</p><p>For example, in our <em>home</em> test suite, we only have one step which is called <em>Demo Test.</em></p><p>This function takes an argument called browser, which is an object we can use to perform tasks, such as <em>pause, waitForElementVisible, </em>and so on. The functions you can use can be found in the <a href="http://nightwatchjs.org/api">api reference</a>. Don’t forget to call the <em>end</em> method to tell nightwatch that the test is finished.</p><p>In order to run the test properly, we will configure the test command in the <em>package.json</em>. Replace the <em>test</em> command by <em>nightwatch</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24548bbc5bf59a3fa059d3c0948ee1aa/href">https://medium.com/media/24548bbc5bf59a3fa059d3c0948ee1aa/href</a></iframe><p>You can now run the test command:</p><pre>npm run test</pre><p>You should see the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFyxPCg5NsKwB__HeIgkUg.png" /></figure><h3>Tests hooks</h3><p>Hooks are powerful tools that you can use when you want to perform the same task before or after running a test suite. There are 4 hooks that we commonly use:</p><ul><li><strong>before</strong>: runs before the test suite</li><li><strong>after</strong>: runs after the test suite</li><li><strong>beforeEach</strong>: runs before each step of a test suite</li><li><strong>afterEach</strong>: runs after each step of a test suite</li></ul><p>It can be used for a lot things. For example you could call a specific service before your test suite to get things ready. You could call another specific service at the end of your test suite to shut it down.</p><p>Let’s create a simple hook that would log that the test suite is finished.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0189b1923a99b640af58d53969f6b84a/href">https://medium.com/media/0189b1923a99b640af58d53969f6b84a/href</a></iframe><p>The hook terminates when the function returns (which in this case is at the end of the function, because the functions return <em>undefined</em> by default when they reach the end).</p><p>You can run the test and see “<em>I am done.” </em>at the end of the test output.</p><p>You may need to perform asynchronous tasks. You can use the <em>done</em> parameter to do so.</p><h3>Custom command</h3><p>There are some workflow that requires to do some things that are not in the nightwatch API. For example, if you sign up to your website, you might receive a code or a link by email. For these kind of things, you might want to look at nightwatch custom command.</p><p>You can create a command, use the gmail API, take the last email received from <em>noreply@yourwebsite.com </em>and perform a query on the content to retrieve the link.</p><p>We are going to do something simpler in this article, but the idea is the same.</p><p>There are two different ways to define a custom command:</p><ul><li>Function-style command which are really simple but really limited.</li><li>Class-style command which are much more flexible.</li></ul><p>Let’s focus on the latter, as it is the one you want to use most of the time. Class-style command are based on <em>EventEmitter</em>. It works by calling the <em>complete </em>event when you are done performing the task. The following command is a <em>weird pause</em> that works only on odd number of milliseconds. Let’s put a file in a <em>custom-commands </em>directory and name it <em>weirdPause.js</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4c7480a0edda64967c1cc8922994238/href">https://medium.com/media/e4c7480a0edda64967c1cc8922994238/href</a></iframe><p>Add the <em>custom_commands_path</em> property to your configuration file <em>nightwatch.json</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d81699d21d32bd65237798a0502839f/href">https://medium.com/media/6d81699d21d32bd65237798a0502839f/href</a></iframe><p>Finally try running it both with an even number and an odd number. The command name is the name of the file itself. This one is a bit odd and not very IDE friendly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bab2f2de5d58a1ab9df517557428e46/href">https://medium.com/media/8bab2f2de5d58a1ab9df517557428e46/href</a></iframe><p>You can see that the even number stops the test and the odd number just pass like a charm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRZ48SdkKRHwpKfFSaNtBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRWqgTAt_YHJafqVE71YRQ.png" /></figure><h3>Global variables</h3><p>When you are testing, you may want to define some variables that you will use across your application. You can do it in the nightwatch configuration file. Let’s add a <em>launch_url</em> and a <em>globals</em> object with a property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1891b933b8f6a1ee67b98d01496f7baa/href">https://medium.com/media/1891b933b8f6a1ee67b98d01496f7baa/href</a></iframe><p>Now we can use this variables directly in the test. It is available through the browser variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72275720a2ef8118f65bec5e42028dcc/href">https://medium.com/media/72275720a2ef8118f65bec5e42028dcc/href</a></iframe><h3>No excuse</h3><p>This is the basics to write your first end-to-end test. You now have everything you need to set up the stack and start testing your app. Remember that it is really simple to start, and you can at the very least test your most important pages.</p><p>There are a lot of other things nightwatch can do. You can find out more on their <a href="http://nightwatchjs.org/">website</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a821ad787fa4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/end-to-end-testing-with-nightwatch-js-a821ad787fa4">End-to-end testing with Nightwatch.js</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your own SVG graph with react-native-svg and D3.js]]></title>
            <link>https://medium.com/kaliop/make-your-own-svg-graph-with-react-native-svg-and-d3-js-dd0250813313?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/dd0250813313</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Pierre Cavalet]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 13:23:42 GMT</pubDate>
            <atom:updated>2020-01-17T09:32:02.562Z</atom:updated>
            <content:encoded><![CDATA[<p>For the french version of this article, <a href="https://tech.kaliop.com/creez-votre-graphe-svg-avec-react-native-svg-et-d3-js/">click here</a>.</p><p>Drawing graphs with <a href="https://tech.kaliop.com/en/technologies/react-native/">React native</a> is easier said than done. There are librairies which propose some ready to use graphs, but most of the time you’ll want to create your own, with your specific design. The goal of this article is to guide you trough the process of creating your own graph from scratch.</p><p>The graph we are going to build is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*cU6iTKKs84hEeGsP22MDtw.png" /></figure><h3>Install the dependencies</h3><p>As mentioned in the title: we need two libraries, <a href="https://github.com/react-native-community/react-native-svg">react-native-svg</a> and <a href="https://d3js.org/">d3.js</a>.</p><pre>npm i --save d3<br>npm i --save react-native-svg<br>react-native link react-native-svg</pre><h3>Let’s draw!</h3><p>The bar chart we are trying to draw is displayed from bottom to top. The problem is that SVG’s Y coordinate works from top to bottom. We are going to use a technique to simplify the drawing.</p><p>We will draw the graph with negative Y coordinate, which will be simpler. For exemple, for a value of 5, we will draw a bar from 0 to -5.</p><p>Finally, we need to translate the graph, because right now, it is out of the SVG viewport.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*JPNIbclTo0thQ3L1VCYzwQ.png" /></figure><p>Let’s do this for real now.</p><p>Let’s put a Rect in the SVG so we can see something.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b01b0d3738d9d4b7f4070bbaa250f439/href">https://medium.com/media/b01b0d3738d9d4b7f4070bbaa250f439/href</a></iframe><p>We translate the graph on the Y axis for the graph height. Note that the Rect Y coordinate is -15 because we drew the Rect outside of the SVG viewport, and then translated it inside. You can try this component and you should be able to see the Rect.</p><h3>Axis generation</h3><p>We will start with the bottom axis. The diagram we previously saw was simplified to understand the translation. Y=0 is the bars starting coordinate. We define the graph margins which is where everything around the graph will be (<em>Jan, Feb, …</em> for exemple).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*GkiaxYXFAOn4O_gxxAIL6A.png" /></figure><p>If you look closely, you will see that the bottom axis a little bit detached from the graph. Since we are drawing with negative coordinate and we want it under the graph, we are going to give the axis Y=2 coordinate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c2f0cac18490478860a44a4aae72841/href">https://medium.com/media/7c2f0cac18490478860a44a4aae72841/href</a></iframe><h3>Bar generation</h3><p>Bars on this graph are just Rect with a border radius. At this point we will need some data. Our bar chart data is going to be an ordered list of key-value pairs. In javascript, we’ll represent this with an array of objects.</p><p><em>Note: I am skipping all the props validation part for the tutorial because I want it as simple as possible.</em></p><p>How do we decide which <strong>x</strong>, <strong>y</strong> <strong>height</strong> and <strong>width </strong>to give to the Rect ?</p><p>We need to keep in mind that the height works like the SVG, from top to bottom, even though we are drawing in negative coordinate. It means that the starting point <strong>(x, y)</strong> will be the top of the Rect, and the height represent the distance between the starting point and the bottom (Y=0). Here is an illustration to understand the concept:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*nx1sGwe1G8_jypeAUvn3NA.png" /><figcaption>Bars position and height</figcaption></figure><p>Now the hard part is to find <strong>x </strong>and <strong>y</strong>. What we want to achieve is that the highest value goes to the top of the graph, so we need the bars to scale depending on the top value.</p><p>Let’s use <a href="https://github.com/d3/d3-scale#point-scales">d3-scale Point scales</a> and <a href="https://github.com/d3/d3-scale#linear-scales">d3-scale Linear scales</a> for this. In a nutshell, the scales allow us to define a specific range and a specific domain, and we will use these scales to define <strong>x </strong>and <strong>y</strong>. The only notable thing we are going to do after the scales calculation is to remove half the bar width to the X coordinate. Since it is a point scale, the points are not supposed to have width, so we consider the points as the center of our bars.</p><p><em>Note: I did not use band scales because they have a fixed padding and a variable width for the bar and I needed the opposite, a fixed width for the bar and a variable padding. It was easier with a point scale for me, but if you need a variable width, band scale is the way to go for the x coordinate.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10f1593a2572d6b0b6ef99c067da429b/href">https://medium.com/media/10f1593a2572d6b0b6ef99c067da429b/href</a></iframe><p>With this code, we have created the following graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*bi1EogkpkVg0Pp4LXrjqBA.png" /><figcaption>Bar chart</figcaption></figure><h3>Add some details</h3><p>We will then add some details using components you already used. We will draw two dashed lines: one on the top, one in the middle. We will add a label on top of the top dashed line with a rounded top value and the unit. <strong>Round</strong> and <strong>unit</strong> will be two new props.</p><p>Here is the final code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d96b8de51a42fa1af12a1c0d5bb794c/href">https://medium.com/media/9d96b8de51a42fa1af12a1c0d5bb794c/href</a></iframe><p>Here is the final result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*cU6iTKKs84hEeGsP22MDtw.png" /></figure><p>I hope you enjoyed this tutorial. There is a lot more you can do with D3.js and react-native-svg. This little tour should help you get confortable with the basics and give you what you need to create your own beautiful graphs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd0250813313" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/make-your-own-svg-graph-with-react-native-svg-and-d3-js-dd0250813313">Make your own SVG graph with react-native-svg and D3.js</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</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 use VueJs instead of jQuery]]></title>
            <link>https://medium.com/kaliop/how-to-use-vuejs-instead-of-jquery-ee6003ba323d?source=rss----50deb79dca0c---4</link>
            <guid isPermaLink="false">https://medium.com/p/ee6003ba323d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jquery]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Antonin Savoie]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 13:12:19 GMT</pubDate>
            <atom:updated>2019-11-18T14:13:58.077Z</atom:updated>
            <content:encoded><![CDATA[<h3>²How to use VueJs instead of jQuery</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*EuQPbxVrXEWCJssVrl-olg.png" /></figure><blockquote>If you want to understand all the content of this article, some knowledge of VueJs is required : <a href="https://vuejs.org/v2/guide/">https://vuejs.org/v2/guide/</a></blockquote><p>I’m lead dev at Kaliop and today I speak about how to use VueJs instead of jQuery.</p><p>For the french version of this article, <a href="https://tech.kaliop.com/utiliser-vue-js-a-la-place-de-jquery/">click here</a>.</p><p>I discovered <a href="https://tech.kaliop.com/en/technologies/vue-js/">VueJs</a> two years ago, and enjoyed to use it since then. I had the chance to work on three VueJs projects, mixed with other technologies. But after that, I came back to more classical “backend” project, with <a href="https://tech.kaliop.com/en/technologies/symfony/">Symfony</a>, eZPublish, even <a href="https://tech.kaliop.com/en/technologies/drupal-8/">Drupal</a>... and with jQuery to handle front click event sometimes.</p><p>We can create great things with that, but I was sad without VueJs, and work was less fun.</p><p>Until the moment I had to synchronize a lot of DOM elements together with jQuery, on an interactive basket for a <a href="https://tech.kaliop.com/en/sub-expertises/e-commerce/">e-commerce platform</a>. I totally blew a fuse, deleted all my code, and I started all over again with VueJs in only one sleepless night. And you know what? My life is happier since then !</p><p>And from that moment, I just wanted to use VueJs everywhere, everytime ! And Iam going to show you how to achieve that.</p><blockquote>Note : shown examples are not perfect, they could be refactored and improved, but I tried to stay as simple as possible. All the code and more is available here <a href="https://github.com/Erilan/replace-jQuery-by-vuejs">github.com/Erilan/replace-jQuery-by-vuejs</a></blockquote><p>First, let’s compare basic samples with jQuery and simple VueJs integration.</p><blockquote>A simple VueJs integration is including the vue library (by CDN for example), a div, and a little piece of script :</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d131c0d5e0531754e61542266fc509f/href">https://medium.com/media/0d131c0d5e0531754e61542266fc509f/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FErilan%2Fembed%2Fpreview%2FdQbZeY%3Fheight%3D600%26slug-hash%3DdQbZeY%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2FErilan%2Fpen%2FdQbZeY&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F595217.dQbZeY.small.820e2aa1-98c0-4d00-9e9e-af1ff8eebac7.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/19f743fa4518bbd6efd4681e23208815/href">https://medium.com/media/19f743fa4518bbd6efd4681e23208815/href</a></iframe><p>Not more complicated than jQuery integration !</p><p>First, let’see a basic dropdown (display a list of item when clicking a button) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5505b07b9616b0719cea40235e9f9064/href">https://medium.com/media/5505b07b9616b0719cea40235e9f9064/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FErilan%2Fembed%2Fpreview%2FVVZryv%3Fheight%3D600%26slug-hash%3DVVZryv%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2FErilan%2Fpen%2FVVZryv&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F595217.VVZryv.small.a9399814-1ea6-498d-96eb-f3c1ded30cb0.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a3f9ac59f1c269842eb487f8c6b4608/href">https://medium.com/media/6a3f9ac59f1c269842eb487f8c6b4608/href</a></iframe><p>Here, the jQuery version is shorter than the VueJs one. It’s a very simple example, it only reacts on a click event, and we toggle a class (jQuery) or we toggle a boolean (Vue). The Vue version is not really better, but it’s a bit more logical : we have a value representing the state of our dropdown, not just a class.</p><p>Now, let’s take a look at basic panels (content displayed when clicking a button) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cb94453ab70d41ac1b8b0ec14bef5c0/href">https://medium.com/media/0cb94453ab70d41ac1b8b0ec14bef5c0/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FErilan%2Fembed%2Fpreview%2FzMOPQg%3Fheight%3D600%26slug-hash%3DzMOPQg%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2FErilan%2Fpen%2FzMOPQg&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F595217.zMOPQg.small.fbeb1fcb-fd79-4f91-983c-580abd08fe9a.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4681c63f58dd29e0e0a0cec84609f02a/href">https://medium.com/media/4681c63f58dd29e0e0a0cec84609f02a/href</a></iframe><p>Here again, the jQuery version is shorter than the VueJs one. Again, we react on a click event, and we play with classes (jQuery), or we set a variable (Vue). Like the previous example, the Vue version is not really better, but it’s more logical. Instead of adding/removing classes, we have a state value representing which content is displayed.</p><p>Ok, go on with a more complicated sample : a recipe serves calculator</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3049400be01b44a0b4013afb90d5f6f1/href">https://medium.com/media/3049400be01b44a0b4013afb90d5f6f1/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FErilan%2Fembed%2Fpreview%2FqQWpqa%3Fheight%3D600%26slug-hash%3DqQWpqa%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2FErilan%2Fpen%2FqQWpqa&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F595217.qQWpqa.small.f8869b75-35fd-435a-b90a-a2e056110ccb.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0e1ca7c1a6350ec9660401832f4a111/href">https://medium.com/media/c0e1ca7c1a6350ec9660401832f4a111/href</a></iframe><p>Now, the Vue version is shorter than the jQuery one, and look smarter. In jQuery, we have to react on multiple event types, to read data from the DOM, to write innerHTML and to launch the compute at start.</p><p>In the VueJs solution, code is shorter, and embark more logic. We have a state value representing the serving number, and each ingredient line compute his amount. We are not reading and writing DOM anymore, we are just calculating interesting values when we have to, enjoying the reactivity of VueJs.</p><p>There is some cases where jQuery is shorted than Vuejs, but it’s easy to add true logic with Vuejs.</p><p>But now, if we want to use all the power of Vuejs and use components ?We can !</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FErilan%2Fembed%2Fpreview%2FRqbxEJ%3Fheight%3D600%26slug-hash%3DRqbxEJ%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2FErilan%2Fpen%2FRqbxEJ&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F595217.RqbxEJ.small.dbb022f7-02db-4715-acd9-8eb9f37f248f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/66533093748e09ce05d9397eb17e0175/href">https://medium.com/media/66533093748e09ce05d9397eb17e0175/href</a></iframe><p>We can create on the fly components, but writing html in a javascript string is often a bad idea, and not really reusable.</p><p>It’s time to go deeper with Webpack ! But it can be hard to use and configure, so we will use Webpack Encore (<a href="https://symfony.com/doc/current/frontend.html">https://symfony.com/doc/current/frontend.html</a>) which is a standalone Webpack wrapper created by SensioLab, the editor of Symfony.</p><p>We just have to install it, and some Vue related packages :</p><pre>composer require symfony/webpack-encore-pack<br>npm install — save node-sass sass-loader vue vue-loader vue-template-compiler</pre><p>In the generated file <em>webpack.config.js</em>, we have to enable the Vue loader :</p><pre>Encore<br>  // enables VueJs support<br>  .enableVueLoader()</pre><p>We can now create .vue files, and enjoy the strength of vue-template-loader :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dcac25a973340c6198193c7c8168ac2/href">https://medium.com/media/6dcac25a973340c6198193c7c8168ac2/href</a></iframe><p>To instantiate our vue, we simply add a div with a specific class and we handle mount in our javascript entry point :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22619635121d1dd687a95413448e06d0/href">https://medium.com/media/22619635121d1dd687a95413448e06d0/href</a></iframe><p>It’s now time to go deeper and deeper !</p><p>Let’s see what I call the <strong>widget approach</strong>. I show integration widgets in a Symfony application in this example, but it can work with any other tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9X4ZkelF5iOOUiAQ" /></figure><p>The idea is to compose pages as usual, rendered from server with static HTML, and to enhance it with some Vue parts, called <strong>Widgets</strong>. A widget can be unique, or reused. It can be independent, or linked with others with an event bus or a Vuex store.</p><p>With this approach, we need to be more rigorous. Here is a proposition of file architecture to handle our widgets, and Vue related files :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/0*RDTpSpkctPtNpPnh" /></figure><p>In our <em>js</em> directory, we have one folder for vue utilities, like mixins, plugins, directives, etc..</p><p>We have a <em>Widgets</em> folder, which contain all our widgets. Each widgets has his own directory, with the root vue, and their components. We can have a <em>Common </em>directory with common vues.</p><p>There is also a directory for the store, and one for others services, like api, eventBus, etc..</p><p>finally, we have our main Vue entrypoint : <strong>vueWidgetsHandler</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0602c0453ee6b1753a5453ce73ac7d32/href">https://medium.com/media/0602c0453ee6b1753a5453ce73ac7d32/href</a></iframe><p>This file is in charge of creating our widgets. It can be very generic, or fully customized.</p><p>For each of our widget, we are going to instantiate a Vue, with various options, like a store, a router, or props.</p><p>In this example, we use the DOM element <em>dataset</em> as values for props. It’s compliant with HTML and easy to use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d84a42d70710a7386ffa25ac55856738/href">https://medium.com/media/d84a42d70710a7386ffa25ac55856738/href</a></iframe><p>With a good combination of widgets, you can build websites that look like an application ! You can find a real example here (the mobile version is better ;) ) : <a href="https://www.make-my-box.com/">www.make-my-box.com</a></p><p>This article is long enough, but there are a lot of possibilities to enhance this approach, by playing with Vuex store, or eventBus !</p><p>Finally, jQuery is well known, there is plenty of plugins and libraries that speed up your project, but using Vue is very fun, and give another way to enhance your website ! His approach is cleaner, simpler to maintain, and bring new features like native data binding !</p><blockquote>All the code and more is available here : <a href="https://github.com/Erilan/replace-jQuery-by-vuejs">https://github.com/Erilan/replace-jQuery-by-vuejs</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee6003ba323d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kaliop/how-to-use-vuejs-instead-of-jquery-ee6003ba323d">How to use VueJs instead of jQuery</a> was originally published in <a href="https://medium.com/kaliop">Kaliop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>