<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>webcomponents &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<atom:link href="https://jessewarden.com/tag/webcomponents/feed" rel="self" type="application/rss+xml" />
	<link>https://jessewarden.com</link>
	<description>Software &#124; Fitness &#124; Gaming</description>
	<lastBuildDate>Sat, 19 Sep 2015 13:40:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://jessewarden.com/wp-content/uploads/2016/08/cropped-Lambda2-32x32.png</url>
	<title>webcomponents &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<link>https://jessewarden.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Fun With Polymer 1.1</title>
		<link>https://jessewarden.com/2015/09/fun-with-polymer-1-1.html</link>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Sat, 19 Sep 2015 02:20:49 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[htmlimports]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[materialdesign]]></category>
		<category><![CDATA[polymer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shadowdom]]></category>
		<category><![CDATA[webcomponents]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=4895</guid>

					<description><![CDATA[Introduction I&#8217;ve spent the past 2 weeks of my vacation playing with JavaScript, Polymer, Node, Express, Restify, and Mongo.Â Today, I wanted to cover the fun I had with Polymer, Google&#8217;s web UI component framework, contrast it with other frameworks, and give my general impressions. From this you&#8217;ll have a firm understanding of what Polymer is [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>I&#8217;ve spent the past 2 weeks of my vacation playing with JavaScript, <a href="https://www.polymer-project.org/1.0/">Polymer</a>, <a href="https://nodejs.org/en/">Node</a>, <a href="http://expressjs.com/">Express</a>, <a href="http://mcavage.me/node-restify/">Restify</a>, and <a href="https://www.mongodb.org/">Mongo</a>.Â Today, I wanted to cover the fun I had with Polymer, Google&#8217;s web UI component framework, contrast it with other frameworks, and give my general impressions. From this you&#8217;ll have a firm understanding of what Polymer is for, how to use it, and what things to watch for.</p>
<p><span id="more-4895"></span></p>
<h2>What is Polymer?</h2>
<p>Polymer is Google&#8217;s open source web component UI framework. The goal is to allow developers to utilize the latest web standards for web components in a cross browser way, today. <a href="http://www.w3.org/TR/components-intro/">Web components</a> is an umbrella of standards, specifically <a href="http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/">Shadow DOM</a>, <a href="http://www.html5rocks.com/en/tutorials/webcomponents/customelements/">Custom Elements</a>, and <a href="http://www.html5rocks.com/en/tutorials/webcomponents/imports/">HTML Imports</a>.</p>
<p>These are the core technologies needed in browsers to build web components.Â Given the web community is &#8220;design by committee&#8221;, it&#8217;s actually quite a fast moving standard in that context, thus much has changed between Polymer version 0.5 and version 1.x. That said, Google&#8217;s done a great job of shielding you from a lot of these core changes as well as including new featuresÂ that iterate on top of previous work.</p>
<p>&#8230; the whole point of creating a UI framework, heh.</p>
<p>In short, Polymer allows you to create your own UI controls more easily than you could in the past, built on webÂ standards, and with performance in mind.Â That, and they already follow the <a href="https://www.google.com/design/spec/material-design/introduction.html">Material Design guidelines</a>.</p>
<h2>What does the codeÂ look like in practice?</h2>
<p>While this is native in browsers now:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.45-AM.png"><img decoding="async" class="size-full wp-image-4899 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.45-AM.png" alt="Screen Shot 2015-09-18 at 11.14.45 AM" width="374" height="45" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.45-AM.png 374w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.45-AM-300x36.png 300w" sizes="(max-width: 374px) 100vw, 374px" /></a></p>
<p>Results in this:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.53.19-PM.png"><img decoding="async" class="size-full wp-image-4906 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.53.19-PM.png" alt="Screen Shot 2015-09-18 at 2.53.19 PM" width="64" height="57" /></a></p>
<p>You can now do this:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.54.17-PM.png"><img decoding="async" class="size-full wp-image-4910 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.54.17-PM.png" alt="Screen Shot 2015-09-18 at 2.54.17 PM" width="532" height="47" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.54.17-PM.png 532w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.54.17-PM-300x27.png 300w" sizes="(max-width: 532px) 100vw, 532px" /></a></p>
<p>And you&#8217;ll see this:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.52.47-PM1.png"><img loading="lazy" decoding="async" class="size-full wp-image-4908 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.52.47-PM1.png" alt="Screen Shot 2015-09-18 at 2.52.47 PM" width="87" height="54" /></a></p>
<p>Notice in <a href="http://getbootstrap.com/">Bootstrap</a>, you have toÂ apply the CSS classes toÂ the tag:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.13.31-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4911 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.13.31-PM.png" alt="Screen Shot 2015-09-18 at 3.13.31 PM" width="74" height="54" /></a></p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.13.49-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4912 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.13.49-PM.png" alt="Screen Shot 2015-09-18 at 3.13.49 PM" width="797" height="57" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.13.49-PM.png 797w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.13.49-PM-300x21.png 300w" sizes="auto, (max-width: 797px) 100vw, 797px" /></a></p>
<p>Unlike Bootstrap, and like <a href="http://benclinkinbeard.com/posts/introducing-atomify-a-new-standard-of-modularity/">Atomify</a>,Â Polymer&#8217;s goal is encapsulate everything; not just the CSS,Â but also the JavaScript functionality, and additional HTML tags that make it up.</p>
<p>You&#8217;ll see a common theme with Polymer is mainly focused around markup, specifically HTML tags. If you come from <a href="https://angularjs.org/">Angular</a> or <a href="https://facebook.github.io/react/">React</a>, you&#8217;ll immediately get that concept of creating your own elements to use. Polymer is the same way.</p>
<p>The reason for this is attempting to mitigateÂ &#8220;div soup&#8221;, where you have a lot of nested divs that use CSS styles create the user interface, as well as helping create semantics: allowing various technologies to glean meaning from your page. The semantics help for Search Engine Optimization, Accessibility, and even during development to lessen the cognitive overhead from developers and designers.</p>
<p>Contrast how <a href="https://mail.google.com/">GMail</a> is built:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/div-soup.png"><img loading="lazy" decoding="async" class="alignnone wp-image-4897 size-large" src="http://jessewarden.com/wp-content/uploads/2015/09/div-soup-1024x601.png" alt="div-soup" width="604" height="354" srcset="https://jessewarden.com/wp-content/uploads/2015/09/div-soup-1024x601.png 1024w, https://jessewarden.com/wp-content/uploads/2015/09/div-soup-300x176.png 300w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a></p>
<p>Versus using custom components:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.02-AM.png"><img loading="lazy" decoding="async" class="wp-image-4902 size-full alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.02-AM.png" alt="" width="896" height="308" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.02-AM.png 896w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-11.14.02-AM-300x103.png 300w" sizes="auto, (max-width: 896px) 100vw, 896px" /></a></p>
<p>AlthoughÂ Polymer&#8217;s nomenclature is about &#8220;tags&#8221; and &#8220;custom elements&#8221;, what you&#8217;re really doing is creating &#8220;components&#8221;: visual and non-visual.</p>
<h2>Why Even Do This?</h2>
<p>Components, Composition, Encapsulation, and Design.</p>
<h3>Components: It&#8217;s How InterfacesÂ Start</h3>
<p>Once you&#8217;ve got a few applications built under your belt, you start recognizing 2 patterns that emerge every project. You have a visual style guide, whether official or unofficial, that you follow. How buttons look, work, what colorsÂ the button is vs. the text,Â and its shape are all examples of the minutiae.</p>
<p>The other pattern is re-use. This is not just a programming concept related to <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>, but a design one as well.Â The rule is you&#8217;re supposed to use the same UI controls for the same user actions so users can more easily use your application. Jakob Nielsen covers that in the &#8220;2. Inconsistency&#8221; section of his <a href="http://www.nngroup.com/articles/top-10-application-design-mistakes/">Top 10 Application Design Mistakes article</a>.</p>
<p>Whether using Angular, React, or Polymer, you&#8217;re going to create 1 button, 1 time, and use it every where in your application a button is needed.</p>
<p>This applies to all user controls. Polymer&#8217;s core concept is building theseÂ components while providing many of which you need out of the box so you don&#8217;t have to create everything from scratch. That said, if you wish to opt-out of Material Design, you can use the core web component libraries it provides to use your own look and feel.</p>
<h3>Composition: It&#8217;s How Interfaces are Made</h3>
<p>Once you have your components built, you then start composing them together into large components that house other components. This is called <a href="https://en.wikipedia.org/wiki/Object_composition">composition</a>, usingÂ something in another thing. You either build more complex components using these pieces together, or build containers. This can be a customized button inside of a calendar control:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/calendar.png"><img loading="lazy" decoding="async" class="size-full wp-image-4903 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/calendar.png" alt="calendar" width="620" height="476" srcset="https://jessewarden.com/wp-content/uploads/2015/09/calendar.png 620w, https://jessewarden.com/wp-content/uploads/2015/09/calendar-300x230.png 300w" sizes="auto, (max-width: 620px) 100vw, 620px" /></a></p>
<p>Which is created by oneÂ HTML tag:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.50.32-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4904 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.50.32-PM.png" alt="Screen Shot 2015-09-18 at 2.50.32 PM" width="829" height="59" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.50.32-PM.png 829w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.50.32-PM-300x21.png 300w" sizes="auto, (max-width: 829px) 100vw, 829px" /></a></p>
<p>or a button and a text field input inside of a self-contained login form:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.48.15-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4905 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.48.15-PM.png" alt="Screen Shot 2015-09-18 at 2.48.15 PM" width="430" height="274" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.48.15-PM.png 430w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-2.48.15-PM-300x191.png 300w" sizes="auto, (max-width: 430px) 100vw, 430px" /></a></p>
<p>Which is also created by one HTML tag:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.20.19-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4914 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.20.19-PM.png" alt="Screen Shot 2015-09-18 at 3.20.19 PM" width="554" height="105" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.20.19-PM.png 554w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.20.19-PM-300x57.png 300w" sizes="auto, (max-width: 554px) 100vw, 554px" /></a></p>
<p>Lastly, you&#8217;ll sometimes create containers that house dynamic content and use HTML&#8217;s declarative nature. Polymer&#8217;s &lt;paper-card&gt; is a perfect example. Not only can you house custom content,Â they also gave you 2 areas for it to live, theÂ &#8216;content&#8217; and &#8216;actions&#8217; area for buttons:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.27.52-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4915 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.27.52-PM.png" alt="Screen Shot 2015-09-18 at 3.27.52 PM" width="320" height="448" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.27.52-PM.png 320w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.27.52-PM-214x300.png 214w" sizes="auto, (max-width: 320px) 100vw, 320px" /></a></p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.28.12-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4916 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.28.12-PM.png" alt="Screen Shot 2015-09-18 at 3.28.12 PM" width="870" height="247" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.28.12-PM.png 870w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.28.12-PM-300x85.png 300w" sizes="auto, (max-width: 870px) 100vw, 870px" /></a></p>
<p>Like <a href="https://docs.angularjs.org/api/ng/directive/ngTransclude">Angular&#8217;s ngTransclude</a>, or <a href="http://backbonejs.org/">Backbone</a> <a href="http://marionettejs.com/">Marionette&#8217;s Regions</a>, you simply use a &lt;content&gt;&lt;/content&gt; tag in your component, and that&#8217;s where stuff will go.</p>
<p>The more complex theÂ components and screens, the more composition and containers you&#8217;ll create. Polymer easily enables composition and containers.</p>
<h3>Encapsulation: D0 One Thing Well and Don&#8217;t Tell Anyone How You Do It</h3>
<p>While functional &amp; reactive programming are in, Object Oriented ProgrammingÂ is still how most projectsÂ are primarily done and how most programming is still taught.Â Good OOP is when you create components that have a well understood API and don&#8217;t leak too much detail and state.</p>
<p>Doing that in HTML, JavaScript, and CSS is really hard. HTML&#8217;s DOM API makes your document an open book. Tag ID&#8217;s and class names are effectively global variables, and cannot clash. JavaScript has no module API norÂ built-in ways of privacy without working around how JavaScript works. CSS is SUPPOSED to cascade; that is a core feature of CSS.</p>
<p>Polymer attempts to fixÂ the encapsulation problems the web has.</p>
<h4>HTML</h4>
<p>Shadow DOM enables you toÂ hide DOM from the document. Just like you can&#8217;t open a native &lt;button&gt;, your normal DOM API code won&#8217;t dig into your component.</p>
<h4>CSS</h4>
<p>This is in flux, but similar to HTML, the CSS styles you define in your Shadow DOM only apply to that component. They don&#8217;t leak out and overwrite other styles. Conversely, you effectively have an umbrella from cascading styles so your component&#8217;s styles aren&#8217;t overwritten if they have the same names of something else. You can confidently put your component in any other application and be assured it&#8217;ll look the same.</p>
<h4>JavaScript</h4>
<p>Beyond makingÂ Object.prototype easier to work with, they don&#8217;t do much here since the web component has a lot of otherÂ solutions forÂ this. However, they DO make it easier to import via HTML imports. Whether your code is code or visual code, both can be imported using the same tag.</p>
<p>The workÂ Google has done with Polymer means you only have to do 2 steps to use a component you or someone else has written: import it and use it.</p>
<p>Import:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.48.51-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4917 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.48.51-PM.png" alt="Screen Shot 2015-09-18 at 3.48.51 PM" width="605" height="58" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.48.51-PM.png 605w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.48.51-PM-300x29.png 300w" sizes="auto, (max-width: 605px) 100vw, 605px" /></a></p>
<p>And then use it as normal HTML, in the light dom or shadow dom:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.39-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4918 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.39-PM.png" alt="Screen Shot 2015-09-18 at 3.49.39 PM" width="654" height="48" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.39-PM.png 654w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.39-PM-300x22.png 300w" sizes="auto, (max-width: 654px) 100vw, 654px" /></a></p>
<p>Or via JavaScript:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.53-PM.png"><img loading="lazy" decoding="async" class="size-full wp-image-4919 alignnone" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.53-PM.png" alt="Screen Shot 2015-09-18 at 3.49.53 PM" width="777" height="63" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.53-PM.png 777w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-3.49.53-PM-300x24.png 300w" sizes="auto, (max-width: 777px) 100vw, 777px" /></a></p>
<p>That is way easier than theÂ copious DevOps, transpilers, and module libraries I and others use today. This is also whyÂ <a href="https://angulardart.org/">Angular Dart</a> years ago went to the <a href="https://github.com/angular/angular.dart/blob/master/example/web/form.dart#L4">component model</a>, and where Angular 2 is going with <a href="http://blog.wolksoftware.com/decorators-metadata-reflection-in-typescript-from-novice-to-expert-part-4?utm_content=buffer0ff0d&amp;utm_medium=social&amp;utm_source=twitter.com&amp;utm_campaign=buffer">class annotation</a>. While functional is in, the basic concepts of modules, package organization, and encapsulation are still valid, good concepts to use and build applications with.</p>
<h3>Design the UI, it Then (Mostly) Builds Itself</h3>
<p>Designing applications is different from designing websites. TheÂ web development world is vast, complex, and there are a variety of approaches. The only consistency I&#8217;ve seen regarding design is that those building applications tend to encapsulate their design into the components they use to build applications whereas the webÂ designers tend to do this from their CSS/LESS/SCSS.</p>
<p>Polymer is clearly on the developers side on this one in that embracing Shadow DOM, I can layoutÂ my component&#8217;s visual pieces, code it to work, and style it all in the same place. Once I distribute it, I don&#8217;t have to worry about style names that make sense, how the CSS is organized, what build task I use to re-compile the LESS, etc.</p>
<p>Instead, you either just code the CSS inline with your component with confidence you aren&#8217;t negatively affecting another component, or you use <a href="http://jessewarden.com/2015/08/sharing-css-between-polymer-components-in-version-1-1-vs-0-5.html">common styles</a> which are a safe, opt-in approach. That way, if you want to share a single style sheet, or support theming, you can do that without breaking encapsulation.</p>
<p>At this point, you help mitigate the biggest problem Web Designers have: Developers.</p>
<p>Most developers I&#8217;ve met say they care about design, but in practice don&#8217;t. This isn&#8217;t malicious, they&#8217;re justÂ focused on their job and that&#8217;s making things work. They&#8217;re held accountable when they don&#8217;t work. If the color or font is wrong? That&#8217;s ok. Doesn&#8217;t compile or show the data correctly from the database? That&#8217;s not ok.</p>
<p>This culture reinforces developers to stay away from design concerns unless they have too since a lot of design changes can&#8217;t easily be unit tested like their code can.</p>
<p>With Polymer, once you hand a developer a component with the padding, fonts, and colors already correct, it&#8217;s pretty hard for them to screw that upÂ unless they dive into the source components. For a Designer, that&#8217;s powerful. For a Developer who hates CSS or loves design but doesn&#8217;t have time for it, it&#8217;s awesome. For a Business Analyst, that&#8217;s less JIRA tickets that pollute the backlog and never get done in time for people to remember what the ticket was referring to.</p>
<p>Additionally, for other designers,Â you can expose components via variables to allow them to break through the Shadow DOM in a clean and well documented manner, yet still abstract the implementation in case you have to refactor the component later.</p>
<p>Components enable designers to ensure the building blocks developers use aren&#8217;t as easily broken, and developers in turn don&#8217;t have to worry as much about &#8220;Crap, I forgot to re-add that CSS class which I can&#8217;t remember it&#8217;s name after I refactored that partial.&#8221;</p>
<h3>So&#8230; Why Again?</h3>
<p>Interfaces for applications are built using components. Polymer makes it easy for you to buildÂ components using JavaScript, HTML, and CSSÂ by keeping them in the same file.</p>
<p>Application interfaces are typically built by composing components withinÂ components to create more complex views and screens. Polymer can use Polymer components inside of Polymer components. You can also create containers to enable this dynamically.</p>
<p>Polymer encapsulates HTML names and ID&#8217;s via Shadow DOM ensuring you don&#8217;t have naming conflicts that break your application without a runtime exception letting you know it break based on some random design change. It also encapsulates your CSS there as well, inverting the control of how CSS works, ensuring the only CSS changes you can make are opt-in, or explicit via easily found keywords like /deep/, or developer created variables.</p>
<p>For Developers, it enables easier encapsulation and adherence to OOP concepts by making it easy to re-use the visual and non-visual components you create.</p>
<p>For Designers, it helpsÂ ensure their CSS isÂ harder to break by developers who don&#8217;t know any better by wrapping them in core building block components the developers don&#8217;t need to go into.</p>
<h2>How Do I Use It?</h2>
<p>I chose the hard way. I suggest you have more fun and choose the easy ways.</p>
<p>First, check out theÂ <a href="https://github.com/yeoman/generator-polymer">Yeoman generator-polymer</a>. It&#8217;ll get you up and running fast, and has a build system already setup for you.</p>
<p>Second, if Yeoman ain&#8217;t yo thing, go straight to the <a href="https://developers.google.com/web/tools/polymer-starter-kit/">Starter Kit</a> (it&#8217;s what the generator helps get started for you).</p>
<p>Third, you can just go straight to the <a href="https://github.com/polymerelements/seed-element">Seed Element</a> to get up and running with something simple and smaller locally to play with.</p>
<p>Fourth, what was most enlightening for me was to build a component using the 0.5 docs &#8220;<a href="https://www.polymer-project.org/0.5/docs/start/tutorial/intro.html">Your First Polymer Application</a>&#8220;. They haven&#8217;t been updated for 1.0, but if you don&#8217;t mind hitting the <a href="https://www.polymer-project.org/1.0/docs/migration.html">migration guide</a>,Â it still gets you 90% of the way there with the core concepts.</p>
<p>Fifth, <a href="https://twitter.com/rob_dodson">Rob Dodson</a> has a great <a href="https://www.youtube.com/playlist?list=PLNYkxOF6rcIDdS7HWIC_BYRunV6MHs5xo">YouTube channel called Polycasts</a> where he goes over building Polymer components and covers everything and builds on earlier content.</p>
<h2>Polymer Gotchas</h2>
<p>Here some of the things that threw me for a loop.</p>
<h3>Events</h3>
<p>When you read the docs for the iron and paper elements, they have properties and method documentation, but NOT events. As someone who builds GUI&#8217;s, this seems like a glaring oversight. To fix it, first, memorize how events work via the <a href="https://www.polymer-project.org/1.0/docs/devguide/utility-functions.html">fire method</a>.</p>
<p>If someone goes:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.17.25-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4926" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.17.25-PM.png" alt="Screen Shot 2015-09-18 at 6.17.25 PM" width="281" height="63" /></a></p>
<p>Then you knowÂ the event to listen for is &#8216;on-change&#8217;:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.18.23-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4927" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.18.23-PM.png" alt="Screen Shot 2015-09-18 at 6.18.23 PM" width="815" height="54" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.18.23-PM.png 815w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.18.23-PM-300x20.png 300w" sizes="auto, (max-width: 815px) 100vw, 815px" /></a></p>
<p>Every single one of the paper elements links directly to the source code. Dig in there for a &#8220;fire&#8221; method. If you don&#8217;t find it, then see which behaviors it implements (think <a href="https://en.wikipedia.org/wiki/Decorator_pattern">Decorator pattern</a> or multiple inheritance ) and find their source code in the <a href="https://github.com/polymer">Polymer repo</a> via the search function. Otherwise,Â scroll back to the top, and see what components it&#8217;s using. The fire method bubbles by default, so the components its using by composition could be the ones who actually fire the original event.</p>
<p>Remember, fire(&#8216;moo-cow&#8217;) results in a &lt;component on-moo-cow=&#8221;onWubWubWub()&#8221;&gt;&lt;/component&gt;. If you use camelCase instead of dash-case for fire events, you&#8217;ll drive yourself nuts when things don&#8217;t work.</p>
<h3></h3>
<h3>animationConfig Placement</h3>
<p>I lost 2 days trying to get animations to work because both times I put it outside of the properties object. It&#8217;s supposed to <a href="https://www.youtube.com/watch?v=Lwvi1u4XXzc">go inside</a>. If you think I&#8217;m not a moron, <a href="https://github.com/PolymerElements/neon-animation/pull/73">please +1 this PR</a>.</p>
<h3>Non-Visual Components</h3>
<p>Once you start getting knee deep in building visual Polymer components for a few days, you forget that you could build non-visual ones as well. Since you can onlyÂ use inheritance on native controls, most of your code will be composition: enhancing existing tags.</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.29.13-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4928" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.29.13-PM.png" alt="Screen Shot 2015-09-18 at 6.29.13 PM" width="920" height="1128" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.29.13-PM.png 920w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.29.13-PM-245x300.png 245w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.29.13-PM-835x1024.png 835w" sizes="auto, (max-width: 920px) 100vw, 920px" /></a></p>
<h3>Core Things Nobody Tells You About</h3>
<p>If you&#8217;ve been building applications on the front end for awhile, you start to have some expectations on where the basic things are. Here they are.</p>
<h4>Ajax/XHR/HTTP Requests</h4>
<p>Use <a href="https://elements.polymer-project.org/elements/iron-ajax">iron-ajax</a>.</p>
<h4>Making selectable lists</h4>
<p>Use <a href="https://elements.polymer-project.org/elements/iron-selector">iron-selector</a>.</p>
<h4>Pub Sub</h4>
<p>If you miss your <a href="http://backbonejs.org/#Events-trigger">_.trigger</a> or <a href="https://docs.angularjs.org/api/ng/type/$rootScope.Scope">$rootScope.$broadcast</a>Â then use <a href="https://elements.polymer-project.org/elements/iron-signals">iron-signals</a>.</p>
<h4>Basic CSS Layout</h4>
<p>Read the source for <a href="https://github.com/PolymerElements/iron-flex-layout/blob/master/iron-flex-layout.html">iron-flex-layout</a>, and remove the dashes in your head. This allows you to do <a href="https://elements.polymer-project.org/guides/flex-layout">everything you could in 0.5</a>, except usingÂ the class attribute.</p>
<p>This:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.44-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4929" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.44-PM.png" alt="Screen Shot 2015-09-18 at 6.41.44 PM" width="435" height="116" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.44-PM.png 435w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.44-PM-300x80.png 300w" sizes="auto, (max-width: 435px) 100vw, 435px" /></a></p>
<p>Becomes this:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.48-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4930" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.48-PM.png" alt="Screen Shot 2015-09-18 at 6.41.48 PM" width="442" height="112" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.48-PM.png 442w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-6.41.48-PM-300x76.png 300w" sizes="auto, (max-width: 442px) 100vw, 442px" /></a></p>
<h4>ResponsiveÂ Layouts / Media Queries</h4>
<p>When you&#8217;re buildingÂ components or screens that have 2 layouts, you use the <a href="https://elements.polymer-project.org/elements/iron-media-query">iron-media-query</a> inline. IfÂ you start duplicating markup for each media query, justÂ refactor it to a component.</p>
<h4>Icons</h4>
<p>There&#8217;s like 5 icon classes&#8230; ignore them. Just install <a href="https://github.com/PolymerElements/iron-icons">iron-icons</a>, then import the ones you need or all of them. To see which ones are available, navigate to the bower_components/iron-icons/demo/ folder on your local web server to see which ones you can use.</p>
<p>ALL of the icons use the same naming structure: &#8220;category:name&#8221;, whether an <a href="https://elements.polymer-project.org/elements/iron-icon">iron-icon</a> or a <a href="https://elements.polymer-project.org/elements/paper-icon-button">paper-icon-button</a>. So if you see the icon attribute, that&#8217;s what the icon name really means.</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-7.12.19-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4932" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-7.12.19-PM.png" alt="Screen Shot 2015-09-18 at 7.12.19 PM" width="642" height="136" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-7.12.19-PM.png 642w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-7.12.19-PM-300x64.png 300w" sizes="auto, (max-width: 642px) 100vw, 642px" /></a></p>
<h4>Infinite Scrolling List</h4>
<p>&#8230; ah, the question you wish C# developers would ask you on interviews vs. red/black tree sorting&#8230; *ahem* If you need one, use <a href="https://elements.polymer-project.org/elements/iron-list">iron-list</a>.</p>
<h4>Images</h4>
<p>They have a really cool uber-image component called <a href="https://elements.polymer-project.org/elements/iron-image">iron-image</a>. Way better than img tags.</p>
<h4>localStorage</h4>
<p>They have a nice wrapper around localStorage called <a href="https://elements.polymer-project.org/elements/iron-localstorage">iron-localstorage</a> that would of saved me a lot of time. Basically allows you to use Polymer&#8217;s built-in data-binding with localStorage.</p>
<h2>Routing</h2>
<p>Polymer doesn&#8217;t ship with a router. They did in 0.5, but in 1.x they assume you&#8217;ll use a router that&#8217;s right for you. There are a few Polymer specific ones on Github and <a href="https://customelements.io/">CustomElements.io</a>.</p>
<p>I tried a few, but none work with the way I work with Mediator View&#8217;s doing most of the heavy lifting. Some weren&#8217;t declarative enough or didn&#8217;t support custom &lt;templates&gt;. Worse, the majority only supported 0.5, not 1.x.</p>
<p>I attempted to wrap Angular&#8217;s <a href="https://github.com/angular-ui/ui-router">UI-Router</a> in a component, but got frustrated pretty quickly with the inability to easily have them talk to each other so just went with <a href="https://visionmedia.github.io/page.js/">page.js</a>.Â  It works quite well.</p>
<h2>Scope</h2>
<p>Polymer focuses on HTML and CSS betterment, not JavaScript. As such, all the same problems with scope exist in Polymer script tags since it&#8217;s basic JavaScript. Everywhere you put &#8220;var me = this&#8221;. If you&#8217;re not going to use a framework, I recommendÂ <a href="https://lodash.com/docs#bindAll">Lodash&#8217; bindAll</a>.</p>
<h2>DevOps</h2>
<h3>Code Quality</h3>
<p>The <a href="http://jshint.com/">jshint</a> works in <a href="http://gruntjs.com/">Grunt</a> and <a href="http://gulpjs.com/">Gulp</a>, but I couldn&#8217;t get <a href="http://jscs.info/">jscs</a> to work unless you externalize your script files and ignore the Polymer html files.</p>
<h3>Injector and Wiredep</h3>
<p>As your project grows, you&#8217;ll need some type of module system. The nice thing about Polymer is that it handles load order for you; as long as you have all your imports there, it doesn&#8217;t matter what order they are in. However,Â <a href="https://github.com/polymer/vulcanize">Vulcanize</a>, the build tool for Polymer, doesn&#8217;t always work with 3rd party libraries.Â I use Injector (<a href="https://www.npmjs.com/package/grunt-injector">grunt</a> / <a href="https://www.npmjs.com/package/gulp-inject">gulp</a> ) which now embeds <a href="https://github.com/taptapship/wiredep">Wiredep</a>Â so it automatically puts script tags for all your <a href="https://www.npmjs.com/">npm</a> and <a href="http://bower.io/">bower</a> classes.</p>
<p>I found running these first, then running Vulcanize afterwards excluding the build path classes in the ignorePath option seemed to work. I didn&#8217;t attempt minifiy/uglify the Polymer specific scripts as they weren&#8217;t externalized. I find while developing it&#8217;s easier to target the DOM I&#8217;m working with if it&#8217;s in the same file and I scroll up. It&#8217;d be nice to find a build way to automatically externalize the JavaScript and the CSS.</p>
<p>Also, I couldn&#8217;t get either of the Grunt or Gulp Vulcanize plugins to play nice with my build structure paths so just wrote <a href="https://github.com/JesterXL/Starting-Strength-Polymer/blob/master/Gruntfile.js#L120">raw JavaScript</a> for it and it worked.</p>
<h3>Unit Tests</h3>
<p>I couldn&#8217;t get the <a href="https://github.com/Polymer/web-component-tester">web components tester</a> to work. After spending hours in Grunt fighting with various missing paths, I gave up.Â I reckon if I had used the Yeoman generator, it&#8217;d work.Â I did get the sample seed-element project&#8217;s tests working though.</p>
<h2>What About <a href="http://www.x-tags.org/">X-Tags</a>?</h2>
<p>&nbsp;</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/girl-shrugging.jpg"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4934" src="http://jessewarden.com/wp-content/uploads/2015/09/girl-shrugging.jpg" alt=":: shrugs ::" width="600" height="495" srcset="https://jessewarden.com/wp-content/uploads/2015/09/girl-shrugging.jpg 600w, https://jessewarden.com/wp-content/uploads/2015/09/girl-shrugging-300x248.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a></p>
<h2>Why Would I Use Polymer vs. Something Like Bootstrap or Foundation?</h2>
<p>Polymer is part component framework, but it&#8217;s also a way to use the newest stuff, now, and help give Google feedback on direction. Since last year, Polymer has been the &#8220;living prototype&#8221; of the web components standards and has changed as both people have used it, the ideas Google has had to improve upon it, and the standards committeeÂ has started standardizing on the implementations.</p>
<p>Unlike Bootstrap/<a href="http://foundation.zurb.com/">Foundation</a>, you&#8217;re building real web components, not divs with decoration.</p>
<p>A lot of the value that Polymer provides is that it implements Google&#8217;s Material Design. If you don&#8217;t want that look and feel, you can still use most of the <a href="https://elements.polymer-project.org/browse?package=iron-elements">iron</a> and <a href="https://elements.polymer-project.org/browse?package=neon-elements">neon</a> animation elements and just stay away from paper.</p>
<p>For those of us in enterprise development building large applications, Bootstrap reigns supreme, mainly because it has all the components we need, now. Contrast that with Polymer, I had to build a <a href="https://github.com/JesterXL/jxl-paper-date-picker">Calendar / Date Picker</a>Â since most of the ones I found were 0.5 only. I then found another v1 the next day. The community DOES build a lot on Github, but quality does vary, and it&#8217;s not a single project like Bootstrap&#8217;s is.</p>
<p>Bottom line, Bootstrap just has more of everything you need, both in design, typography, components, and layout.</p>
<h2>Could I Use Polymer With Angular, Backbone, or React?</h2>
<p>If you&#8217;re going to use it with Angular, try <a href="https://material.angularjs.org/latest/#/">Angular Material</a> first. You&#8217;re basically marrying yourself to Material Design&#8217;s look and feel, but most clients I know would be mostly ok with that.</p>
<p>If you want to do it yourself, I don&#8217;t recommend it. Angular 1.0 doesn&#8217;t yet play well with Shadow DOM, whereas Angular 2 is getting there. You get <a href="https://github.com/webcomponents/webcomponentsjs/issues/396">weird bugs</a> unless you do it <a href="https://gist.github.com/JesterXL/bf8156a61df7704c4e4a">just right</a>&#8230; which doesn&#8217;t really feel right. If you do forge ahead, you&#8217;ll enjoy that most of your Angular directives can merely have this as their template:</p>
<p><a href="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-9.01.08-PM.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4935" src="http://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-9.01.08-PM.png" alt="Screen Shot 2015-09-18 at 9.01.08 PM" width="588" height="43" srcset="https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-9.01.08-PM.png 588w, https://jessewarden.com/wp-content/uploads/2015/09/Screen-Shot-2015-09-18-at-9.01.08-PM-300x22.png 300w" sizes="auto, (max-width: 588px) 100vw, 588px" /></a></p>
<p>Notice it&#8217;s template, not templateUrl, which means this is a nice way to give your Polymer components Controllers&#8230; sort of. While the methods work, binding and events were hard to figure out if they were working or not.</p>
<p>For <a href="http://backbonejs.org/">Backbone</a>, things are murky. The Backbone View is basically your Polymer component&#8217;s JavaScript, and the &lt;template&gt;&lt;/template&gt; tag contentsÂ is the Handlebars template. Polymer already has a pub sub library, so there is no need for Backbone Events. While in theory Backbone Views could make good Controller classes, it&#8217;d be easier to just do this yourself listening for attached/detached events from your components, a la <a href="http://www.adobe.com/devnet/actionscript/articles/intro-robotlegs-pt1.html">Robotlegs Context</a>.</p>
<p>I haven&#8217;t tried this myself, but I know of one big bank that was investigating this approach last year mainly because they still have a lot of JSP and portals where full applications cannot be built, so instead they share mini-applications. Polymer seems a great fit for this.</p>
<p>After having some experience using their composition strategy, both Angular and Backbone are way harder to integrate with than I originally thought since once you&#8217;re out of the Polymer realm, things get harder to work with. Binding doesn&#8217;t work, so you have to get/set things. Events aren&#8217;t data bound, so you have to use addEventListener. Things like that. It&#8217;s just easier to live and work in the Polymer realm, and take the same approach you do in Backbone architecture: add as you need <a href="https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it">YAGNI</a> style.</p>
<p>More investigation is needed as I might of missed some things or did outside world integration wrong.</p>
<p><a href="https://facebook.github.io/react/">React</a> makes no sense with Polymer. They bothÂ are trying to solve the same thing: faster and easier DOM. React <a href="http://calendar.perfplanet.com/2013/diff/">claims</a> that <a href="http://blog.500tech.com/is-reactjs-fast/">it&#8217;s fast</a>, whereas a lot of the Polymer justification of the &lt;template&gt; tag and Shadow DOM is performance.Â I don&#8217;t know who&#8217;s right, but both build reusable components, have data binding, have a nice component lifecycle, make the DOM easier to work with, and have no implied MVCÂ architecture on top. It&#8217;d be easier to use React within Polymer I think, but again, I don&#8217;t see the point unless you believe the speed benefits could help in the Shadow DOM realm.</p>
<h2>Conclusions</h2>
<p>Polymer&#8217;s great. I like the v1.1 release a lot. Using components feels natural, and is how I builtÂ applications from my Director, Flash, Silverlight, and Flex days. While I hate CSS, I enjoy that Flexbox mostly works, and much of Material Design is already implemented for me. I like the iron and paper components I have out the box.</p>
<p>I&#8217;m disappointed it&#8217;s not as many as Bootstrap. I also miss all of theÂ Angular features I&#8217;ve become accustomed to, mainly ui-router, Controllers, and dependency injection for easier unit testing. Jury&#8217;s out on DevOps. I also miss the 0.5 docs; I&#8217;m guessing the plethora of standards changes at Google is just really fast and maybe their short on documentation resources, or don&#8217;t have an easy way for open source to contribute on that front.</p>
<p>If IÂ had aÂ smaller gig where I wasn&#8217;t building a large, year longÂ application with 20+ developers, AND I could justify the time building the missing Bootstrap components/css if any,Â I&#8217;d definitely choose Polymer. As someone who was forced to the web, it&#8217;s certainly made it a lot more fun to work with.</p>
<p>If you&#8217;d like to learn more, I&#8217;veÂ got <a href="https://github.com/JesterXL/jxl-paper-date-picker">a calendar component</a> I built and a <a href="https://github.com/JesterXL/Starting-Strength-Polymer">Polymer, Node, and MongoÂ reference applications</a> as well.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
