<?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 priley86 on Medium]]></title>
        <description><![CDATA[Stories by priley86 on Medium]]></description>
        <link>https://medium.com/@priley86?source=rss-33f392ff6f07------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dBu9jr4tBPsa6VBJ0XgFdg.jpeg</url>
            <title>Stories by priley86 on Medium</title>
            <link>https://medium.com/@priley86?source=rss-33f392ff6f07------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 23:24:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@priley86/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[Building cross-framework components with performance in mind, a web component thesis]]></title>
            <link>https://medium.com/@priley86/building-cross-framework-components-with-performance-in-mind-a-web-component-thesis-5e17353aee18?source=rss-33f392ff6f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e17353aee18</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-components]]></category>
            <dc:creator><![CDATA[priley86]]></dc:creator>
            <pubDate>Sun, 09 Oct 2016 15:46:19 GMT</pubDate>
            <atom:updated>2016-10-09T16:23:59.456Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently gave a <a href="https://t.co/lHXcfonrCP">presentation</a> at Triangle JS about web components and web component interoperability amongst common UI frameworks. I’d like to build on this talk and present some new ideas around web component rendering options and their performance. I’ll also follow up with some sample implementations that address more complex rendering challenges such as transcluded content rendering and rendering common web components across different frameworks.</p><h4>Benchmarking a variety of JS rendering implementations</h4><p>A recent <a href="https://auth0.com/blog/face-off-virtual-dom-vs-incremental-dom-vs-glimmer/">post</a> at auth0 surveyed the landscape of commonly used JS frameworks and provided some insight into their individual performance. It was subsequently <a href="https://auth0.com/blog/updated-and-improved-more-benchmarks-virtual-dom-vs-angular-12-vs-mithril-js-vs-the-rest/">updated</a> to include some metrics for DOM rendering libraries <a href="https://github.com/google/incremental-dom">incremental-dom.js</a> and <a href="https://github.com/Matt-Esch/virtual-dom">virtual-dom.js</a>. I took some time to <a href="https://github.com/priley86/blog-dombench/tree/dombench2">reproduce</a> these tests and verify the results claimed by the author. I also added some metrics for the case that a custom element was used in the rendering template alongside the virtual-dom library. It should be noted that the goal of this suite is to “stress” test the browser’s rending with each library and provide an average benchmark after running five tests with each implementation. The author also did due diligence by adding performance improvements for rendering long lists as suggested by each library (ex: Angular’s <a href="http://www.codelord.net/2014/04/15/improving-ng-repeat-performance-with-track-by/">track-by</a> expression).</p><h4>Memory consumed</h4><p>The following charts total memory consumed by each framework. This chart agrees with the author’s claim that incremental DOM consumes far less memory than other frameworks (making it a great choice for mobile implementations where memory is constrained).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxSOzrP_CXXHh8fZwj3Uhw.png" /></figure><p>We can also see the number of major/minor garbage collections in Chrome caused by each framework. Garbage collections are caused when frameworks create and destroy lots of new javascript references. These affect other metrics and cause the browser to waste more cycles “cleaning up”. As expected, we see incremental DOM shine again due to it’s optimized for memory algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RReVOk--dqQo9cKemmLgMA.png" /></figure><h4>Frames Per Second</h4><p>Maintaining a high FPS is an important metric in describing a framework’s performance during high rendering scenarios. This metric seems to indicate that most frameworks hover around 50 FPS when stressed to their maximum. If not careful, rendering with Angular1 can be downright abysmal due to its long digest loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jzJfTTeHmgLfrPTBbvGQqw.png" /></figure><h4>Dropped Frames</h4><p>This metric tracks the number of frames “skipped” by the browser due to overall performance. Again we see Angular1 struggles when not used properly. Also there is a bit of an impact rendering custom elements instead of other native elements. One can assume this is due to custom element initialization time spent by the browser constructing its definition. Some more commentary on this can be found <a href="https://groups.google.com/forum/#!topic/polymer-dev/fAGzYNvxnPQ">here</a>. I would expect this to improve as browsers add further support and iterate on the new custom element spec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*335EJhmFJ7yqPD1NPwj3Pw.png" /></figure><h4>Nodes Per Layout</h4><p>Another important metric is number of nodes rendered per layout. This indicates rendering algorithm optimizations which attempt to minimize the number of DOM nodes changed during each rendering cycle. Surprisingly, incremental DOM and virtual DOM score virtually the same followed by the other frameworks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJdwq-VCgHpnZfScvPFLbQ.png" /></figure><h4>Total Javascript Runtime</h4><p>This metric tracks total time spent on Javascript execution. Again incremental DOM shines here; followed closely by cito js and virtual DOM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MScd8kNQA3UqPrBYKNwzaQ.png" /></figure><h4>Performance Conclusions and a note about Layout/Paint</h4><p>I specifically left out Layout/Paint metrics due to an issue described <a href="https://github.com/auth0-blog/blog-dombench/issues/7">here</a>. I was unable to reproduce the author’s results for this metric, and it appeared that higher layout/paint times actually bode well for each sample (rather than counter like the author described). The idea here being that more time spent on layout/paint indicates higher throughput (which seemed to correlate with FPS); although I’ll wait for confirmation before making any assumptions.</p><p>My overall conclusions from this benchmark are:</p><ol><li>Each of the frameworks mentioned can perform relatively well when used carefully and when best practices are observed.</li><li>This stress test goes beyond what would be commonly observed in your applications, but it’s good to see how frameworks perform under stress when determining what rendering library you want to use in future implementations.</li><li>I would strongly encourage you to upgrade to new JS frameworks React or Angular2 when feasible. These frameworks will help you avoid the performance “pitfalls” inherent in older implementations like Angular1 or Ember.</li><li>Browser vendors need to continue improving web component performance. Making developer contributed DOM as fast as “native” DOM should be a priority. It appears there is already an ongoing effort to improve this based on the custom element’s v1 spec of element <a href="https://developers.google.com/web/fundamentals/getting-started/primers/customelements#upgrades">upgrades</a>. There is also a performance hit for Shadow DOM “shadowRoot” construction. In the meantime, we should be more careful to conditionally render custom elements only when needed.</li></ol><h4>Some Suggested Rendering Libraries and Strategies for Web Component Rendering</h4><p>Based on these results, I wanted to try and tackle a few common rendering problems such as transclusion (the inclusion of nested content in a component) and template binding via common UI frameworks AngularJS and ReactJS alongside web components. In these tests, I also chose to exclude Shadow DOM due to it’s current lack of <a href="http://jonrimmer.github.io/are-we-componentized-yet/">browser support</a> and <a href="https://www.polymer-project.org/1.0/blog/shadydom#shadow-dom-is-awesome-why-is-there-a-shady-dom">slow polyfill</a>. I’ll include links which may be helpful for those still pushing ahead with Shadow DOM now though.</p><p>Surveying the landscape of libraries which make use of these rendering techniques, I found a few contenders which should prove adequate for providing an optimal rendering path in web components alongside your web application:</p><ol><li><a href="https://github.com/skatejs/skatejs">SkateJS</a>: Skate is web component rendering library which utilizes incremental DOM for rendering web components. It provides helpful extensions for making interoperability less challenging and weighs in at only 4k min+gz. Its core contributor, Trey Shugart, works at Atlassian and sits on the WebComponents.org<a href="http://webcomponents.org/about/"> contributors list</a> amongst Google, Microsoft and others.</li><li><a href="https://github.com/developit/preact">PreactJS</a>: Preact provides a minimal subset of the virtual DOM JS implementation used in ReactJS. It also has helpful extensions for <a href="https://github.com/developit/preact-markup/">rendering HTML strings</a> and <a href="https://github.com/bspaulding/preact-custom-element">defining custom elements</a>. It weighs in at an astoundingly light 3k min+gz. It has been <a href="https://www.sitepoint.com/react-alternatives-preact-virtualdom-deku/">tested</a> alongside <a href="https://github.com/Matt-Esch">Matt Esch</a>’s “heavier” <a href="https://github.com/Matt-Esch/virtual-dom">virtual-dom.js</a> implementation and was very comparable. Considering these libraries implement virtually the same solution, I opted for the lighter alternative.</li></ol><p>These libraries should provide a great platform for building optimal components in your framework implementations. Before I dive into a few examples and weigh pros/cons, I’d also like to note that in <em>most cases </em>you will likely be able to get away with vanilla javascript when building web components (as noted in my Triangle JS <a href="https://t.co/lHXcfonrCP">presentation</a>). This is also clearly observed by peaking into the source of the <a href="https://onsen.io/">Onsen.io</a> project, a highly respected web component framework that is cross-framework compatible and works well on mobile/hybrid apps. It should also be noted that these rendering frameworks will likely be desirable only when rendering a <em>lot</em> of DOM inside a component.</p><h4>Transclusion &amp; Template Binding</h4><p>Transclusion allows us to take DOM rendered inside of a component by a framework and drop it into the component’s internal DOM structure where we’d like. Given that custom elements behave exactly like “real DOM”, this is fairly trivial in most cases. I wrote up an example of this <a href="https://plnkr.co/edit/dDf25hgHIkqqPzvdlJl9?p=preview">here</a> with custom elements and AngularJS reimplementing the Patternfly <a href="http://www.patternfly.org/pattern-library/content-views/list-view/#/api">List View</a>. I also did the same thing with React <a href="https://plnkr.co/edit/Ds77ZqlxJIV87TSXOZuV?p=info">here</a>. What should become immediately clear is that commonly observed patterns with Angular such as “ng-model” bindings and “ng-repeat” loops still work just as well with web components. You can also easily still bind events and provide a means to send messages amongst components.</p><p>Building on this example, I took the dropdown widget (kebab widget) and implemented its core widget structure using Preact. You can see this <a href="http://www.webpackbin.com/N1fwEMX0Z">here</a>. What’s notable about this is I’ve taken the dropdown items rendered in the DOM and transcluded them into the Preact components “render” method (its children). Another approach to this is using custom element attributes (which pass in the list item data instead). You can see this in action <a href="http://www.webpackbin.com/EyztqfXRZ">here</a>. One challenge with this approach is the Preact component lifecycle will likely not match your framework’s, so you’ll have to ensure proper handling of attributes at all times (note the try/catch of attribute json, which handles the case that the data has not yet rendered by Angular). Although with careful handling, this is still completely possible.</p><p>If you’d like to look at a simpler example that shows a few Preact use cases with Shadow DOM, take a look <a href="http://www.webpackbin.com/VJyU9wK5W">here</a> and <a href="http://www.webpackbin.com/NyUsjSQRZ">here</a>. These were written by the author, Jason Miller.</p><p>A similar example I wrote utilizing SkateJS to render an array of attribute data can be found <a href="https://jsfiddle.net/patrickriley/hsoup9pj/12/">here</a>. One thing to note here about Skate is that it’s not exactly spelled out in the docs that you must “re-render” any transcluded content (light DOM) in the “render” method of your component, as Skate will replace it after its rendering cycle. You also need to give it some options to remove the Shadow DOM shadow root which it inherently implements. You can see some commentary on how to do this <a href="https://github.com/skatejs/skatejs/issues/802">here</a>.</p><h4>What about Polymer?</h4><p>If you’re up to date on the web component scene, you’ll likely find it amusing that the Polymer library was not mentioned in this post until now. While its goals are to become a lightweight extendable framework sufficient for building a variety of components, I feel it’s missed the beat here and made too many assumptions for most framework authors to embrace. As spelled out in a recent <a href="https://medium.com/dev-channel/the-case-for-custom-elements-part-1-65d807b4b439#.vd2lgy6wr">post</a> by <a href="https://medium.com/u/d712d6fb229b">Rob Dodson</a>, the gradual adoption of web components is ideal for most and should be tempered with ongoing browser implementations of the web component specifications. While most vendors have agreed and started implementations for the Custom Elements, Templates, and Shadow DOM specs (notably Apple’s Safari), the HTML Imports spec, heavily relied upon by Polymer, has not yet been agreed to by other vendors (i.e. Apple, Mozilla), and should be a cause for concern (who wants to use a polyfill forever?). It’s also evident that ES6 module/code splitting techniques can lead to very <a href="https://medium.com/@addyosmani/progressive-web-apps-with-react-js-part-2-page-load-performance-33b932d97cf2#.fwwrqsrwh">performant</a> solutions as well with HTTP2 and web components as noted by Google’s own <a href="https://medium.com/u/2508e4c7a8ec">Addy Osmani</a>. I’d also like to point out that Polymer’s current rendering performance has been questioned at times and led to quite a few <a href="https://mobile.twitter.com/tomdale/status/769186852079300608">debates</a> on Twitter.</p><p>I’ll close on a positive note about Polymer though and share my support that it definitely provides a revolutionary approach in its implementation of atomic design principles and does so in a very forward looking way. I’ll be watching this topic closely and will be happy to jump onboard once other browser vendors have too.</p><h4>Conclusions</h4><p>In conclusion, web components have come a long way, and some implementation and interoperability strategies are definitely starting to take shape. I’d love to see many of the web’s current jQuery plugins become optimized web components having their own lightweight and performant implementations that are easily shareable and extendable across frameworks. Providing these “leaf” nodes as optimized components with a reduced set of dependencies should make them highly usable in many applications (for example, think how performant a tree view would become with virtual DOM). Web components also do a lot in the way of helping us encapsulate styles and behaviors (but I’ll save animation for a future post).</p><p>‘Til next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e17353aee18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Components with Angular2]]></title>
            <link>https://medium.com/@priley86/web-components-with-angular2-ee935f4c1e30?source=rss-33f392ff6f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee935f4c1e30</guid>
            <dc:creator><![CDATA[priley86]]></dc:creator>
            <pubDate>Tue, 06 Sep 2016 21:37:00 GMT</pubDate>
            <atom:updated>2016-09-06T21:49:22.501Z</atom:updated>
            <content:encoded><![CDATA[<p>With the advent of <a href="http://w3c.github.io/webcomponents/spec/shadow/">Shadow DOM</a>, <a href="http://w3c.github.io/webcomponents/spec/imports/">HTML Imports</a>, <a href="https://html.spec.whatwg.org/multipage/scripting.html#the-template-element">HTML Templates</a>, and <a href="http://w3c.github.io/webcomponents/spec/custom/">Custom Elements</a>, the future of web development is pretty bright. In this post I’d like to talk about a few concepts which may help when writing custom elements, and how you can improve your element interop with other frameworks.</p><h4>Using Custom Events</h4><p>Custom Events give us the ability to communicate from our custom element back to the framework. You can see a great example of this here using Typescript with Ng2 and a custom element:</p><p><a href="https://plnkr.co/edit/1qsyD5?p=preview">Plunker</a></p><pre>// fires when our element is attached to the DOM<br>attachedCallback() {<br>  this.addEventListener(‘click’, (e) =&gt; {<br>    var eventObj = new CustomEvent(‘selected’, {<br>     detail: this.username<br>    });<br> <br>   if(e.target.tagName === ‘BUTTON’) {<br>    // fire custom event<br>    this.dispatchEvent(eventObj);<br>   }<br> });<br>}</pre><h4>Using Mutation Observers</h4><p>Mutation Observers give us the ability to natively monitor changes in the DOM. We can tell when attributes change or when the external framework has changed our element’s content. You can see this in action here:</p><p><a href="https://plnkr.co/edit/OkrCvP?p=preview">Plunker</a></p><p>The tabs component monitors the DOM content (wrapped within the angular component), and will adjust dynamically.</p><pre>this.mutationObserver = new MutationObserver(this.handleMutations.bind(this));</pre><p>Since the Mutation Observer returns all changes, you have to check if the changes are additions or deletions</p><pre>mutations.forEach(function(mutationRecord){<br>          forEach.call(mutationRecord.addedNodes, function(node){<br>            handlers.push([&#39;add&#39;, node]);<br>          });<br>          forEach.call(mutationRecord.removedNodes, function(node){<br>            handlers.push([&#39;remove&#39;, node]);<br>          });<br>      });</pre><h4>Extending the Shadow DOM</h4><p>Also in this example, you can see the addition of Shadow DOM properties and mixins. These are a great way to make your components extendable. You can read a great post on this <a href="http://meowni.ca/posts/styling-the-dome/">here</a>. Note that Shadow DOM mixins require browser experimental flags.</p><pre>/*<br>  Styling with CSS variables<br>  <a href="https://pawelgrzybek.com/css-custom-properties-explained/">https://pawelgrzybek.com/css-custom-properties-explained/</a><br>  <a href="https://www.polymer-project.org/1.0/docs/devguide/styling#custom-css-properties">https://www.polymer-project.org/1.0/docs/devguide/styling#custom-css-properties</a><br>*/<br>pf-tabs {<br>  --tabs-bg-color: #FFF;<br>  --tabs-active-color: #0088ce;<br>  --tabs-inactive-color: #4d5258;<br>  --tabs-font-size: 1.2em;<br>}</pre><pre>/*<br>  Styling with CSS mixins (Chrome Experimental Feature)<br>  <a href="https://pawelgrzybek.com/css-mixins-with-apply-rule/">https://pawelgrzybek.com/css-mixins-with-apply-rule/</a><br>  <a href="https://www.polymer-project.org/1.0/docs/devguide/styling#custom-css-mixins">https://www.polymer-project.org/1.0/docs/devguide/styling#custom-css-mixins</a><br>*/<br>:root {<br>  --tab-styles: {<br>    background-color:yellow;<br>    display:inline-block;<br>  }<br>}</pre><h4>Conclusion</h4><p>Custom elements and Shadow DOM enable us to write some powerful new extensions in our frameworks. I look forward to exploring these more, and will continue sharing my thoughts here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee935f4c1e30" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>