<?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 Charpentier on Medium]]></title>
        <description><![CDATA[Stories by Nicolas Charpentier on Medium]]></description>
        <link>https://medium.com/@charpeni?source=rss-932a4e7a9846------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6O6yRjrdzHa6svAFd9dyWA.jpeg</url>
            <title>Stories by Nicolas Charpentier on Medium</title>
            <link>https://medium.com/@charpeni?source=rss-932a4e7a9846------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 08:07:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@charpeni/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[Setting up an Example App for Your React Native Library]]></title>
            <link>https://medium.com/@charpeni/setting-up-an-example-app-for-your-react-native-library-d940c5cf31e4?source=rss-932a4e7a9846------2</link>
            <guid isPermaLink="false">https://medium.com/p/d940c5cf31e4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[metro]]></category>
            <dc:creator><![CDATA[Nicolas Charpentier]]></dc:creator>
            <pubDate>Mon, 01 Apr 2019 12:17:50 GMT</pubDate>
            <atom:updated>2019-04-01T12:17:50.560Z</atom:updated>
            <content:encoded><![CDATA[<h4>Having a hard time with a React Native example app? Here’s how you can simplify this with Metro bundler.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4k4nHaOd2zeP1-CHzQfTPA.png" /></figure><blockquote>Unable to resolve module … Module does not exist in the module map or in these directories … Naming collision</blockquote><p>There is probably a tonne of ways to create an example app for your React Native library, except almost each of them comes with some major downsides.</p><p>The naive and common approach will be to use: yarn add file:../ to add your library to your example app, and that would probably work great! But, you would have to reinstall your package on every lib change, if you don’t forget it. Some libraries are using something similar, with a custom script to automatically watch and update files on changes (<em>watchman / rsync</em>), this may be great engineering but certainly not the best developer experience! (See <a href="https://github.com/wix/wml">wix/wml</a>).</p><p>Then, what about symlinks? Well, <a href="https://github.com/facebook/metro/issues/1">Metro doesn’t follow them</a>, so you can forget about symlinks and yarn link or you will end up with:</p><pre>Unable to resolve module ...<br>Module does not exist in the module map or in these directories</pre><p>Also, even if you pass these steps you will necessarily have to meet this error:</p><pre>Haste module map naming collision duplicate module name</pre><p>This usually means you have duplicated <em>node_modules</em> that have been copied over your lib and the example app, so there is no easy exit with conventional methods.</p><p>What if I told you that there is an easier way, without hassle?</p><h3>Link your library using 🚇 Metro</h3><p>With <a href="https://facebook.github.io/metro/">Metro bundler</a>, you can link your library to an example app without any extraneous dependencies.</p><ul><li>No need to <strong>sync</strong> your library on each change.</li><li>No need of <strong>symlinks</strong> (which are not followed by Metro).</li><li>No need to hassle with duplicated <strong>haste modules</strong>.</li></ul><p>Starting from 0.59, React Native projects comes with a <a href="https://github.com/facebook/react-native/blob/aefb05941a60f05f15270361794dccc88f6a09ba/template/metro.config.js">metro.config.js</a> — before 0.59, filename and functionalities may differ — that allow us to configure Metro’s core concepts which are:</p><h4>Resolution</h4><blockquote>Metro needs to build a graph of all the modules that are required from the entry point. To find which file is required from another file Metro uses a resolver. In reality this stage happens in parallel with the transformation stage.</blockquote><h4>Transformation</h4><blockquote>All modules go through a transformer. A transformer is responsible for converting (transpiling) a module to a format that is understandable by the target platform (eg. React Native). Transformation of modules happens in parallel based on the amount of cores that you have.</blockquote><h4>Serialization</h4><blockquote>As soon as all the modules have been transformed they will be serialized. A serializer combines the modules to generate one or multiple bundles. A bundle is literally a bundle of modules combined into a single JavaScript file.</blockquote><p>In our case, we will have to configure one of these concepts — remember our previous issues with the haste resolver? — the <strong>resolution</strong>.</p><h4>Configuring Metro</h4><p>First, we will have to tell Metro to watch for an additional folder in addition to our example app folder, which is the library you want to link in addition to relying only on the app’s node_modules:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c55cc2833177a8f0ec8f7fd14a1ae7ce/href">https://medium.com/media/c55cc2833177a8f0ec8f7fd14a1ae7ce/href</a></iframe><p>Then, we have to explicitly tell Metro to blacklist node_modules/react-native/.* from your library folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f34d866d550ad4a30bfe33264672633a/href">https://medium.com/media/f34d866d550ad4a30bfe33264672633a/href</a></iframe><p>By doing this, we tell Metro to not resolve files that are matching our regex to prevent any haste collisions from happening. We may want to tweak our Regex or add additional ones if we have more than an example.</p><p>If you have native modules that you would like to link, you would have to edit the path referencing them as ../../ instead of accessing them directly from the example app’s node_modules .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/011ad3447763b08da3537d4332d0de2e/href">https://medium.com/media/011ad3447763b08da3537d4332d0de2e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bc5184d3e94f2c01245c425589c00a3/href">https://medium.com/media/2bc5184d3e94f2c01245c425589c00a3/href</a></iframe><p>Your example app should be up and running! 🎉</p><p>For further information, you can refer to <a href="https://github.com/charpeni/react-native-lib-example-app/commit/443d0b309efc5a606b12158c935bbde5b9858e94">this commit</a>.</p><p>For <a href="https://facebook.github.io/metro/docs/en/configuration">further documentation on configuring Metro.</a></p><p>A full example repository is also available here: <a href="https://github.com/charpeni/react-native-lib-example-app">https://github.com/charpeni/react-native-lib-example-app</a></p><h3>What’s next?</h3><p>Interested in testing this or you’d like to maintain or work on React Native libraries? Come see us in the <a href="https://github.com/facebook/react-native/issues/23313">☂️ Lean Core initiative</a>.</p><p>There’s also plenty of libs that are waiting on this developer experience improvement in the React Native Community:</p><p><a href="https://github.com/react-native-community">React Native Community</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d940c5cf31e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native at Classcraft]]></title>
            <link>https://medium.com/classcraft-engineering/react-native-at-classcraft-388c36df4f7c?source=rss-932a4e7a9846------2</link>
            <guid isPermaLink="false">https://medium.com/p/388c36df4f7c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Nicolas Charpentier]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 13:50:08 GMT</pubDate>
            <atom:updated>2018-07-23T13:50:08.015Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*VBTa87rbzpAr9F2J" /></figure><blockquote>We had to carefully find a way to introduce React Native bit-by-bit into the existing native application.</blockquote><p>At Classcraft, we are using JavaScript, especially <a href="https://www.meteor.com/">Meteor</a> and <a href="https://reactjs.org/">React</a> for our web apps, and before the last year, our mobile applications were coded in full native apps (Objective-C and Java). We’ve been struggling with legacy stuff and a lot of new features coming from our growing web’s codebase.</p><p>We’re a small team, and the mobile team don’t have a distinct team for iOS and Android. So, each time a refactor or a new feature comes in, we had to do it on both platforms. This was leading to many wastes of time and frustration, also all the business logics were initially coded and maintained in JavaScript (from the web apps), why should we have to rewrite it in Objective-C and Java then?</p><h3>Introducing React Native</h3><p>So, to minimize the maintenance cost and to improve the development cycle we looked into <a href="https://facebook.github.io/react-native/">React Native</a>. Unfortunately, we didn’t have the bandwidth to discard our native apps and redo everything with React Native.</p><p>In order to achieve that, we tackled this one step at the time, as this timeline shows. So, we had to carefully find a way to introduce React Native bit-by-bit into the existing native application, without wasting our resources on unwanted or unnoticed refactors but also while getting traction on the bugs and features planning.</p><h4>Summary of Classcraft’s Mobile App Timeline</h4><ul><li><strong>March 2014</strong>, initial commit.</li><li><strong>Sep 2016</strong>, both repos got merged into one with the first line of React Native.</li><li><strong>Spring &amp; Summer 2017</strong>, a lot of screens got rewritten as React Native views.</li><li><strong>June 2017</strong>, I joined the team. 🎉</li><li><strong>Fall 2017</strong>, the core of the application became a React Native app hosting jointly React and native views.</li><li><strong>Winter 2018</strong>, many new features got introduced fully in JavaScript using shared code from the web’s codebase.</li></ul><h4>First Contact Between Classcraft’s App and React Native</h4><p>Our initial goal was to gradually introduce React Native into an existing native application. We kept our existing structure, but some views get refactored into React Native views, and they were mounted by the <em>UIViewController </em>on<em> </em>iOS<em> </em>or a <em>Fragment </em>on Android (If you attempt a similar approach, you can refer to <a href="https://facebook.github.io/react-native/docs/integration-with-existing-apps">Integration with Existing Apps docs</a>).</p><p>The deciding factor was if we had to do any significant UI changes or bug fixes that would be easier to convert into React Native, do it. New features will be in React Native as well since all the business logic are ready — or almost — to use in our shared code. What I mean by shared code, is that all of our utils and business logic in JavaScript that applied to any platform had been exported into a folder that is used as a NPM package.</p><p>Here is a high-level overview of what was the structure of the app was after the first phase integration — remember that at this phase our React Native views were only meant to replace a <em>UIView</em> or <em>Layout</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*Sn5qyzk-1V0p7wGFq_XHAA.png" /></figure><p>It could be an entire view that got rewritten or even small components like the badge we’re using in the messaging section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*s_IOVbo-vvlR2Umhxns7fg.png" /></figure><p>Here is the native view we’re still using for the messages.</p><p>Noticed those green notification badges?</p><p>Those are, in fact, a React Native view that’s shown on each row by the native controller. This component is meant to receive some props from the native controller and then gather the information and display a badge, if necessary.</p><p>Then with this implementation, we can integrate this component into our both platform.</p><p>We were happy with this solution, and it improved our bandwidth since we didn’t have to replicate all the logic on each platform. But still, we had to tweaks native to declare and display our React Native views or with full React Native views, we have to declare some <em>UIViewController </em>and<em> Fragment to </em>host it and pass the required props. In short, it was a success, but not enough, the second phase will talk about this in deep.</p><p>Unfortunately, switching from native to React Native made us lose our typing. It leads us to introduced <a href="https://flow.org/">Flow</a> — a static type checker for JavaScript — into our codebase (web &amp; mobile). <a href="https://www.typescriptlang.org/">TypeScript</a> was also an option, but with our existing web codebase using Meteor, React, Webpack and Babel, we stick to an incremental introduction of Flow across our apps, with, of course, shared types.</p><h4>The Second Phase</h4><p>After successfully introducing React Native into existing apps, our goal was to switch from a native container to a React Native container, which use <a href="https://github.com/react-navigation/react-navigation">react-navigation</a> to display React Native and native views seamlessly. With this structure, we’ll be able to ship feature faster as we won’t have to touch any native code and it could be done by any web wizards.</p><p>So we made the switch following the docs about Native UI Components (<a href="https://facebook.github.io/react-native/docs/native-components-ios">iOS</a> / <a href="https://facebook.github.io/react-native/docs/native-components-android">Android</a>). But we end up coding our own solution to host <em>UIViewController</em> or <em>Fragment</em> instead of <em>UIView</em> or <em>Layout</em>. With this solution, we leverage our legacy views into a new app structure without having to refactor it (well actually we had to handle the navigation bar with react-navigation), but that was not a tricky part. I may write a technical blog post about this strategy to display directly a <em>UIViewController</em> or <em>Fragment</em>, just ping me if you’re interested.</p><p>We still have our native application “container”, but it’s only used to launch the React Native app and to handle the sign in/up process. Even the deep linking — except for login from third parties — is a passthrough handled by react-navigation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhtsYFitBU55gQPDLcCuJg.png" /><figcaption>Shortened schema of the application.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*LI5tKUKiQkdVr3MTrniY5A.gif" /></figure><p>Following this, the native side still handles data subscriptions, but our new React Native screens are handling their own subscriptions.</p><p>Also, translations are now loaded by React Native and then sent through the bridge to the native side. At the moment, the native can’t communicate synchronously with React Native, so we send the whole dictionary of terms to the native.</p><p>Except for these points, everything stays pretty much the same on the native side after the second phase. Now we’re slowly phasing out remaining native views!</p><h3>What’s Next for Mobile at Classcraft</h3><p>I can’t speak for the team, but I’m still happy with the choices I have made so far. I’m still pretty excited about JavaScript, and I’m glad our mobile application is now in JavaScript.</p><p>Still speaking for myself, I may have an eye on <a href="https://reasonml.github.io/">ReasonML</a> to leverage the typing and to keep up the functional paradigm, who knows where this is going.</p><p>We had some trouble with the integration of Meteor into React Native. Actually, we use <a href="https://github.com/inProgress-team/react-native-meteor">react-native-meteor</a>, and unfortunately, this is not the real implementation of Meteor, the core got rewritten, and it’s hard keeping the beat with Meteor (we’re actually the primary maintainer of this open-source lib). We encountered many not so funny issues, which I wrote about some of them <a href="https://github.com/Urigo/meteor-native-packages/issues/1#issuecomment-379782096">here</a>. Hopefully, we’ll have some time soon to dig into projects like <a href="https://github.com/Urigo/meteor-client-bundler">Meteor Client Bundler</a>, which sounds great for our case and to improve the sharing between our mobile and web applications.</p><p>We’re also excited about the state of React Native in 2018, especially with all the changes that <a href="https://facebook.github.io/react-native/blog/2018/06/14/state-of-react-native-2018">Fabric</a> will bring.</p><p>Have you experienced any integration of React Native into an existing app or used Meteor with React Native? What’s your experience so far?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=388c36df4f7c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/classcraft-engineering/react-native-at-classcraft-388c36df4f7c">React Native at Classcraft</a> was originally published in <a href="https://medium.com/classcraft-engineering">Classcraft Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrow Functions in Class Properties Might Not Be As Great As We Think]]></title>
            <link>https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1?source=rss-932a4e7a9846------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b3551c440b1</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Nicolas Charpentier]]></dc:creator>
            <pubDate>Thu, 16 Nov 2017 18:45:59 GMT</pubDate>
            <atom:updated>2017-11-16T18:46:36.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nr79p-m8ki2L3zepg1nc8g.gif" /></figure><p>Since the last year, the <a href="https://github.com/tc39/proposal-class-fields">Class Properties Proposal</a> simplify our life, especially in React with the internal state , or even with statics ones like propTypes and defaultProps .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5d3V8cnz05YCsxDBBvz8Rw.png" /><figcaption>Comparison between without (left) and with (right) class properties.</figcaption></figure><p>Furthermore, Class Properties/Property Initializers seems to be more trending in the last six months to handle binding in React instead of a bind call in the constructor.</p><h3>Cory House 🏠 on Twitter</h3><p>Poll: 📊 How do you typically handle binding in #react today? Examples of each: https://t.co/zOEfsiSQCX</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32cbbb93f2e39df3531e4a6b2fc98a9b/href">https://medium.com/media/32cbbb93f2e39df3531e4a6b2fc98a9b/href</a></iframe><p>Arrow functions in class field properties seem useful because they’re autobind, in short, no need to add this.handleClick = this.handleClick.bind(this) in the constructor.</p><p>But, should we really use arrow functions in class field properties?</p><p>First of all, let’s see what class properties do under the hood.</p><h3>What Class Properties look like once transpiled to ES2017</h3><p>Let’s code a simple class with a static property, an instance one, an arrow function in property, and a usual function as method with the plugin transform-class-properties .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e763dc6df8da437bd0a54f2cc96762c/href">https://medium.com/media/8e763dc6df8da437bd0a54f2cc96762c/href</a></iframe><p>Once we go to the <a href="https://babeljs.io/repl/">Babel REPL</a> to get this class transpiled to ES2017 with the following presets: es2017 and stage-2.</p><p>We got this transpiled version:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0292ad8376301be092a0f1f44d248b61/href">https://medium.com/media/0292ad8376301be092a0f1f44d248b61/href</a></iframe><p>As we can see, instance properties have been moved inside the constructor and the static one moved to an afterward declaration.</p><p>Personally, I like the addition of static keyword as we can now directly export a class with static properties.</p><p>On instance properties, it’s great too, because in our code (not transpiled one) the constructor will be less bloated with declarations.</p><p>For our arrow function in a property, handleClick got moved in the constructor too, such as an <strong>instance</strong> property.</p><p>For our usual function method handleLongClick, nothing change.</p><p>Property initializers may be useful for properties, but when it comes to arrow functions in class properties, it feel like a hackish way of achieving a binding.</p><p>Did you spot some issues? Let’s see what I found.</p><h4>Mockability</h4><p>If you want to mock or spy on a class method, the easiest and proper way to do so is with the prototype as all changes to the Object prototype object are seen by <strong>all</strong> objects through prototype chaining.</p><p>Let’s say we want to do some tests with our previous class A .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e763dc6df8da437bd0a54f2cc96762c/href">https://medium.com/media/8e763dc6df8da437bd0a54f2cc96762c/href</a></iframe><p>A.prototype.handleLongClick is defined.</p><p>A.prototype.handleClick is not a function.</p><p>Oops, since we used an arrow function in a class property our function handleClick is only defined on the initialization by the constructor and not in the prototype. So, even if we mock our function in the instantiated object, the changes won’t be seen by other objects through prototype chaining.</p><h4>Inheritance</h4><p>Let’s define our base class A .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d66c2c993e5489eb7cfce503622dd1b1/href">https://medium.com/media/d66c2c993e5489eb7cfce503622dd1b1/href</a></iframe><p>If class B inherit from class A ,handleClick won’t be in the prototype and we can’t call super.handleClick from our arrow function handleClick .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aca0840801a8479cef256a1553459c36/href">https://medium.com/media/aca0840801a8479cef256a1553459c36/href</a></iframe><p>If class C inherit of class A , but implement handleClick as a function instead of an arrow function, handleClick will only executes super.handleClick() and nothing else. Strange isn’t?</p><p>It’s because the instantiation of handleClick in the constructor of our parent class overrides it.</p><p>C.prototype.handleClick() will call our implementation but will fail with the previous error: Uncaught TypeError: (intermediate value).handleClick is not a function .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6023d35aa3b7876ca8012bbba298580f/href">https://medium.com/media/6023d35aa3b7876ca8012bbba298580f/href</a></iframe><p>If class D is a plain class that inherit from class A , he will have an empty prototype and new D().handleClick() will log A.handleClick .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be8299721456106a81e647745b10a1ab/href">https://medium.com/media/be8299721456106a81e647745b10a1ab/href</a></iframe><h4>Performance</h4><p>Now the interesting part, let’s talk about performance.</p><p>We know that usual functions are defined in the prototype and will be shared across all instances. If we have a list of N components, these components will share the same method. So, if our components get clicked we still call our method N times, but it will call the same <strong>prototype</strong>. As we’re calling the same method multiple times across the prototype, the JavaScript engine can optimize it.</p><p>On the other hand, for the arrow functions in class properties, if we’re creating N components, these N components will also create N functions. Remember what we’ve seen in the transpiled version, class properties are initialized in the constructor. Which means if we click on N components, N <strong>different</strong> functions will be called.</p><p>Let’s see how they are doing in a benchmark with V8 engine (Chrome).</p><p>The first one is simple, we only measure the instantiation time, and we call our method one time.</p><p>Beware that number doesn’t really matter in this one, since one instantiation won’t be noticed in your application and we’re talking about operations per second and the number are high enough. I’m more concerned by the gap between our functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kX8PygxLxltb4qRFW5efIw.png" /></figure><p>For the second one, I used a representative use case. The instantiation of 100 components — like a list — which after we called the method one time on each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NX_Iwhvl5zz2N8w-2ztVlg.png" /></figure><blockquote>All benchmarks were run on a MacBook Pro 13&quot; 2016 2GHz on Mac OS X 10.13.1 and Chrome 62.0.3202.</blockquote><p>In short, to improve performance, you should declare your shared method in the prototype and only bound it to the context if you need to (if you pass it as prop or callback). It makes sense to bound our shared methods to the prototype and initialized our properties in the constructor of each instance, but methods not much.</p><p>We’re still talking about high ops/s, but we clearly see that arrow functions in class properties are not as performant as we thought.</p><p>And yes you’re right, the usage of property initializers won’t be noticed in our applications unless we instantiate many components. Yes we can see this as a premature optimization and you’re right premature optimizations are the root of all evil — with E Corp — but instead, can we see arrow functions in class properties as premature feature or misused feature? Hopefully, engines will optimizes the arrow functions in class properties.</p><p><em>P.S: Class properties for </em><strong><em>properties</em></strong><em> are such a great improvement!</em></p><p>I’ve seen this in many application and libraries, even ones that contain components we can instantiate multiple times. Should we really use this ESnext feature for class methods in our packages knowing that can impact — for the moment — our performance?</p><p>Personally, I don’t think that arrow functions in class properties are convenient enough — in some cases — at the expense of the performance.</p><p>Our savior will be the <a href="https://github.com/andreypopp/autobind-decorator">autobind-decorator</a>, unfortunately it’s only available with babel as it’s still a proposal at stage 2.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f182e9ee352298b7ecc57c52b25e98c1/href">https://medium.com/media/f182e9ee352298b7ecc57c52b25e98c1/href</a></iframe><p>Even this, they also recommend to avoid autobind on all methods or class:</p><blockquote>It is unnecessary to do that to every function. This is just as bad as autobinding (on a class). You only need to bind functions that you pass around. e.g. onClick={this.doSomething}. Or fetch.then(this.hanldeDone) — Dan Abramov‏</blockquote><blockquote>I was the guy who came up with autobinding in older Reacts and I’m glad to see it gone. It might save you a few keystrokes but it allocates functions that’ll never be called in 90% of cases and has noticeable performance degradation. Getting rid of autobinding is a good thing — Peter Hunt</blockquote><h3>Conclusion</h3><blockquote>The initialization of arrow functions in class properties are transpiled into the constructor.</blockquote><blockquote>Arrow functions in class properties won’t be in the prototype and we can’t call them with super<em>.</em></blockquote><blockquote>Arrow functions in class properties are much slower than bound functions, and both are much slower than usual function.</blockquote><blockquote>You should only bind with .bind() or arrow function a method if you’re going to pass it around.</blockquote><p>Knowing how arrow functions in class properties are handled under the hood and with these benchmarks, you should be able to make an informed choice and aware of the possible consequences.</p><p>What do you think? Will you still use it? How will this affect you?</p><p>Feel free to share your thoughts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b3551c440b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Things You Should Know About ES8]]></title>
            <link>https://medium.com/hackernoon/5-things-you-should-know-about-es8-e4ccd955d883?source=rss-932a4e7a9846------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4ccd955d883</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicolas Charpentier]]></dc:creator>
            <pubDate>Fri, 14 Jul 2017 11:26:41 GMT</pubDate>
            <atom:updated>2019-04-15T13:57:03.964Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bjtPC1A8WKcoLqd7S93icw.jpeg" /></figure><p>ECMAScript 2017 8th edition (ES2017/ES8) has been officially released and published a few weeks ago, let’s figure it out some important changes. All of these are available with Node 8 and with the latest version of browsers without babel or any polyfills.</p><p><a href="https://www.ecma-international.org/publications/standards/Ecma-262.htm">Here’s the specification in detail</a>.</p><h3>Object.values</h3><blockquote>Like Object.keys, but for values.</blockquote><p>Such as <strong>Object.keys</strong> do, the <strong>Object.values</strong> method returns an array of a given object’s own enumerable property values instead of keys.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32d700f2c8471f4009ce1c56e9c5c43e/href">https://medium.com/media/32d700f2c8471f4009ce1c56e9c5c43e/href</a></iframe><h3>Object.entries</h3><blockquote>If we merged Object.keys and Object.values, that would be Object.entries. It returns an array of [key, value].</blockquote><p>The <strong>Object.entries()</strong> method returns an array of a given object&#39;s own enumerable property [key, value] pairs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/787a8030b4989c079e0739d0b39ab524/href">https://medium.com/media/787a8030b4989c079e0739d0b39ab524/href</a></iframe><h3>padStart</h3><blockquote>Pad a string from the start until the given length is reached.</blockquote><p>The <strong>padStart()</strong> method pads the current string with another string (repeated, if needed) so that the resulting string reaches the given length. The padding is applied from the start (left) of the current string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30c92e7922ef7957367823d918fade88/href">https://medium.com/media/30c92e7922ef7957367823d918fade88/href</a></iframe><h3>padEnd</h3><blockquote>Pad a string from the end until the given length is reached.</blockquote><p>The <strong>padEnd()</strong> method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3185f71117cfd8fd022fd97c124dca25/href">https://medium.com/media/3185f71117cfd8fd022fd97c124dca25/href</a></iframe><h3>padThai</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*sSMUVdlp3Ig750xwA5l3Bg.jpeg" /><figcaption>Just a delicious pad thai</figcaption></figure><h3>Trailing commas in function parameter lists</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6880d417af1a2391352bbf7e13657387/href">https://medium.com/media/6880d417af1a2391352bbf7e13657387/href</a></iframe><p>Enjoy ES2017!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4ccd955d883" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/5-things-you-should-know-about-es8-e4ccd955d883">5 Things You Should Know About ES8</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Integration with Angular CLI]]></title>
            <link>https://medium.com/hackernoon/continuous-integration-with-angular-cli-ea6a40fa7d3c?source=rss-932a4e7a9846------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea6a40fa7d3c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Nicolas Charpentier]]></dc:creator>
            <pubDate>Thu, 13 Jul 2017 13:05:55 GMT</pubDate>
            <atom:updated>2017-07-14T02:35:21.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4Lwja6_uG3BBfAe6rdO_g.jpeg" /></figure><p>Angular CLI is a powerful tool to scaffold and build Angular apps. Not only it provides you scalable project structure, instead, it handles all common tedious tasks for you out of the box and it already follows the Angular best practices.</p><blockquote>Build and test your application in a minute</blockquote><p>As tasks, we’ve common commands like:</p><ul><li>ng new to initialize a new Angular project with a lot of settings.</li><li>ng generate to generate something from a blueprint.</li><li>ng serve to build the application and starts a web server.</li><li>ng build to compile the application into an output directory.</li><li>ng test to run your unit tests with Karma the provided test runner.</li><li>ng lint to lint you app code using tslint to ensure best practices of Angular.</li></ul><p>With these commands, you can easily create a new Angular app, generate some components following blueprints and build it in few minutes. Even that, you can ensure everything is still functional with the test runner and if you still respect the style and best practices from Angular with the linter. And this, without any configuration necessary, everything is already ready so you can run test without any further configuration. However, these tools are only effective if you run the command, otherwise, it’s a wasted potential.</p><h3>Continuous Integration</h3><p>To use it at its full potential, we can automatically execute these commands into a continuous integration tool such as <em>CircleCI</em>, <em>Travis</em>, <em>AppVeyor</em>, <em>Jenkins</em>, <em>Bamboo,</em> and a lot more, hooked with your source control on each commit, pull request and even prevent merge if these commands fail. In that way, this will prevent someone from merging if his code doesn’t match with your or Angular style and breaking your project with unbuildable code. You’ve probably already heard “<em>but it’s working on my computer</em>“ that’s exactly what we want to prevent here.</p><p>All you have to do is to setup the environment and executes these previous pre-chewed commands.</p><p>First, let’s build our angular application in production and AoT to be sure everything is alright, then test it and finally lint it. It can be executed on multiple tools, but let’s do examples for a few, at least my favorites.</p><p>We will use <em>Yarn</em> as a fast and secure package manager to cache our dependencies between builds, for more information refer to this article:</p><p><a href="https://medium.com/front-end-hacking/reliable-continuous-integration-in-javascript-463521c4c55c">Reliable Continuous Integration in JavaScript</a></p><h4>CircleCI 2.0</h4><p>Version 2.0 has been rolled out few days ago, enjoy this updated config.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f24eaa264d95b7bd81e7f19672d87002/href">https://medium.com/media/f24eaa264d95b7bd81e7f19672d87002/href</a></iframe><h4>AppVeyor</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22a5e6ec910df4aa7e9203458e6213ee/href">https://medium.com/media/22a5e6ec910df4aa7e9203458e6213ee/href</a></iframe><p>For more information, feel free to checkout the repository that was used to experiment this :</p><p><a href="https://github.com/charpeni/angular-cli-circleci">charpeni/angular-cli-circleci</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea6a40fa7d3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/continuous-integration-with-angular-cli-ea6a40fa7d3c">Continuous Integration with Angular CLI</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reliable Continuous Integration in JavaScript]]></title>
            <link>https://medium.com/front-end-weekly/reliable-continuous-integration-in-javascript-463521c4c55c?source=rss-932a4e7a9846------2</link>
            <guid isPermaLink="false">https://medium.com/p/463521c4c55c</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nicolas Charpentier]]></dc:creator>
            <pubDate>Thu, 19 Jan 2017 02:33:44 GMT</pubDate>
            <atom:updated>2017-01-20T21:40:11.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/636/0*n3-8-RJi9xMHVU2r.png" /></figure><p>When you build a piece of software you want to build a reliable one, so often you’re using various continuous integration tools, such as <em>CircleCI</em>, <em>Travis</em>, <em>Shippable</em>, <em>Codeship</em>, <em>AppVeyor, Semaphore, Jenkins</em>, and<em> Bamboo</em>.</p><h4>But, is your continuous integration process is as reliable as you think?</h4><p>I’ve seen a lot of people on their continuous integration cache or reuse the same <em>node_modules</em> between builds. What they want is a fast pipeline, but more often than not this is done to the cost of a trustworthy CI.</p><p>— Have you ever heard this when your application act strangely ?</p><blockquote>You should delete your node_modules folder and redo a npm install.</blockquote><p>— Because I do, and way too often.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*VZY--qbfO9d-DE6e.gif" /></figure><blockquote>The node_modules folder is not as reliable it could be</blockquote><p>You may want to clean it up sometimes, because it seems to get clogged with time, especially on a testing environment.</p><h4>What is the expected lifetime of the node_modules folder ?</h4><p>Lifetime of the node_modules should be for the current build, unless you often run some sanity checks.</p><h4>Extraneous Packages</h4><blockquote>npm prune</blockquote><p>If you don’t know this command, you should probably read this and run it into your development folders.</p><blockquote>This command removes “extraneous” packages.</blockquote><blockquote>Extraneous packages are packages that are not listed on the parent package’s dependencies list.</blockquote><p>So, let’s say for example that in an application I add a dependency named <em>potato</em>, I commit and I push. CI will run and install <em>potato</em> into <em>node_modules</em> folder. Now, let’s say I remove that dependency from <em>package.json</em>. Since it’s already installed on my machine and the CI container, it will work fine.</p><p>If I clone the repository again or another developer tries my repository, it will not work as expected. However, it works on my machine and the CI is green. So we need to put the whole project on hold until we can resolve the issue. Finding and resolving the issue can be both time consuming and frustrating especially if there’s only two devs involved.</p><p>— You’ve probably heard this before :</p><blockquote>Yeah but it works on my computer</blockquote><p>— We certainly do not want to hear that</p><p>The role of the CI should be to validate that an application works well from a fresh installation.</p><p>That’s why <strong>you should always clean <em>node_modules</em> and do a <em>npm install </em>or at least run the prune command</strong>.</p><p>If an install worked on one system, it should work exactly the same way on any other system</p><h4>Git Dependencies</h4><p>If you use a dependency that isn’t published to NPM like a git URL, your dependency won’t be updated by<em> npm install </em>if the version wasn’t updated, even if you commit to master or your specified branch/tag/commit.</p><p>That’s why clean install should be privileged, you certainly don’t want to test your application with an older dependency version.</p><h3>Yarn to the Rescue</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*iIMhJxRoN4IlHp1WbMP98Q.png" /></figure><blockquote>If you want an ultra fast, mega secure, and super reliable solution, <a href="https://yarnpkg.com/">Yarn</a> will be yours</blockquote><h4>Fast</h4><blockquote>Yarn caches every package it downloads so it never needs to download the same package again. It also parallelizes operations to maximize resource utilization so install times are faster than ever.</blockquote><h4>Reliable</h4><blockquote>Using a detailed, concise lockfile format and a deterministic algorithm for installs, Yarn is able to guarantee that an install that worked on one system will work exactly the same way on any other system.</blockquote><h4>Secure</h4><blockquote>Yarn uses checksums to verify the integrity of every installed package before its code is executed.</blockquote><p>Moreover, Yarn doesn’t require additional steps to prune extraneous packages, <em>yarn install</em> will do it automatically on each installation.</p><p>Also, Yarn resolves git tarball like a charm.</p><h3>Conclusion</h3><p>So basically, just install Yarn and replace <em>npm install</em> by <em>yarn install </em>to considerably increase the trust level of your CI.</p><p>If you want to reach the top trust level, be sure you run <em>yarn install</em> on a clean environment. The cache provided by Yarn will do the job for you, don’t forget to keep the yarn cache and not the<em> node_modules </em>folder across builds. <a href="https://yarnpkg.com/en/docs/install-ci">See here how to do it.</a></p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=463521c4c55c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/reliable-continuous-integration-in-javascript-463521c4c55c">Reliable Continuous Integration in JavaScript</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>