<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nicolas Payot on Medium]]></title>
        <description><![CDATA[Stories by Nicolas Payot on Medium]]></description>
        <link>https://medium.com/@npayot?source=rss-c4c624857350------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hx6iUxIf0Kp10dmXr5LP9A.jpeg</url>
            <title>Stories by Nicolas Payot on Medium</title>
            <link>https://medium.com/@npayot?source=rss-c4c624857350------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:16:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@npayot/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Engineering Onboarding at Datadog]]></title>
            <link>https://medium.com/@npayot/engineering-onboarding-at-datadog-b1c736edef5e?source=rss-c4c624857350------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1c736edef5e</guid>
            <category><![CDATA[datadog]]></category>
            <category><![CDATA[onboarding]]></category>
            <dc:creator><![CDATA[Nicolas Payot]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 13:26:08 GMT</pubDate>
            <atom:updated>2025-02-20T10:33:33.446Z</atom:updated>
            <content:encoded><![CDATA[<p>After more than five years at Malt, I’m starting a new role at Datadog as a Senior Software Engineer in the Logs Config team. Here’s what my first week of engineering onboarding looked like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PlcS1QUrAYWhxqUCdm_qhQ.png" /></figure><p>Datadog holds onboarding sessions every two weeks. This one included about <strong>80 people</strong> (interns and full-time employees) from NYC, Paris, and remote offices. I had the option to attend in person in Paris with the new hires or remotely from the coworking space in Lyon. Since I’ll be working there, I wanted to take the opportunity to meet my new colleagues, whom I’ll see at least three times a week, so I chose the remote option. Also, spending a full week in Paris requires some planning, as I have two young children.</p><p>Datadog’s Lyon office is in the <a href="https://www.wojo.com/fr-FR/espaces-de-travail/wojo-lyon-3e-part-dieu">Wojo coworking space</a>, conveniently located near the main train station (Part-Dieu). It offers various amenities, including secure bike parking, concierge services, and, of course, snacks and drinks.</p><h3>Day 1</h3><p>My laptop arrived before my start date, preconfigured but password-protected, so I couldn’t use it until the first day. I assumed it would allow me to participate in the first onboarding session, but I quickly learned that passwords were not provided until the afternoon IT onboarding session. Datadog onboards the vast majority of new hires at their main offices (with paid travel expenses, of course). The sessions can then be attended from a Zoom-equipped room. Since I chose to do it from the Lyon&#39;s office (and unfortunately there isn’t such a room), I had to follow them from my phone, which was a bit challenging, but manageable. Datadog mentions that if you’re onboarding remotely, you need to use a personal device for the first few sessions (a detail I somewhat overlooked). On the bright side, my badge worked the first time and I had access to my Uber Eats Pro account for lunch!</p><p>The morning included two onboarding sessions:</p><ul><li><strong>“Welcome to Datadog”</strong> — an introduction to the product history and overview.</li><li><strong>“The People Team” </strong>— covering recruitment, retention, and employee development, along with onboarding tools and resources.</li></ul><p>In the afternoon, we had the long-awaited <strong>IT onboarding </strong>session, where I finally unlocked my laptop, set up my tools, and discovered… 84 unread emails.</p><p>Next was <strong>“Security Awareness”</strong>, covering phishing, passwords, device security, physical security, and travel policies — nothing surprising but essential to remember.</p><p>The final session, <strong>“Orientation Wrap-Up”</strong>, summarized the day and outlined the rest of the week.</p><p>I wrapped up the day with a meeting with my manager, who warmly welcomed me and walked me through the 30–60–90-day onboarding plan, outlining clear goals and expectations for the first three months.</p><h3>Day 2</h3><p>I started the morning with a 30-minute call with my <strong>mentor</strong>, a Staff Engineer who works with my team. At Datadog, each new hire is assigned a mentor whose goal is to provide you with a <strong>“lay of the land”</strong>. They will give you an overview of the role, introduces key stakeholders, and ensures a smooth onboarding experience in collaboration with the manager.</p><p>We then attended <strong>“Welcome to Engineering”</strong>, a 45-minute session covering the engineering organization, development processes, and guidelines for the first month.</p><p>This was followed by <strong>“Engineering Onboarding Overview”</strong>, which provided foundational knowledge and guidance on setting up our development environments. While Datadog has some standardized practices, teams have the flexibility to make their own decisions, and this session helped us understand how those choices are made.</p><h3>Day 3</h3><p>The day began with the <strong>“France Payroll &amp; Benefits”</strong> session, where the People Ops team introduced key contacts and walked us through HR tools for payroll and time off. They also outlined the various benefits related to health, family, finance, personal growth, and social activities — there are quite a few!</p><p>In the afternoon, we completed the <a href="https://learn.datadoghq.com/courses/datadog-foundation"><strong>Datadog Foundation Lab</strong></a>, a publicly available workshop. This multi-hour course introduces key Datadog products and concepts, including integrations, universal service monitoring, logs, metrics, monitors, service level objectives, and dashboards.</p><h3>Day 4</h3><p>After reading tons of documentation (Datadog’s knowledge base is huge), I met with my <strong>buddy</strong> in the late morning. In addition to having a mentor, each new hire is paired with a buddy from any team, who helps them get familiar with the company and culture. My buddy shared useful productivity tips and tools for managing the flood of new information.</p><p>In the afternoon, we attended two technical sessions:</p><ul><li><strong>“Base and Backend”</strong> — covering development fundamentals such as repositories, source control, code reviews, incidents, and documentation. The backend section touched on environments, tools, testing, and releases.</li><li><strong>“Frontend”</strong> — a hands-on workshop where we each opened a Pull Request to create a new page in a static app and push it to production, helping us grasp the development workflow.</li></ul><h3>Day 5</h3><p>The final day began with sessions on <strong>“Compute + Networking”</strong>. At Datadog, Compute refers to both the infrastructure powering Datadog’s services and the platform teams that manage those resources. The Networking session covered fundamental concepts, including communication between services across clusters and data centers.</p><p>Next, we had a deep dive into <strong>API Development</strong>, outlining key principles for both internal and external APIs.</p><p>We wrapped up with <strong>“Engineering Onboarding Wrap-Up”</strong>, which reviewed the engineering activities that take place throughout a quarter and provided an overview of what to expect.</p><figure><img alt="Datadog swag kit" src="https://cdn-images-1.medium.com/max/1024/1*nmNzarpb_SjH4LpmkNieUw.jpeg" /></figure><p>Datadog is the largest company I’ve ever worked for, and the sheer amount of information, people, products and processes to absorb has been a bit overwhelming — but also exciting. Everyone I’ve met has been super nice and helpful and has made me feel very welcome. This intense past week has felt like going back to school, and while it’s going to be challenging, I couldn’t be more eager to dive in. Plus, my team looks great.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1c736edef5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migration to Nuxt: where are we Today?]]></title>
            <link>https://blog.malt.engineering/migration-to-nuxt-where-are-we-today-9f98c2ad9b58?source=rss-c4c624857350------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f98c2ad9b58</guid>
            <category><![CDATA[product]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[nuxt]]></category>
            <category><![CDATA[developer-experience]]></category>
            <dc:creator><![CDATA[Nicolas Payot]]></dc:creator>
            <pubDate>Tue, 23 Jul 2024 08:08:42 GMT</pubDate>
            <atom:updated>2024-07-30T07:35:19.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgV9wr-MbINI-MAjuTlOUg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@huchenme?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Hu Chen</a> on <a href="https://unsplash.com/photos/marina-bay-sands-singapore-__cBlRzLSTg?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><p>At the beginning of last year, we published <a href="https://blog.malt.engineering/the-singapore-project-migration-to-nuxt-ce4019b8f86c">an article about the Singapore project at Malt</a>. The migration to Nuxt began in the fourth quarter of 2022, and by January 2023, approximately 10% of the applications were migrated. Let’s see what happened in between and where we are now.</p><h3>Our current progress</h3><p>As of July 2024, we have made significant progress in our migration efforts. We now have approximately 83% of applications migrated, out of a total of 25 applications. Another interesting figure is the number of lines of code. Somehow, it matches with the percentage of applications migrated, being around 83% as well. This is purely coincidental because applications obviously have different sizes. This represents a good 800k lines of code. The frontend codebase is estimated to have 1M LOC in total. If we take out our calculator, this means we managed to migrate around one application per month from January 2023 to July 2024. Of course, this is simply an approximation because some months were busier than others, but it provides a general indication of the average migration rate.</p><h3>Giving ourselves the means to move forward</h3><p>As you might expect, this was neither a one-person effort nor a team working in best effort mode. The first objective that we set was to complete the whole migration by the end of the first quarter of 2024. As you can see, we did not meet this target, but first let’s look at what we did to give ourselves an opportunity.</p><p>At Malt, the engineering team consists of almost 60 developers who are rigorously organized into product tribes and one platform tribe, and each tribe is composed of multiple squads (i.e. small teams). Product teams were asked to include technical migrations in their roadmaps. This entailed extensive back-and-forth communication with product directors and managers to ensure that everyone understands the Singapore project objectives. As a reminder, by incorporating Nuxt into our codebase, we aim to greatly simplify the developer experience and increase our velocity.</p><p>We also decided to build a temporary team (the Singapore squad) within the platform tribe to handle specific application migrations full-time in 2023. This team consisted of six members: our prior CTO, two backend devs, and three frontend developers. The purpose of this group of people was to unburden product teams so that we could avoid a complete product freeze for several months.</p><p>The Singapore squad migrated approximately 35% of applications between 2023 and Q1 of 2024. While we failed to migrate the entire codebase before the end of the first quarter of 2024, we helped avoid a product freeze.</p><p>Another goal of the Singapore team was to assist product teams with the new stack, either through direct collaboration in their daily tasks or by implementing shared core layers and features, such as the shared navigation menu, logging, alerting and monitoring, or feature flags and AB tests.</p><p>Throughout the many migrations, we established a framework for methodically migrating an application from Java Server Pages to Nuxt. Let’s look at this strategy. We’ll focus on the Singapore squad actions, although the product teams basically followed the same path.</p><h3>Migration strategy</h3><h4>Kickoff meeting</h4><p>We began each migration with a kickoff meeting involving the product squad, including the product manager and the tech lead. This meeting was crucial for aligning on the scope of the migration and ensuring everyone understood the objectives. We typically had one backend and one frontend developer from the Singapore squad to work on a single migration.</p><h4>Scoped focus</h4><p>A key principle of our migration was to avoid implementing new features during the process. We strictly focused on transitioning the existing code to Nuxt, preserving functionalities while updating the technology stack. This approach helped us maintain project scope while not delaying the migration process.</p><h4>Getting-started documentation</h4><p>We created detailed guides in our internal documentation, both for frontend and backend, so that anyone could get started easily. Indeed, when migrating an application from JSP to Nuxt, we’re creating a backend application that contains backend services and RESTful APIs, and a frontend application. This application can be Client-Side Rendered (CSR) or Server-Side Rendered (SSR) depending on the constraints. These guides include application’s dependencies, directories structures, configurations and shared core features integrations.</p><h4>Automated setup script</h4><p>To streamline the initial setup process, we decided to go even further and developed a shell script that automates the creation of both the backend and frontend applications. This ensured consistency across our migrated projects and drastically reduced setup time.</p><h4>OpenAPI contracts</h4><p>The Singapore migrations also introduced a new way to create and consume REST APIs. After a few experiments, we decided to specify our APIs using OpenAPI contracts and benefit from the generated code on both the backend and frontend. This approach was a game-changer, dramatically accelerating the way we built and consumed new APIs.</p><h4>Incremental migration with double run</h4><p>We didn’t want to spend weeks migrating entire applications in tunnel mode without first deploying them to production. At Malt, we rely heavily on feature flags, which allow us to deploy to production multiple times per day if necessary and easily enable/disable anything. However, we were unable to use this strategy because both applications (legacy and new) frequently used the same URLs. So we decided to utilize an HTTP header (<strong><em>X-Singapore-NewApp</em></strong>) to route traffic to the new application when it was present. We used a browser extension to enable/disable this header on our machines. This strategy allowed us to introduce and test new pages while maintaining production deployments as usual.</p><h4>Post-migration support</h4><p>Once the traffic was redirected to a new Nuxt application migrated by the Singapore squad, the team committed to supporting the owner team for two weeks. This transition period allowed us to address any immediate issues and ensure a smooth handover. After this period, the ownership of the application returned to the product team.</p><h3>Roadblocks</h3><p>While this process greatly helped with the migrations, we encountered a couple important issues on our journey to Nuxt that we think are worth mentioning and sharing.</p><h4>Cross-Request State Pollution</h4><p>Let us go back to April 2023. Our first Nuxt 3 SSR application is now in production. It manages the new home page and a number of landing pages. Everything is going well; SEO and performance metrics are better than expected. We are currently working on building the navigation menu for connected users (which will display user information as well as some specific calls to action). The first version is complete, all acceptance tests have passed, and we are ready to ship to production!</p><p><strong>We rolled back fifteen minutes later.</strong></p><p>Indeed, we discovered a very “slight” problem with the connected user menu. It randomly displayed the details of another user. 😱</p><p>We attempted to reproduce the issue locally, but it was difficult because we needed to simulate a large amount of traffic (we used Gatling and ApacheBench), and our development server frequently crashed under the pressure. However, we saw that the problem appeared on a frequent basis. We didn’t notice in our staging environment because there weren’t enough concurrent requests.</p><p>We spent days digging through our code and couldn’t uncover any specific reason why this behavior occurred. Let’s first look at what our code was doing:</p><pre>export function useUserState() {<br>    const user = useState&lt;UserInfo&gt;(&#39;user&#39;, () =&gt; ({}));<br><br>    const fetchUser = async () =&gt; {<br>        try {<br>            const userInfo = await $fetch&lt;UserInfo&gt;(`/api/user/me`);<br>            user.value = userInfo;<br>        } catch (err: unknown) {<br>            // Handling error<br>        }<br>    };<br><br>    return {<br>        user,<br>        fetchUser,<br>    };<br>}</pre><p>This code is simplified for the sake of this article but as you can see, we weren’t doing anything unusual. <strong><em>useState</em></strong> is not called outside of the <strong><em>useUserState</em></strong> composable and <strong><em>useUserState</em></strong> was indeed properly called in a script setup. An important point to know is that this <strong><em>fetchUser</em></strong> request was only called on the server side through <strong><em>useAsyncData</em></strong>.<strong> </strong>We also had a good look at what our <strong><em>&quot;/api/user/me&quot;</em></strong> endpoint was doing but investigations were inconclusive.</p><p>However, while delving into Nuxt code, we came upon the <strong><em>useAsyncData</em></strong> function definition. According to the documentation, this composable can be used to gain access to data that resolves asynchronously. It also avoids request duplication between server and client because it sets the page’s payload on the server side, thus making the data available on the client side, without an additional fetch call. Within this function (and as in many Nuxt composables) the<strong><em> useNuxtApp</em></strong> composable is used. This one is used to get the Nuxt application instance associated with the current request. Indeed, for each server request, a new Nuxt application instance is created.</p><p>We had strong concerns about the <strong><em>useNuxtApp</em></strong> function: somehow we were seeing payload data associated with another instance, but we couldn’t prove it.</p><p>So we decided to enlist the expertise of Nuxt’s founder, <a href="https://x.com/Atinux">Sébastien Chopin</a>. Our CTO contacted him and very quickly, a full-day pairing-session was organized. Within hours Sébastien and <a href="https://x.com/danielcroe">Daniel Roe</a> (Nuxt core team lead) found out about the issue and pushed <a href="https://github.com/nuxt/nuxt/pull/20910">a pull request</a> to fix it.</p><p><strong>Yes, this is something that we can do with the Nuxt community 💚</strong></p><h4>Memory Leaks in SSR applications</h4><p>Let’s move a bit forward in time and focus on the migration of the freelancer profile page. As you could expect, this is an important part of the platform (it’s one of the most popular pages and it brings a lot of traffic to Malt). It took more than three months to be fully enabled in production and was totally carried out by the product team that controls the scope. Obviously, it was decided that this would be an SSR application.</p><p>With Nuxt SSR applications, came a new type of issues we were not used to dealing with: server side memory leaks with Node.js.</p><p>Using Datadog runtime metrics, we could notice that we were consuming quite a lot of heap space for this application. The represented period here is from the 1st to the 11th of June 2023. The heap memory is increasing incredibly fast while dropping suddenly. The drop is explained by the fact that the pods are automatically restarted when the memory threshold is reached or when we perform a new deployment to production, which we did quite a lot trying to fix the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/0*geB9GMZfk5lawkpB" /><figcaption>Heap Space Usage of profile-front from 07/01/2023 to 07/11/2023</figcaption></figure><p>We didn’t yet have a way to create heap snapshots right before an “Out of Memory” error occurred in production, so we tried to reproduce the issue locally.</p><p>Nuxt proposes a preview mode that allows to run an application locally with the production build. By updating the preview script this way:</p><pre>&quot;preview&quot;: &quot;node - inspect - expose-gc .output/server/index.mjs&quot;</pre><p>We can use Chrome DevTools to have more insights on the application’s heap memory (with the <strong><em>chrome://inspect</em></strong> URL). Then, by simulating some traffic with specific tools such as Gatling or ApacheBench, we saw a net increase in the total memory heap size, which was predicted, but it never went down to where it started, even when garbage collection was forced, indicating that there was a leak somewhere.</p><p>We tried to compare heap snapshots between the moment where the application is running with no traffic and after it received thousands of requests but… have you tried reading and understanding a heap snapshot from a Nuxt SSR application?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dCfG0erGjz1lhfQu" /><figcaption>Heap snapshot of profile-front</figcaption></figure><p>So, we tried to find the root of the problem by dichotomy, meaning we started removing small parts of the code and performed a new inspection each time, until we found out a state where the memory was not leaking anymore. It was very time consuming but eventually we came across these lines:</p><pre>eventBus.on(&#39;event1&#39;, onEvent1);<br>eventBus.on(&#39;event2&#39;, onEvent2);<br>eventBus.on(&#39;event3&#39;, onEvent3);<br><br>onScopeDispose(() =&gt; {<br>    eventBus.off(&#39;event1&#39;, onEvent1);<br>    eventBus.off(&#39;event2&#39;, onEvent2);<br>    eventBus.off(&#39;event3&#39;, onEvent3);<br>});</pre><p>This code was directly called in a script setup, meaning the listeners were attached on server side and thus never released.<strong> </strong>Once the listeners were attached on the client side only (using an <strong><em>onMounted</em></strong> hook), the memory heap size went back to normal.</p><p>These were not the only walls we hit on the road.</p><p>There was this time where we published millions of events in a single queue of RabbitMQ (way more than consumers could handle) because of a missing session cookie in SSR requests. Also at some point we discovered that our Design System components (built with StencilJS) did not support SSR. Detailing these problems is beyond the scope of this already lengthy article, but we will cover some of them in <a href="https://blog.malt.engineering/malts-migration-to-nuxt-table-of-contents-2e658e9b4c6b">future posts</a>.</p><h3>Conclusion</h3><p>Malt’s engineering team has gained invaluable experience from the Singapore project. It has not only modernized our technology stack, but has also significantly improved the developer experience, particularly on the frontend. It resulted in a 35% reduction in lines of code, and a fivefold boost in our velocity.</p><p>We still have to work on the remaining 20% of the codebase that needs to be converted (while facing some more challenges) but we’re now better prepared with the knowledge and expertise to make this entire project a success.</p><p><em>Thanks to my colleagues for their review and suggestions during the editing process of this article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f98c2ad9b58" width="1" height="1" alt=""><hr><p><a href="https://blog.malt.engineering/migration-to-nuxt-where-are-we-today-9f98c2ad9b58">Migration to Nuxt: where are we Today?</a> was originally published in <a href="https://blog.malt.engineering/">malt-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro Frontend at Malt]]></title>
            <link>https://blog.malt.engineering/micro-frontend-at-malt-7461e8fe2cf9?source=rss-c4c624857350------2</link>
            <guid isPermaLink="false">https://medium.com/p/7461e8fe2cf9</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Nicolas Payot]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 13:11:29 GMT</pubDate>
            <atom:updated>2022-06-21T13:11:29.352Z</atom:updated>
            <content:encoded><![CDATA[<p>The product team at Malt is organized in tribes. A tribe is a big functional area reflecting a part of our business. It can be seen as a mini startup within Malt. Each tribe contains different squads, smaller teams that have all the necessary skills to ship a feature to production.</p><p>Talking about features, in the client tribe / conversion squad, we needed at some point to integrate a functional UI component already present in a specific part of the product (a Vue.js application called <strong>messenger</strong>), within another page (another Vue.js application called <strong>client-project</strong>).</p><blockquote>For the context, at Malt in our frontend, we use <strong>J</strong>ava<strong>S</strong>erver <strong>P</strong>ages flavored with a bit of home-made JavaScript modules, and multiple Vue <strong>S</strong>ingle <strong>P</strong>age <strong>A</strong>pplications.</blockquote><figure><img alt="The chatbox Micro Frontend" src="https://cdn-images-1.medium.com/max/1024/1*-3xtpooIMqbYoWkQ11nVaQ.gif" /></figure><p>There were a few ways we could do this:</p><ul><li>Create a shared Vue component (it could work since <strong>messenger</strong> and <strong>client-project</strong> were Vue applications). But we also needed the existing backend API from <strong>messenger</strong> (something we could do by proxifying <strong>messenger’s</strong> backend API from <strong>client-project&#39;s</strong> backend or by letting <strong>client-project</strong> makes direct calls to <strong>messenger&#39;s</strong> backend).</li><li>Duplicate the frontend between the two Vue applications. But the problem remains the same for the backend services.</li><li>Extract the component into a micro Vue application that can run in isolation, be managed and deployed autonomously, and be easily mounted on any page. Basically, a Micro Frontend?</li></ul><p>We chose the third solution, because even though the setup is likely to be more important than the two others ways, the component has rich-enough behaviors (with a backend API) and it brings more flexibility and autonomy since we do not need to deploy each host applications when we want to publish an update of this component.</p><p>This article will focus on our implementation, the technical challenges we faced and how we tackled them.</p><h3>A quick reminder about Micro Frontends</h3><p>We can find plenty of information about Micro Frontends for several years now (the term started to buzz around 2016). Here is brief definition of what they are: a (not so new) pattern where web pages / applications are split into different fragments. Each fragment can be owned by a different team so that they are developed, maintained and deployed in isolation.</p><h3>Including the Micro Frontend assets</h3><p>In our product, each web page comes from a JSP that includes all the necessary style and script bundles so that it works properly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29111d07499099cd062b5205a5260d45/href">https://medium.com/media/29111d07499099cd062b5205a5260d45/href</a></iframe><blockquote>&lt;c:url&gt; is a JSTL tag that allows URL rewriting. We use it to replace the given path with its hashed version for production caching.</blockquote><p>Assuming we would like to insert a Micro Frontend inside a given page, we would need to additionally include all related assets in the &lt;head&gt; and &lt;body&gt; tags. Although possible, this would be quite a pain to do it manually everywhere it is needed, and above all, we would have to build and deploy the host applications every time an update to the Micro Frontend is made (because the assets revisioning would change).</p><p>To overcome this issue, we created a single JSP file per Micro Frontend whose job is to include all necessary assets each MF needs. We called it starter.jsp.</p><p>Now, how can we use this file to get its content and include it (i.e. include styles and scripts) in the host applications? How about having a route / an API endpoint to serve this starter page? Then we could call it from the host applications and dynamically inject the required styles and scripts. This is the approach we chose, and while it raises the issue of the MF being asynchronously included, it allows it to be completely autonomous. There is no need to update and deploy the applications that use the MF when the latter is updated. Indeed, a simple API call is enough to get the latest content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xH5nBF9MCmHDl2nydUG_mQ.png" /></figure><h4>About assets dynamic inclusion</h4><p>As you can see on the previous schema, both host applications use JavaScript code to call a route in order to get a list of assets to include in their page. Basically, we are using the starter page as a manifest of our Micro Frontend&#39;s assets.</p><p>First, we need to GET that page content (a simple call using window.fetch does the trick). We then parse the resulting HTML content and extract every &lt;link&gt; and &lt;script&gt; tags, and we re-inject them at the right place within the current page (into &lt;head&gt; for &lt;link&gt; and into &lt;body&gt; for &lt;script&gt;). To this end, we use the DOM API to create a detached element (document.createElement(&#39;html&#39;)) and then query it.<br>For the sake of completeness, we have to admit that it is a bit more involved than the above explanation. Indeed, for security reasons modern browsers will not just let us dump scripts coming from elsewhere. To circumvent it, we have to recreate script tags attribute per attribute. See <a href="https://gist.github.com/nicolaspayot/5a165b7b6e4e890719650a605f7d9b4e">the full source here</a> for all the gory details.</p><h3>Sharing Vue dependencies</h3><p>Our Micro Frontends are basically tiny Vue applications. When included within a JSP whose content is handled by a Vue Single Page Application, we actually embed Vue dependencies twice. In our case, we often use the following ones: vue, vue-class-component, vue-property-decorator, vue-router, vuex, vuex-class. How could we share these dependencies so that they are not included twice in a same page?</p><h4>Meet Webpack DllPlugin and DllReferencePlugin</h4><p>Webpack DllPlugin creates two things: a manifest.json file and a JavaScript bundle of modules. The manifest.json file is used to map module imports from source code to the generated bundle of modules. It means that if an import matches an entry in the file, webpack will not bundle it in its outputs.</p><p>In our monorepo, we made a dedicated npm package with a specific webpack configuration whose job is to create a bundle that includes all Vue dependencies named above. This bundle is called vue_common_vendors.js. Here is our webpack configuration (for development):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8942cecde8ee41fe30a7265916957dd/href">https://medium.com/media/e8942cecde8ee41fe30a7265916957dd/href</a></iframe><p>Then, in the vue.config.js files of the Micro Frontends and the SPA that need it, we use webpack DllReferencePlugin to reference the previously created manifest.json file and avoid bundling common Vue dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b486eafe24a7cce1212305a67cfcc287/href">https://medium.com/media/b486eafe24a7cce1212305a67cfcc287/href</a></iframe><p>Finally, in our JSP, we just need to include this bundle of Vue common dependencies <strong>before</strong> including the JavaScript assets of the SPA and the Micro Frontend. Neither Vue application will contain these dependencies in its own bundle and will use it from vue_common_vendors.js.</p><h3>Communicating with the Micro Frontend</h3><p>Most of the time, there is a need to interact between a Micro Frontend an its host application. The simplest way to do that is to use standard CustomEvent. They are now very well supported by all browsers and their main purpose is to transmit custom data, just what we need. However, at Malt, we are using a custom home-made library.</p><p>Actually, we started to implement communication with CustomEvent but we encountered a case where we were dispatching an event before its listener had been added (i.e. before the Micro Frontend is loaded and ready). To solve this problem, we enhanced our events library with a method triggerOnceThereIsAtLeastOneListener that — if the listener corresponding to the dispatched event is not ready yet — stores the event in an array to be dispatched as soon as its listener is attached.</p><h3>Conclusion</h3><p>Currently, we have two Micro Frontends running in production on several pages. Let us recall what we were trying to achieve with them: integrate a UI component with rich behaviors — or even a small application — in multiple pages. Each Micro Frontend should be decoupled from host applications and be managed in total autonomy.</p><p>The approach we chose is certainly perfectible but regarding our context, it answers the problem we wished to solve.</p><p>Do not hesitate to post your feedback, we are always eager to have opinions from others! And if you feel like working on such challenges, feel free to <a href="https://careers.malt.com/careers.html">knock on the door</a>.</p><blockquote>Thanks to my fellow colleagues for their review and suggestions: <strong>Nicolas Grisey Demengel</strong>, <strong>Jean Helou</strong>, <strong>Achille Guillon</strong> and <strong>Kévin Carnaille</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7461e8fe2cf9" width="1" height="1" alt=""><hr><p><a href="https://blog.malt.engineering/micro-frontend-at-malt-7461e8fe2cf9">Micro Frontend at Malt</a> was originally published in <a href="https://blog.malt.engineering/">malt-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue.js Amsterdam 2022 — Day 1]]></title>
            <link>https://blog.malt.engineering/vue-js-amsterdam-2022-day-1-2759e9f0b1de?source=rss-c4c624857350------2</link>
            <guid isPermaLink="false">https://medium.com/p/2759e9f0b1de</guid>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Nicolas Payot]]></dc:creator>
            <pubDate>Mon, 20 Jun 2022 07:53:19 GMT</pubDate>
            <atom:updated>2022-06-20T07:53:19.824Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vue.js Amsterdam 2022 — Day 1</h3><p>This year, a part of the Malt frontend team had the opportunity to attend <strong>THE</strong> Vue conference of the year: <a href="https://vuejs.amsterdam/"><strong>Vue.js Amsterdam</strong></a>. Here is an article that takes a look back on the first of these two days. Another one will follow for the second day. But first, why did we even go there?</p><p>At Malt, engineers are spread across tribes and squads but also within guilds that represent communities of practices. The frontend guild is one of them and we use Vue daily in our product to solve users problems. We all mostly work remotely and from different cities and thus offices. In addition to getting up to date on all the latest topics on Vue and its ecosystem, this conference was the perfect occasion to spend physical time together, exchange and bring out new ideas about the challenges we meet everyday.</p><figure><img alt="Malt&#39;s frontend team, gathering for Vue.js Amsterdam 2022" src="https://cdn-images-1.medium.com/max/1024/1*NYQ18yFqL4lrmNVTItW8Fw.jpeg" /></figure><p>The event took place at <a href="https://goo.gl/maps/AZxwDRYh7umzQSkp7">Theater Amsterdam, Danzigerkade</a>, which has been described by the global Javascript leaders as the <strong>“greatest conference venue in the world”. </strong>Indeed, the <strong>500m2 screen</strong> and the cinema seats helped a lot enjoy the talks in the best possible conditions.</p><figure><img alt="Vue.js conference venue, Theater Amsterdam" src="https://cdn-images-1.medium.com/max/1024/1*r55sMK3Qd5pZqaL_3iLuag.jpeg" /></figure><h3>State of the Vuenion 2022</h3><p>The conference started with a <a href="https://www.youtube.com/watch?v=1ntuhMzAzU8">remote talk from Evan You</a>, creator of Vue, on the state of Vue and its ecosystem. As of today, Vue 3 has about <strong>800k weekly npm downloads</strong>, which is an <strong>increase of 70%</strong> since the default version launch and <strong>4 times more</strong> than last year. Vue 2.7 will be the last minor release of Vue 2, and it will have 18 months of LTS starting from the release of 2.7 stable. It is important to note that the <strong>end of year 2023 will probably be Vue 2 EOL</strong>. Vue 2.7 should facilitate the migration to Vue 3 (the Composition API and &lt;script setup&gt; are being ported 🎉). Evan also presented the major planned features of Vue 3.3 which include stabilizing Suspense and Reactivity Transform, improving SSR and supporting imported types in &lt;script setup&gt;.</p><h3>Getting more out of your Pinia stores</h3><p>If you use state management libraries with Vue and keep an eye on the ecosystem, you must have heard of Pinia. <a href="https://twitter.com/posva">Eduardo San Martin Morote</a> (member of the Vue core team and creator of Vue Router) deep dived into the replacement of Vuex and now recommended state-management solution: Pinia. He showcased with brio how it is easier and lighter to use than Vuex and how it is well integrated with the Composition API (use of composable functions in stores).</p><figure><img alt="Getting more out of your Pinia stores" src="https://cdn-images-1.medium.com/max/1024/1*VtEXJKNyTtOfphzEzLVSTg.jpeg" /></figure><blockquote>Fun fact, it is called Pinia because as a pineapple composed of individual flowers, each store is born individually, but they are all connected at the end.</blockquote><h3>Fast stories powered by Vite</h3><p>Since the creation of Vue.js, there is this habit of often choosing french words to designate tools and libraries from its ecosystem (last example to date being Vite, the new build tool). It is quite naturally that <a href="https://twitter.com/Akryum">Guillaume Chau</a> (also a member of the Vue core team), named his last creation: <a href="https://histoire.dev/">Histoire</a>. Histoire is an alternative to Storybook powered by Vite. It is a tool to generate stories that showcase and document components. It comes from the statement that Storybook is not optimal for Vue developers. Guillaume live coded a Vue 3 application with stories from Histoire. It was blazing-fast thanks to Vite and we could realize how great the DX is (native to Vite projects, instant reloading, highly customisable). Also, he ended his presentation by publishing the <a href="https://github.com/histoire-dev/histoire">GitHub repository</a> live. Histoire was born! Quite an impressive demonstration.</p><h3>The unwanted stack</h3><p>Surprisingly, not all talks were about Vue or its ecosystem. And that actually was a good thing. It brought a little bit of diversity in this heavy program on two days (no less than <strong>25 presentations!</strong>).</p><p><a href="https://twitter.com/MayaShavin">Maya Shavin</a>, Senior Software Engineer at Microsoft, gave an inspirational talk about how to deal with the urge to introduce a new tool / tech in an outdated stack. As you can guess, this comes with a lot of points to address first, such as answering the question: why is “this new tool” THE solution? What are the tradeoffs? How is the developer experience? How is community support? Are there any alternatives? How does it scale? …</p><h3>Reusable widgets that work</h3><p><a href="https://twitter.com/MariaLamardo">Maria Lamardo</a> is Head of Accessibility Training and Sr Manager of Accessibility Engineering at CVS Health. Her talk was a nice introduction / reminder (choose what fits you) on how to create accessible components with Vue. She demonstrated how to best use <strong>ARIA </strong>in well-known widgets such as buttons and modals.</p><h3>It&#39;s a (testing) trap! — common testing pitfalls and how to solve them</h3><p><a href="https://twitter.com/leichteckig">Ramona Schwering</a>, Software Developer at Shopware, presented common mistakes we all encounter when writing automated tests. They included issues in tests code organization (not respecting the pattern <strong>given / when / then</strong>), using classes as CSS selectors (instead of data-* attributes) or also using hard coded timeout when waiting for particular events to occur. Lots of good tips to make test writing and maintenance less painful.</p><h3>Animating with Vue</h3><p>As you can guess, this talk was all about animations in a Vue application. <a href="https://twitter.com/CodesOfRa">Ramona Biscoveanu</a>, Frontend Developer at SAP, did a great job by starting with a reminder on the use of &lt;transition&gt; and &lt;transition-group&gt; Vue tags to animate elements, and then by including GSAP and showcasing mind-blowing animations.</p><h3>The Nuxt Web</h3><figure><img alt="The Nuxt Web, by Sébastien Chopin, Co-Founder at Nuxt" src="https://cdn-images-1.medium.com/max/1024/1*6QPTrqp3qM5Bt0CuNbAEXA.jpeg" /></figure><p>This was the first talk about Nuxt. Who better to talk about the subject than <a href="https://twitter.com/Atinux">Sébastien Chopin</a> himself, Co-Founder at <a href="https://nuxtjs.org/">Nuxt</a>. He started to introduce the state of Nuxt with some key figures: since October 2016, there are <strong>46M</strong> npm downloads, <strong>300k</strong> live websites and <strong>18k</strong> GitHub contributors.</p><p>He then highlighted the differences of Nuxt 3 with Nuxt 2: rewritten in TypeScript, new minimalist web server (h3), bundling with Vite or Webpack 5 and of course, the use of Vue 3 as the UI framework. The team made a huge effort on the bundle size that is needed to create, let’s say, a hello world. It went from <strong>91.2kB</strong> of JavaScript files to a single JavaScript file of <strong>34.1kB</strong>.</p><p>The most impressive new feature is that Nuxt 3 allows <strong>ESR: </strong><a href="https://v3.nuxtjs.org/guide/concepts/rendering/#rendering-on-cdn-edge-workers"><strong>Edge Side Rendering</strong></a><strong>. </strong>It means that code can directly be rendered on CDN edge workers, such as CloudFlare Workers, Vercel Edge, Netlify Edge, … and thus reduce latency and costs. How cool is that?</p><p>The first stable version of Nuxt 3 should be released in summer 2022.</p><h3>Full stack development with Nuxt 3 and Nitro</h3><p><a href="https://twitter.com/_pi0_">Pooya Parsa</a> is Head of Framework at Nuxt. He gave an outstanding and deep-into-the-details talk about Nuxt 3 and especially <a href="https://v3.nuxtjs.org/guide/concepts/server-engine/">Nitro</a>, its new server engine. Nitro is directly developed by the Nuxt team, with 4+ years of server experience. Its main goal is to build and deploy universal JavaScript servers. Here are some of the benefits it offers: rapid development (zero config with HMR), filesystem routing (automatically registers server and API routes), TypeScript support out of the box, multi-provider (same codebase can be deployed to any provider), modules auto imports, code-splitting or also a built-in cache API.</p><figure><img alt="Pooya Parsa, Head of Framework at Nuxt" src="https://cdn-images-1.medium.com/max/1024/1*DKwql_mykJm5iMZKHDVXrA.jpeg" /></figure><blockquote>I wish it had been earlier in the day because the level of technical information was so dense.</blockquote><h3>Developer eXperience with Nuxt 3</h3><p><a href="https://twitter.com/danielcroe">Daniel Roe</a>, core team member at Nuxt, gave another presentation about Nuxt, focusing on the Developer eXperience. This was almost an entire live-coding session. We could get a good grasp on the most exciting features of Nuxt 3 in a real-world application. Despite a few glitches (the demo effect), he came through like a champ. Hats off Daniel!</p><h3>From startup to unicorn</h3><p><a href="https://twitter.com/_loick_">Loïck Le Digabel</a>, Frontend Chapter Lead at Backmarket, shared his experience on the challenges he faced when scaling from startups to unicorns. Previously at Blablacar before Backmarket, he lived this situation at least twice and managed to highlight some very interesting differences and take-aways between the two work environments. In a startup, every level of the company is at an early-stage, there is not a lot of money, the main goal is to capture market share and it is very likely to pivot. We need to go fast! Challenges are way different in a unicorn. We need to consider hypergrowth, growing teams and quality as a product. In the tech context, it is (usually) at this moment that we deal with automation, internationalization, legacy and especially the need to plan and act pragmatically.</p><h3>How to enable large scale collaboration between disciplines using Nuxt</h3><p><a href="https://twitter.com/joranquinten">Joran Quinten</a>, Senior Frontend Developer, and Yassine El Ouzzani, Solutions Engineer at Jumbo Tech Campus had the heavy task to speak for the last conference of the day. Fortunately, it was not too technical. Once again, we enjoyed detailed feedback from experience. They showed how their use of a Vue components library and a headless CMS running on Nuxt facilitates collaboration between people of different skills.</p><h3>Conclusion</h3><p>13 conferences in a single day is <strong>A LOT!</strong> Fortunately, everything was well-oiled so that we could enjoy the whole program. The place was amazing, there was plenty of good food, beverages and the Master of Ceremonies made sure to keep us entertained between the different sessions.</p><p>Stay tuned for day 2!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2759e9f0b1de" width="1" height="1" alt=""><hr><p><a href="https://blog.malt.engineering/vue-js-amsterdam-2022-day-1-2759e9f0b1de">Vue.js Amsterdam 2022 — Day 1</a> was originally published in <a href="https://blog.malt.engineering/">malt-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Elm syntax through TDD]]></title>
            <link>https://medium.com/@npayot/learning-elm-syntax-through-tdd-89a523240fe1?source=rss-c4c624857350------2</link>
            <guid isPermaLink="false">https://medium.com/p/89a523240fe1</guid>
            <category><![CDATA[elm]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[kata]]></category>
            <category><![CDATA[string-calculator]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Nicolas Payot]]></dc:creator>
            <pubDate>Fri, 08 Sep 2017 12:33:11 GMT</pubDate>
            <atom:updated>2017-09-11T08:58:05.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*DLkvRTG64yVWNqcC5zgBIQ.png" /></figure><p>I’ve been wanting to get a good grasp at <a href="http://elm-lang.org/">Elm</a> for quite some time now. Elm is a <strong>functional language</strong> that compiles to JavaScript. It gained a lot of attraction lately as functional (reactive) programming is increasingly used in front-end development. If you’re a JavaScript developer, I’m quite confident you’ve already heard about one, some or all of these libraries: React, Redux, Cycle.js, RxJS, MobX, Ramda, Immutable.js… All of them embrace functional programming patterns and principles.</p><p>Elm is said to be easy to learn and use. Well, this is what we’re going to see by implementing <strong>String Calculator Kata</strong> with <strong>Test Driven Development</strong>. Rules are described here: <a href="http://osherove.com/tdd-kata-1/">http://osherove.com/tdd-kata-1/</a>. For this exercise, we’ll only focus on the language syntax and patterns.</p><h3>Getting the environment up and running</h3><h4>Installing Elm</h4><p>I’ve followed the official <a href="https://guide.elm-lang.org/install.html">guide</a> and chose the <strong>npm</strong> package to get Elm on my machine. npm install -g elm will give you access to the following command line tools (<em>of course, Node and npm are required to use this method</em>):</p><ul><li>elm-repl: <em>play with Elm expression</em></li><li>elm-reactor: <em>get a project going quickly</em></li><li>elm-make: <em>compile Elm code directly</em></li><li>elm-package: <em>download packages</em></li></ul><p>It’s no more complicated than that. Only elm-repl and elm-package will be used in the context of this kata exercise.</p><h4>Testing Elm code</h4><p>As we’ll explore Elm with TDD, we need to find how to quickly run unit tests to get <strong>immediate feedback</strong>. Bonus point if they can automatically re-execute themselves as we write and update code (watch mode).</p><p>After a quick search, <a href="https://github.com/elm-community/elm-test">elm-test</a> appears to be a solid candidate. It provides an API (describe, test, Expect, fuzz) and the necessary tooling to run tests locally in a terminal. Install it with the following command: npm install -g elm-test.</p><h4>Init the project</h4><p>Initiating a project is really easy. All we need to do is create an empty directory, cd into it and run the following command: elm-test init. Here’s what we will get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*m_wLRSPrpCK2Epu9xT1ynQ.png" /></figure><p>elm-package.json describes the project’s informations and lists the required dependencies. These are downloaded in the elm-stuff directory. Example.elm shows how to create a test suite. First test is not implemented and if we try to run the suite with elm-test command, terminal output message will be quite informative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhxsCdwMlt_r_RwPxoKRow.png" /></figure><h3>Implementing String Calculator Kata</h3><blockquote>A <strong>code kata</strong> is an exercise in programming which helps a programmer hone their skills through practice and repetition. The term was probably first coined by <a href="https://en.wikipedia.org/wiki/Dave_Thomas_(programmer)">Dave Thomas</a>, co-author of the book <a href="https://en.wikipedia.org/wiki/The_Pragmatic_Programmer"><em>The Pragmatic Programmer</em></a>,<a href="https://en.wikipedia.org/wiki/Kata_(programming)#cite_note-pragmatic-1">[1]</a> in a bow to the Japanese concept of kata in the martial arts. — <a href="https://en.wikipedia.org/wiki/Kata_(programming)">Wikipedia</a></blockquote><p>In Test Driven Development, we move forward with <strong>baby steps</strong>. First step is to write a failing test. Then, make this test pass with a small amount of production code and then refactor. Finally, repeat the loop until all requirements are met. Shall we get started?</p><h4>First thought: syntax is weird</h4><p>In the String Calculator Kata, first step is to create a simple add method that takes 0, 1, or 2 numbers (as a string) and returns their sum. For example, add(&quot;&quot;) should return 0, add(&quot;1&quot;) 1 and add(&quot;1,2&quot;) 3.</p><p>Let’s write the first failing test:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c98c498e6cab7b3e96a8884073f67f9/href">https://medium.com/media/8c98c498e6cab7b3e96a8884073f67f9/href</a></iframe><blockquote>elm-test —-watch is the way to run this test suite with watch mode. It means every time we’ll write or update code, a tests run will automatically be triggered. Pretty neat!</blockquote><p>First things first. Ok, import statements are quite familiar, but, what is this lack of parentheses and curly brackets? It appears <strong>Elm uses whitespace and indentations instead of those</strong> (although parentheses are necessary in specific cases).</p><p>Here, test is a function that takes a first argument as a string and a second argument as a function that evaluates a single Expectation (actually, test is a function that returns a function. Indeed, <strong>functions are </strong><a href="https://en.wikipedia.org/wiki/Currying"><strong><em>curried</em></strong></a><strong><em> </em>by default with Elm</strong>).</p><p>Next, what the heck is this: &lt;|\() -&gt;? Well, &lt;| is used to <strong>reduce parentheses usage</strong>. For example, leftAligned (monospace (fromString &quot;code&quot;)) can also be written that way: leftAligned &lt;| monospace &lt;| fromString &quot;code&quot;. Isn’t it better (I guess…)?</p><p>Finally, \() -&gt; is used to implement anonymous function. The empty parentheses are what’s called a <strong>unit</strong> type. A type that can only ever have a single value (which is ()). \_ -&gt; can also be used where _ is a placeholder for any value.</p><p>Now, let’s write the code to make this test pass:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ee2a0eb5b787de71f70b8c002f55f9b/href">https://medium.com/media/9ee2a0eb5b787de71f70b8c002f55f9b/href</a></iframe><p>Done. Baby step! Let’s go a bit further, shall we? No need to refactor yet, here’s a second failing test where we will try to get the sum of 2 numbers:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb597ec1979224318b2c5cb40b46c9e4/href">https://medium.com/media/cb597ec1979224318b2c5cb40b46c9e4/href</a></iframe><h4>Using List and Result</h4><p>I didn’t get the solution for this test right away. Checking if the string has a , and then split is quite obvious but I had to understand how List works and how to convert String to Int with Elm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b73e1b3c3cc4c976288f6f4e4b5a2fac/href">https://medium.com/media/b73e1b3c3cc4c976288f6f4e4b5a2fac/href</a></iframe><p>Here, we use the map method to convert our String number to an Int. String has a built-in function (toInt) to do this task, but the thing is that it returns an object of type Result, because this kind of task can fail. And <strong>Elm treats errors as data</strong> (<strong>no runtime errors</strong>, looking at you JavaScript!). So, Result is an object that’s either Ok (when task succeeded) or Err (when task failed). Then, all we need is to return the actual value when Ok or a default value (0) when Err. Exactly what Result.withDefault function does.</p><p>Finally, we use the List.sum method to get the sum of our Int numbers. Notice the use of |&gt; to reduce parentheses usages. The output of the left part is the input of the right part. I personally find it very convenient and logical after a bit of practice.</p><h4>Refactoring</h4><p>What we can do here to refactor is create a function splitWithSeparator whose responsibility is to check if a string has a given separator and then split this string into a list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8e2696a2b2cc58fee54fad971bfe0da/href">https://medium.com/media/d8e2696a2b2cc58fee54fad971bfe0da/href</a></iframe><p>In the case where the string of numbers doesn’t contain any separator (it means there’s only one number), we just append the number to a list, so that in both cases, splitWithSeparator will return a List (in Elm, a function has to return the same type in every branch of code).</p><h4>Handling new lines between numbers</h4><p>Next step of the kata is to allow add method to handle new line character \n between numbers, so that for example, add(&quot;1\n2,3&quot;) will return 6.</p><p>Let’s add another new failing test for this case:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed670a8a34e5475b00cccfdcebd91114/href">https://medium.com/media/ed670a8a34e5475b00cccfdcebd91114/href</a></iframe><p>My first attempt to make this test pass was to split the string with \n as separator and then split again each chunk of string with , as separator, which gives us a list of lists of strings. That’s not very elegant (actually not at all) but it works, thanks to List.concatMap that maps its given function onto a list and flatten the resulting lists.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e479d2c2877f53a29b3054b8e48c624/href">https://medium.com/media/4e479d2c2877f53a29b3054b8e48c624/href</a></iframe><h4>Regex to the rescue</h4><p>Although the solution with concatMap works, we can do better. How about using a simple regex to split our string of numbers wherever there’s either \n or , as separator? Let’s refactor the splitWithSeparator method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdcf6bb606fd986b62b7ab92873dddd0/href">https://medium.com/media/cdcf6bb606fd986b62b7ab92873dddd0/href</a></iframe><p>Regex.split splits a string into a list using a given Regex.regex separator. It also needs to know how many matches we want to make. Here we need to find all the characters that match the following pattern: \\n|,. So, we use the Regex.HowMany data structure value: Regex.All. Our method is greatly simplified, isn’t it?</p><h4>Handling custom separator</h4><p>I think this step is the hardest but hang in there! So now we need to handle custom separator in our add method. A custom separator should be specified at the beginning of the string of numbers, the following way: &quot;//[separator]\n[numbers]&quot;. For example: add(&quot;//;\n1;2;3&quot;) should return 6. Of course, this should be optional and all previous scenarios should still be supported. Let’s repeat the loop and add the failing test:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08c477e0ca466268b7f8ab5e652ac70d/href">https://medium.com/media/08c477e0ca466268b7f8ab5e652ac70d/href</a></iframe><p>Here, what comes to mind first is to check if the string contains a custom separator, extract it if present and then repeat the split and convert steps. How does that sound? Ok, get ready, we’re about to get our hands dirty!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee9a8b612e9c907451c7a70110059558/href">https://medium.com/media/ee9a8b612e9c907451c7a70110059558/href</a></iframe><p>What do we have here. 3 new functions: startsWithSeparator, extractSeparator and removeSeparatorPattern. Also, there’s this let ... in thing we’ll explain a bit further.</p><p>startsWithSeparator is quite easy, we’ll use Regex again but this time with the contains method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3369775b70673e4f5539c619ac834750/href">https://medium.com/media/3369775b70673e4f5539c619ac834750/href</a></iframe><p>extractSeparator is a bit touchy. Notice the new regex we’re using: ^//(.+)\\n (see above). Parentheses are here to capture any character(s) that will be between // and \n. This is our custom separator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7b2bd87430a3717e7e6bb20713ba2bc/href">https://medium.com/media/e7b2bd87430a3717e7e6bb20713ba2bc/href</a></iframe><p>Regex.AtMost 1 means we’re looking for 1 match only. Regex.find returns a list of Match objects. Each Match contains a submatches field, which is a list of subpattern(s), the pattern(s) surrounded by parentheses. It can be empty as all regex don’t have subpattern. By using List.concapMap, the lists of submatches are flatten into an unique list. Then, we can extract our custom separator string with List.head, which gives us the first item (in our case, there will always be one item).</p><p>The unwrap function is used to extract the current value of a Maybe wrapper. Here, it’s kind of unsafe because if there’s no value (Nothing), the program will crash. However, in our case, it should never happen. We need to apply this util function twice because our custom separator is actually wrapped twice in a Maybe object. Indeed, submatches is a list of strings enclosed in Maybe objects, and List.head returns the head of the list as a Maybe object as well.</p><p>Let’s take a step back to let ... in. If you’re familiar with JavaScript (ES6+), you know let can be used to declare variables. Well, it’s the same with Elm except that the declared variables have to be used within a in block. It might seem a bit weird at first but it’s a good way to enclose variables, as they’re not available outside their block.</p><p>Finally, removeSeparatorPattern will return a new string, without the custom separator at the beginning. It’s quite straight forward:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d6f63767049dce2274e10158a4dc109/href">https://medium.com/media/6d6f63767049dce2274e10158a4dc109/href</a></iframe><h4>Refactoring, again</h4><p>Now (if you’re still here…), all of our tests should pass but the add method got a little bit complicated. What we could do is create a function to extract the list of string numbers (with or without custom separator) and let the add method only calculate the sum of these numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ce63eb6480ece8a92f6777e5d9f2a44/href">https://medium.com/media/9ce63eb6480ece8a92f6777e5d9f2a44/href</a></iframe><p>As you may notice, we remove the second argument of startsWithSeparator function. It’s actually not necessary as we’re always looking for the same customSeparator pattern. extractSeparator is renamed with extractCustomSeparator for more clarity, and its second argument removed as well (we use the hard coded variable customSeparator within the function). Also, we add a splitWithString function as we don’t need regex to split a string of numbers with a given string separator.</p><p>As a result, here’s the simplified add method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f683c0e6141c16f42377752eacb6b960/href">https://medium.com/media/f683c0e6141c16f42377752eacb6b960/href</a></iframe><h4>Negatives are not allowed</h4><p>This is the last rule for this kata. Calling add with a negative number should throw the following exception : “<em>Negatives are not allowed” </em>, followed with the negative number (a list if there are multiple negatives). Actually, there are 4 more steps we could add, but that’s plenty enough for this article…</p><p>Before writing the corresponding failing test, let’s look at how to handle errors / exceptions with Elm. By searching through the official documentation, we can find an interesting object: Result.</p><blockquote>Result is either Ok meaning the computation succeeded, or it is an Err meaning that there was some failure.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7aca6ffa0c120d095aaacac968ff71b/href">https://medium.com/media/f7aca6ffa0c120d095aaacac968ff71b/href</a></iframe><p>By running this unit test, that obviously fails, we get the following error message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOStmqJRxrLpVVT_22QNAg.png" /></figure><p>I like how informative it is. Indeed, the add method currently returns an Int object whereas it should be a Result (wrapping a string when Err and an Int when Ok).</p><p>First, we need to refactor all of our previous tests so that the assertions look like this: Expect.equal (StringCalc.add &quot;1,2&quot;) (Result.Ok 3). Now, all tests should fail, but that’s ok. All we need to do to make them pass is change the return type and value of the add method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73e255c6f9c225b0dc971165c66c66d9/href">https://medium.com/media/73e255c6f9c225b0dc971165c66c66d9/href</a></iframe><p>All right, we’re back on track! Only the last one with the negative number should now fail.</p><p>Let’s write a function to check if there’s a negative number in the list. It’s quite simple thanks to List API (one line’s enough):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57b0eb9d3296e61a608d8a6e827b94f2/href">https://medium.com/media/57b0eb9d3296e61a608d8a6e827b94f2/href</a></iframe><p>Now, let’s update the add method with this new piece of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab0d9b49de975df6d240288b8cc595d9/href">https://medium.com/media/ab0d9b49de975df6d240288b8cc595d9/href</a></iframe><p>As you may have noticed, containsNegative expects a list of Int numbers. Thus, we update extractNumbers to return a list of Int (instead of String) numbers .</p><p>Test should be green! Ok, it will obviously fail if the negative number is different than -1 but, remember, <strong>baby steps!</strong></p><h4>Refactoring again² (lightly)</h4><p>By updating extractNumberList we duplicated some code: |&gt; List.map toInt. Indeed, it is necessary in both branches (in case numbers list start with custom separator or not). One simple way to remove this <a href="https://en.wikipedia.org/wiki/Code_smell">code smell</a> is to extract it into a function that we can use within the add method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0d583d5f8158f63d18b70c594c38922/href">https://medium.com/media/e0d583d5f8158f63d18b70c594c38922/href</a></iframe><h4>Handling negatives list</h4><p>Here’s the last failing test we’ll add for this kata:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39ecc99cddceb1dc8c4208499c90b7fd/href">https://medium.com/media/39ecc99cddceb1dc8c4208499c90b7fd/href</a></iframe><p>2 steps are required to make it pass: extract the negative numbers and display them in the error message. Let’s repeat the loop and implement these functions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6abb789f6b1c13f3807b7b1c5ef8015b/href">https://medium.com/media/6abb789f6b1c13f3807b7b1c5ef8015b/href</a></iframe><p>Then, add method should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7a8fb20826182ad8e5210207b12d5e0/href">https://medium.com/media/f7a8fb20826182ad8e5210207b12d5e0/href</a></iframe><p>Finally, all our tests should pass. Isn’t it satisfying?! 😎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dICaQg7TeE926ZJPaxWbbw.png" /></figure><blockquote>All the code is available on my ⭐️ <a href="https://github.com/nicolaspayot/string-calc-elm"><strong>Github</strong></a><strong> ⭐️</strong>. I tried to separate each step with a different commit, which should give you a good overview of progress.</blockquote><h3>Conclusion</h3><p>I think TDD (if you’re experienced enough with it) is a good way to learn a new language. Although, it might be a good idea to start with a code kata you’re familiar with. I didn’t know String Calculator and I struggled quite a bit at first, having to understand Elm stuffs and figuring out how to fulfil the kata requirements at the same time.</p><p>Coming from JavaScript, Elm syntax seems a bit weird and the way to do things is quite disturbing. But that feeling doesn’t last long once you start playing with the core libraries and their API. Documentation is really nice and detailed with lots of examples. Also, error messages are very informative. They’ll show you just what you need to fix your problem.</p><blockquote>Please, feel free to add feedback, I’m sure there are better ways (more Elm-ish) to handle this coding exercise. I’d love to hear more about it from Elm developers.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89a523240fe1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Migrate from AngularJS to Vue]]></title>
            <link>https://medium.com/dailyjs/how-to-migrate-from-angularjs-to-vue-4a1e9721bea8?source=rss-c4c624857350------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a1e9721bea8</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ngvue]]></category>
            <category><![CDATA[angularjs]]></category>
            <dc:creator><![CDATA[Nicolas Payot]]></dc:creator>
            <pubDate>Tue, 23 May 2017 10:31:01 GMT</pubDate>
            <atom:updated>2017-06-26T15:33:52.953Z</atom:updated>
            <content:encoded><![CDATA[<h4>…using ngVue</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*aNNZ2MNYy9pSI-ZUkx0o1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*4877k4Hq9dPdtmvg9hnGFA.jpeg" /></figure><p>Our front-end application at <a href="https://www.dawex.com/">Dawex</a> (<em>a marketplace for monetizing and acquiring data</em>) is a <strong>single-page app</strong> powered with <strong>AngularJS</strong>. The first lines of code were written during the summer of 2015. Back then, it totally made sense to choose this framework. The team had lots of experience with it and it fairly matched our needs for the platform. <strong>Angular</strong> <em>(the new one)</em> was only in alpha version. <strong>React</strong> had just started to become popular, used primarily among the front-end community, but we didn’t have enough experience with it. And <strong>Vue</strong>… well, it hadn’t yet <em>made it</em>.</p><p><strong>Who knew Vue would end up with the big players?</strong></p><p>Even though our app is developed with an <em>old</em> framework <em>(it saddens me to write that but, hey… 2009)</em>, we built a solid architecture and it scales pretty damn well!</p><p>From the very beginning, we always tried to stay on top and do what’s best for the platform and our users. Neither was the developer experience forgotten.</p><p>We’re using a full component-based design with modern JavaScript (ES2015+) and advanced tooling such as <strong>Babel, ESLint, Gulp, Jest, Redux, Webpack</strong>, and other great technologies that the JavaScript open-source scene has to offer.</p><h3>Then, what?</h3><p>As a front-end developer, I get excited every time a new shiny framework / or tool (you name it) pops up in my Twitter feed (<em>of course, this doesn’t mean it’ll land right away in our stack)</em>. As you can guess, <strong>Vue piqued my interest — </strong>so much so that I thoroughly wanted to start to migrate our application from AngularJS over to Vue.</p><p>The Vue API is much simpler. It’s pretty impressive how fast it is to get on track with it.</p><p>For instance, you only need a single file (.vue) to create a component, and there you go — ready to use! Sometimes, I still get confused with the camelCase/kebab-case specification between declarations and use in HTML templates with AngularJS.</p><p>We don’t really suffer from performance problems, but let’s be honest: dirty checking is just NAY. Reactivity system within Vue is unobtrusive and combined with its lightweight virtual-DOM implementation, it allows change detection to be lightning fast.</p><p>Also, the developer experience is way better. I find myself much more satisfied and enthusiastic when developing with Vue. I won’t go any further with <strong>Vue vs AngularJS</strong>, there are plenty of other blog posts about it.</p><p>Back to the migration topic. It can’t be done in one shot. It should be progressive and as smooth as possible.</p><p><em>The next part of this article details some thoughts I had about this challenge:</em></p><h3>Meet ngVue</h3><p><a href="https://github.com/ngVue/ngVue">ngVue/ngVue</a></p><p><strong>ngVue</strong> is an AngularJS module. It allows you to painlessly integrate Vue components within an AngularJS application.</p><p>What this means is that we could start any new development feature with Vue or convert an existing one.</p><blockquote>Here are slides about it from a talk I gave at LyonJS meetup: <a href="http://slides.com/npayot/ng-vue">http://slides.com/npayot/ng-vue</a>.</blockquote><p>This module offers a directive: vue-component, and a factory: createVueComponent.</p><p>The directive gives the possibility of embedding a Vue component with its defined properties. The factory will yield to the same result as it creates a reusable directive that is bound to a specific Vue component.</p><h4>vue-component</h4><p>As an example, let’s say we have a simple Vue component that we’d like to add within an AngularJS one:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a7f5e5b36ae3daf932423aa7694d850/href">https://medium.com/media/0a7f5e5b36ae3daf932423aa7694d850/href</a></iframe><p>Here’s the AngularJS component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce0292fed1321fe0aace90a9c52102a1/href">https://medium.com/media/ce0292fed1321fe0aace90a9c52102a1/href</a></iframe><p>As you can see here, the vue-component directive takes two attributes: name and vprops.</p><p>name should be the Vue component name registered as a value in an AngularJS module. vue-component needs it so that it can get, in its link function, the Vue component instance through the $injector service. This way, it can be instantiated and rendered on the &lt;vue-component&gt; tag. Also, ngVue module needs to be added to the AngularJS main module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f69eef1c1bb5255e412eb8a21837de5a/href">https://medium.com/media/f69eef1c1bb5255e412eb8a21837de5a/href</a></iframe><p>vprops allows you to pass data from an AngularJS context to the Vue component. It can also be used this way, giving you a finer control to your component properties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d33b5778a72b3475316b8abee85fbaac/href">https://medium.com/media/d33b5778a72b3475316b8abee85fbaac/href</a></iframe><h4>createVueComponent</h4><p>This factory is interesting because it enables the binding of a Vue component to a custom directive. Thus, using vue-component is not necessary, neither registering the Vue component as a value, and your own custom tag can be used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ba189a956c4e9f29327a1da2598d71d/href">https://medium.com/media/3ba189a956c4e9f29327a1da2598d71d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/340bc973d677ab1542f15562b702f827/href">https://medium.com/media/340bc973d677ab1542f15562b702f827/href</a></iframe><p>Integration of Vue components is a first step in the migration path.</p><p>Unfortunately (<em>in this particular case…</em>), AngularJS comes with a thick layer we can’t use within Vue: <strong>Dependency Injection</strong>. If you’re developing and maintaining an AngularJS app for years, I bet you’ve created a bunch of sweet services / factories / providers. This would be a shame not being able to use them within Vue components, wouldn’t it? <em>At least during the cohabitation of AngularJS and Vue</em>. Well, there might be a solution… Let’s explore it!</p><h3>Using AngularJS services within Vue components</h3><p>Thanks to ES2015 modules, AngularJS services instances can be exposed and then imported. <strong>No dependency injection!</strong> To enable this mechanism, services instances have to bet fetched in AngularJS context. $injector to the rescue! Here is how it works:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f91e47b313bee4f7491f94c102daa6cf/href">https://medium.com/media/f91e47b313bee4f7491f94c102daa6cf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19dfe29a07c37ffefe8511c4510c73a3/href">https://medium.com/media/19dfe29a07c37ffefe8511c4510c73a3/href</a></iframe><p>Then, we can simply import and use helloService instance anywhere: import { helloService } from &#39;path/to/hello.service;</p><h3>TADA! 🎉🎉🎉</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*4877k4Hq9dPdtmvg9hnGFA.jpeg" /></figure><h3>Conclusion</h3><p>I think ngVue and getting rid of dependency injection for AngularJS services (<em>well, sort of…</em>) represent a good approach to progressively migrate to Vue.</p><p>Obviously, there are other limits and challenges to be met that will eventually be the subject of another blog post when we start. 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a1e9721bea8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dailyjs/how-to-migrate-from-angularjs-to-vue-4a1e9721bea8">How to Migrate from AngularJS to Vue</a> was originally published in <a href="https://medium.com/dailyjs">DailyJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>