<?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 Ashley Romain Bonhomme on Medium]]></title>
        <description><![CDATA[Stories by Ashley Romain Bonhomme on Medium]]></description>
        <link>https://medium.com/@ashleymoogle?source=rss-41971cfff52b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*n_zvphFSJpe8bZjB.</url>
            <title>Stories by Ashley Romain Bonhomme on Medium</title>
            <link>https://medium.com/@ashleymoogle?source=rss-41971cfff52b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 08:12:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashleymoogle/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[Using latest technologies and your team : how to increase productivity for everyone]]></title>
            <link>https://medium.com/@ashleymoogle/using-latest-technologies-and-your-team-how-to-increase-productivity-for-everyone-46022cedf192?source=rss-41971cfff52b------2</link>
            <guid isPermaLink="false">https://medium.com/p/46022cedf192</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Ashley Romain Bonhomme]]></dc:creator>
            <pubDate>Tue, 23 May 2017 08:10:54 GMT</pubDate>
            <atom:updated>2017-05-23T08:10:54.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*LPtZMXEuTBpt8Fr5dcH11w.gif" /></figure><p>As a front-end web developer, I’m always watching for new technologies and the latest stuff. New is sexy, especially when it makes the product you’re working on more optimised, cleaner and/or simpler to use even if sometimes the price of this sweetness comes with increased complexity in the project.</p><p>Every Javascript developer knows this : in this line of work, you either swim or you die. Take AngularJs for example : not so long ago it was The Thing. Now with Angular2 ready for production, and the propension of Google to let their old stuff go when the new stuff is live, it raise one question : will you upgrade or take the risk to discover a major security leak in a few years, when google had stopped patching AngularJs ?</p><p>The point is : trying to experiment with the latest thing, following the hype is, I think, good, advisable even.</p><p>But it can lead to one problem.</p><h3>Everyone has it’s own skillset</h3><p>Not everyone on your team might know Javascript, that’s okay, it’s your job as a front-end dev, but sometimes some of your stuff can be a burden for your team if nobody knows how to use it.</p><p>Most developers are not necessarily versed in the arcanes of Npm or even Webpack but they need to make it work in order to use the project or for deployment. They need to use commands and they need to understand what it does.</p><p>From here you have 2 choices : <br>First, you can teach everyone how to use, say, Webpack. You need to explain each command and what it does. However it can become very irritating since you need to explain everything again each time you add a Webpack pipe if you have a complex app with builds for production, dev, tests…</p><h3>Making life easier for everyone</h3><p>Or you can make magic commands that do everything. It can be a controversial choice but that’s the one I made to avoid wasting everyone’s time and allow my team to be more productive, faster. That plus a huge documentation about everything if the worst happened (If I’m abducted by aliens for example).</p><p>So what did I do ? Well, I used 2 things : npm scripts and make.</p><p>Npm scripts are handy scripts that allows dependencies with CLIs to be executed locally from your node_modules instead of having to install everything globally and they can chain commands (ie : install stuff, build…).</p><p>To make npm scripts it’s easy, take your package.json</p><pre>&quot;name&quot;: &quot;Yourproject&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;version&quot;: &quot;0.0.0&quot;,<br>  &quot;engines&quot;: {<br>    &quot;node&quot;: &quot;7.0.0&quot;,<br>    &quot;npm&quot;: &quot;2.10.1&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;super-install&quot;: &quot;npm install &amp;&amp; webpack --progress&quot;,<br>    &quot;build&quot;: &quot;webpack --progress&quot;,<br>    &quot;build:dev&quot;: &quot;webpack --progress&quot;,<br>    &quot;start&quot;: &quot;webpack --progress --watch&quot;<br>  },<br>  &quot;private&quot;: true,<br>  &quot;dependencies&quot;: {<br>    &quot;mobx&quot;: &quot;^3.1.9&quot;,<br>    &quot;mobx-react&quot;: &quot;^4.1.7&quot;,<br>    &quot;react&quot;: &quot;^15.3.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;webpack&quot;: &quot;^2.3.3&quot;<br>  }<br>}</pre><p>Add your stuff in the script prop and you’re done. To use your npm script just type npm run yourScript</p><pre>npm run build</pre><p>That’s it, easy.</p><p>But that wasn’t enough for me.</p><h3><strong>One command to bring them all and in the darkness bind them</strong></h3><p>See, with npm scripts you can’t really use unix commands like “rm -rf node_modules” if you want to clean every dependencies before each install for example. Plus, again, some people really don’t like or get npm (hello non-js back developers :D).</p><p>To avoid this problem, I used make. Make allows you to use bash to do everything, even launch npm scripts. You just have to create a Makefile (no extension) and then write your scripts. This is an excerpt of my Makefile :</p><pre>define npm_script_targets<br>TARGETS := $(shell node -e &#39;for (var k in require(&quot;./package.json&quot;).scripts) {console.log(k.replace(/:/g, &quot;-&quot;));}&#39;)<br>$$(TARGETS):<br>   yarn $(subst -,:,$(MAKECMDGOALS))<br><br>.PHONY: $$(TARGETS)<br>endef<br><br>$(eval $(call npm_script_targets))<br><br>update:<br>   @echo &quot;\xF0\x9F\x90\xB8  Welcome to the update command, it will update the projet and rebuild&quot;<br>   @sleep 4s<br>   @echo &quot;\xF0\x9F\x9A\xBD  Cleaning dependencies&quot;<br>   rm -rf node_modules<br>   @sleep 2s<br>   @echo &quot;\xF0\x9F\x90\xB1  Updating dependencies&quot;<br>   make npm install<br>   @echo &quot;\xE2\x9A\xA1  Compil webpack&quot;<br>   make build-dev<br>   @echo &quot;SUCCESS&quot;</pre><p>The first part parses the npm scripts in my package.json and changes the ‘:’ into ‘-’ because ‘:’ is used to declare scripts in make. Then you have the update command that displays stuff (with emojis, I’m not a monster), clean dependencies, install everything and builds.</p><p>So the only thing left to do when pulling the project is to type :</p><pre>make update</pre><p>Voilà!</p><p>Every time I change some stuff in how we build or initiate the app I just update my make scripts if needed so it’s completely transparent for everyone in the team, they just need to use the same old magic command.</p><h3>Happily ever after</h3><p>Now, I hope, everyone is happy, I know I am. I can happily wreak my webpack config, test packages or try new build configurations without hindering everyone in their everyday work each time they pull the project or work on the same branch as me, nice!</p><p>Ultimately, I’ld say it’s mostly about you and your team’s flow but I think it should be everyone responsibility to make his work easy to use and understandable by everyone. In the best universe, with the magic commands, you always have your teammate’s documentations for reference and they always have yours, right ? :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46022cedf192" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Worker : cache your resources and other good stuff]]></title>
            <link>https://medium.com/zenchef-tech-and-product/service-worker-cache-your-resources-and-other-good-stuff-7642b089fff5?source=rss-41971cfff52b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7642b089fff5</guid>
            <category><![CDATA[workers]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ashley Romain Bonhomme]]></dc:creator>
            <pubDate>Thu, 19 Jan 2017 08:11:35 GMT</pubDate>
            <atom:updated>2017-01-19T09:25:45.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*TqaGoWSHFcrkfO2Vx3he4w.gif" /></figure><p>Pretty recently I took interest in how I could better optimize my webapps. I’m not talking about the code per se, but about what’s around your webapps lifecycle : building, rendering, resources, that kind of stuff.</p><p>I started to use Webpack a few months back and fell in love with it. Thanks to it I can serve css and javascript bundles and even css modules or javascript modules ! That increased drastically the loading time of our product at Zenchef (where the codebase is starting to get pretty heavy).<br>So, yeah that’s good and all but how could we go further ?</p><p>I started to hear about Service Workers and their multiple uses for some time now so one day i was like ‘What the hell’ and tried an implementation on a little project.</p><h3>Service Workers ? What the… ?</h3><p>First let’s start talking about Service Workers specifically. They allow you to :</p><ul><li>Cache resources (like your webpack bundles or your frameworks from cdn)…</li><li>…Which can lead to faster loading time AND offline navigation !</li><li>Push notifications</li><li>Have background sync</li><li>…</li></ul><p>It’s starting to look a lot like mobile app doesn’t it ?</p><p>For my implementation i used :</p><ul><li>A React app bundled with webpack</li><li>css bundled with webpack</li><li>index.html to mount react and includes scripts</li><li>A javascript file named initServiceWorker.js</li><li>A service worker named sw.js</li></ul><h3>Boldly go to the code !</h3><p>First let’s start with initServiceWorker.js</p><pre>if (&#39;serviceWorker&#39; in navigator) {<br>    navigator.serviceWorker.register(&#39;/sw.js&#39;).then((<em>reg</em>) =&gt; {<br>        console.log(&#39;Yay, service worker is live!&#39;, <em>reg</em>);<br>    }).catch((<em>err</em>) =&gt; {<br>        console.log(&#39;No oats for you.&#39;, <em>err</em>);<br>    });<br>}</pre><p>Straightforward enough, if your navigator supports Service Workers, you try to register to one. <em>Note that it uses Promises.</em></p><p>Then we have the Service Worker itself. There is multiple steps to make it work but basically it listens to events and act accordingly.</p><p>First we have the ‘install’ event. That event is used once and serves as an init. We will tell it to cache our resources</p><pre>const <em>version </em>= &quot;v1::&quot; //Change if you want to regenerate cache<br>const <em>staticCacheName </em>= `${<em>version</em>}static-resources`;<br><br>const <em>offlineStuff </em>= [<br>    &#39;/dist/app.bundle.css&#39;,<br>    &#39;/dist/app.bundle.js&#39;,<br>    &#39;/assets/workers/initServiceWorker.js&#39;<br>]<br><br>self.addEventListener(&#39;install&#39;, (<em>event</em>) =&gt; {<br>    console.log(&#39;in install&#39;)<br>    <em>event</em>.waitUntil(<br>        caches<br>            .open(<em>staticCacheName</em>)<br>            .then((<em>cache</em>) =&gt; {<br>          <em>cache</em>.add(&#39;//cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js&#39;)<br>                return <em>cache</em>.addAll(<em>offlineStuff</em>);<br>            })<br>            .then(() =&gt; {<br>                console.log(&#39;WORKER:: install completed&#39;);<br>            })<br>    )<br>});</pre><p>Okay so let’s break it down.<br>First you create variables for the version, the cache name and the path of the items you want to cache.<br>Then you use self.addEventListener(event) to catch an install event. This event uses funny methods like .waitUntil, that do exactly as his name says, and caches.</p><p><strong>caches</strong> is the keyword to all cache methods. Since it’s the installation you will want to open a new cache with your version name and add some items to it. Note that you can add url like i did with the React CDN.</p><p>Mind that you need to refresh your page after the registration for the install and activation to take effect.</p><h3>Worker : ACTIVATED</h3><p>Now that we have our ressources installed in cache let’s talk about the activate event. This event is fired each time the Service Worker is registered.</p><pre>self.addEventListener(&#39;activate&#39;, function (<em>event</em>) {<br>    <em>event</em>.waitUntil(<br>        caches<br>            .keys()<br>            .then((<em>keys</em>) =&gt; {<br>                return Promise.all(<br>                    <em>keys<br>                        </em>.filter((<em>key</em>) =&gt; {<br>                            //If your cache name don&#39;t start with the current version...<br>                            return !<em>key</em>.startsWith(<em>version</em>);<br>                        })<br>                        .map((<em>key</em>) =&gt; {<br>                            //...YOU WILL BE DELETED<br>                            return caches.delete(<em>key</em>);<br>                        })<br>                );<br>            })<br>            .then(() =&gt; {<br>                console.log(&#39;WORKER:: activation completed. This is not even my final form&#39;);<br>            })<br>    )<br>});</pre><p>When the worker is activated, it checks the current cache and flush outdated resources thanks to our version variable.<br>And… That’s it. Now to the better part : fetching</p><h3>Go fetch !</h3><p>The fetching event intercepts everything you’re trying to include in your app. What we are trying to do here is to : serve the content from the server / cdn / whatever OR serve it from cache if it is available in it.</p><pre>self.addEventListener(&#39;fetch&#39;, function(<em>event</em>) {<br>    <em>event</em>.respondWith(<br>        // Try the cache<br>        caches.match(<em>event</em>.request).then(function(<em>response</em>) {<br>            return <em>response </em>|| fetch(<em>event</em>.request);<br>        }).catch(function() {<br>            //Error stuff<br>        })<br>    );<br>});</pre><p>And with just that you have cached all the things and made your website load faster.<br>But the real magic is when you switch your wi-fi off and notice that your React app still works since React.js is served from cache instead of cdn.</p><h3>Conclusion</h3><p>Beyond the fact that you can reduce some loading times, the most interesting point is the offline capabilities granted by the Service Workers.<br>Of course it will add another layer of complexity to your front if you want to have a real Offline-Capable app but it’s worth it !<br>Some time in the future I might try a better implementation with added background-sync and push-notifs but for now that will be all.</p><p>You can find the code and other good stuff in <a href="https://github.com/ashleymoogle/starter-kit-js">my starter-kit-js on Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7642b089fff5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenchef-tech-and-product/service-worker-cache-your-resources-and-other-good-stuff-7642b089fff5">Service Worker : cache your resources and other good stuff</a> was originally published in <a href="https://medium.com/zenchef-tech-and-product">Zenchef’s Tech and Product Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write nice angular components in ES2015]]></title>
            <link>https://medium.com/zenchef-tech-and-product/how-to-write-nice-angular-components-in-es2015-e150d77d2a18?source=rss-41971cfff52b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e150d77d2a18</guid>
            <category><![CDATA[components]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[directives]]></category>
            <category><![CDATA[zenchef]]></category>
            <dc:creator><![CDATA[Ashley Romain Bonhomme]]></dc:creator>
            <pubDate>Tue, 27 Dec 2016 17:20:59 GMT</pubDate>
            <atom:updated>2016-12-28T09:11:52.281Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*1LufzuvnUabrvKL9yp6LMQ.gif" /><figcaption>Angular</figcaption></figure><p>Here at Zenchef, our app is mainly in Angular 1.x, with some features in React (thanks ngReact).<br>Getting back to Angular after a project on React is not easy, especially if you have an old codebase in ES5. Did you know that with a little work you can get some of that React component sweetness with Angular’s own component system ?</p><blockquote>Well, if not, let’s discover how !</blockquote><h3>Why Angular components ?</h3><p>Why not using directives ? Well first, directives are really a pain to write while components are way easy to work with on that point. Moreover, native imports are easier to use with components, especially if you want to work with imported ES2015 classes.</p><pre>class Directive {<br><br>    constructor(<em>$rootScope</em>, myFactory) {<br>        this.rootScope = <em>$rootScope<br>        </em>this.service = myFactory<em><br>    </em>}<br><br>    link(<em>scope</em>, <em>element</em>, <em>attrs</em>) {<br>        this.foo = &quot;&quot;<br>        let <em>method </em>= () =&gt; {<br>           this.service.get().then((data) =&gt; {<br>              this.foo = data         <br>           })<br>        };<br>    }<br><br>    static directiveFactory(<em>$rootScope</em>, myFactory){<br>        Directive.instance = new Directive(<em>$rootScope</em>, myFactory)<br>        return Directive.instance<br>    }<br>}<br><br>Directive.directiveFactory.$inject = [&#39;$rootScope&#39;, &#39;myFactory&#39;];<br>export { Directive }</pre><p>Then you register an instance of your directive to your angular module (you can also do a new instance with new () )</p><pre>import MyFactory from &#39;./MyFactory&#39;<br>import {Directive} from &#39;./Directive</pre><pre>angular.module(&#39;app&#39;, [])<br>       .factory(&#39;myFactory&#39;, MyFactory)    <br>       .directive(&#39;myDirective&#39;, Directive.directiveFactory)</pre><p>VS components</p><pre>import ctrl from &#39;./MyCtrl&#39;<br>import temp from &#39;./MyTemplate.html&#39;<br><br>export default {<br>    bindings: {<br>        &#39;user&#39;:&#39;=&#39;,<br>        &#39;source&#39;:&#39;=&#39;<br>    },<br>    template: temp,<br>    controller: ctrl,<br>    controllerAs: &#39;vm&#39;<br>}</pre><p>Registering is easy, no instance needed</p><pre>import MyComponent from &#39;./MyComponent&#39;</pre><pre>angular.module(&#39;app&#39;, [])<br>       .factory(&#39;myFactory&#39;, MyFactory)<br>       .component(&#39;myComponent&#39;, MyComponent)</pre><p>Note that with directive, you still have the link property (and all the other if you want), even with a ES2015 class while with component you simply bind a controller or, in that case, a simple class.<br>One other good thing with components is that they use the controllerAs syntax by default ($ctrl by default, but you can change the prefix by adding a controllerAs prop to the component, as seen above.) and the bindToController is set by default.</p><h3>Architecture</h3><p>Now that we’ve seen how simple Angular components are, let’s talk about the mean of it : the template and controller. As you can see above, two files were imported :</p><pre>import ctrl from &#39;./MyCtrl&#39;<br>import temp from &#39;./MyTemplate.html&#39;</pre><blockquote>What’s inside them ?</blockquote><h4>MyTemplate.html</h4><pre>&lt;div&gt;<br>     &lt;h3&gt;{{vm.title}}&lt;/h3&gt;    <br>     &lt;a&gt;{{vm.user.name}} from {{vm.source.name}}&lt;/a&gt;<br>&lt;/div&gt;</pre><h4>MyCtrl.js</h4><pre>export default class MyCtrl {<br>    constructor($timeout, myFactory) {<br>        this.timeout = <em>$timeout<br>        </em>this.service = myFactory<em><br>    </em>}<br><br>    $onInit() {    <br>        this.title = &quot;A title&quot;<br>        this.getBindings()<br>    }<br><br>    <em>getBindings </em>= () =&gt; {<br>        console.log(this.<em>user</em>)<br>        console.log(&#39;---&#39;)<br>        console.log(this.<em>source</em>)<br>    }<br>}<br><br>MyCtrl.$inject = [&#39;$timeout&#39;, &#39;myFactory]</pre><p>Well, that’s not totally finished but we’ll work with it.<br>Note the $onInit() method, with angular 1.6+ you must use it to do your initial bindings.</p><p>Now, we have our three files : MyTemplate.html, MyCtrl.js and MyComponent.js.<br>MyComponent imports the other two but how do you import MyComponent.js ? You could do it directly where you initialize your Angular module but a nice way to import your components could be to treat all of them as a collection and pick the ones you want. Exactly like you would do with React-router for exemple.</p><p>Create a /components folder, create a /MyComponent folder inside and put all three files inside.<br>Now at the root of /components you can create a index.js file like so :</p><pre>import _MyComponent from &#39;./MyComponent/MyComponent&#39;<br>export { _MyComponent as MyComponent}<br><br>import _MyComponent2 from &#39;./MyComponent2/MyComponent2&#39;<br>export { _MyComponent2 as MyComponent2}<br><br>import _MyComponent3 from &#39;./MyComponent3/MyComponent3&#39;<br>export { _MyComponent3 as MyComponent3}<br><br>import _MyComponent4 from &#39;./MyComponent4/MyComponent4&#39;<br>export { _MyComponent4 as MyComponent4}</pre><p>And the registration :</p><pre>import {MyComponent} from &#39;./components&#39;<br>import {MyComponent2} from &#39;./components&#39;</pre><pre>angular.module(&#39;app&#39;, [])<br>       .factory(&#39;myFactory&#39;, MyFactory)<br>       .component(&#39;myComponent&#39;, MyComponent)<br>       .component(&#39;myComponent2&#39;, MyComponent2)</pre><p>Thats extremely useful, especially if you have modules to lazyload (and you should!) and multiple module initialization through your app</p><h3>So…</h3><p>I love React and I love components ! I think with this method using ES2015 features like classes and import you can really work with something a little similar in Angular. I started to love Angular again since I began to use ES2015 and some best practices (like less $scope, the better) and I really hope this little article will help you love it (again) too.</p><p>Have fun coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e150d77d2a18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenchef-tech-and-product/how-to-write-nice-angular-components-in-es2015-e150d77d2a18">How to write nice angular components in ES2015</a> was originally published in <a href="https://medium.com/zenchef-tech-and-product">Zenchef’s Tech and Product Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>