home-assistant.github.io/blog/categories/technology/atom.xml
2016-08-03 16:17:39 +00:00

46 lines
5.4 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Category: Technology | Home Assistant]]></title>
<link href="https://home-assistant.io/blog/categories/technology/atom.xml" rel="self"/>
<link href="https://home-assistant.io/"/>
<updated>2016-08-03T16:16:51+00:00</updated>
<id>https://home-assistant.io/</id>
<author>
<name><![CDATA[Home Assistant]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Why we use web components and Polymer]]></title>
<link href="https://home-assistant.io/blog/2016/05/18/why-we-use-polymer/"/>
<updated>2016-05-18T00:09:00+00:00</updated>
<id>https://home-assistant.io/blog/2016/05/18/why-we-use-polymer</id>
<content type="html"><![CDATA[<p>Ive been planning to write this post for a while now as we get questions like this a lot: <em>“Why does Home Assistant use Polymer? Why not React, Redux and what not?”</em></p>
<p>Its understandable, Polymer is quite the underdog in the world of web frameworks. A corporate backer does not guarantee popularity or an active community and this shows in the number of projects using Polymer.</p>
<p>Still, <a href="https://home-assistant.io/demo">we use Polymer and its awesome</a>. To explain why, Ill be referencing the React workflow quite a bit, as they do a lot of things right, and show how it is done in Polymer.</p>
<p>Polymer gives us components for the web, just like React, but based on web standards: <a href="https://www.w3.org/standards/techs/components#w3c_all">web components</a>, <a href="https://www.w3.org/TR/css-variables/">CSS variables</a>. These standards dont have wide browser support yet but its being implemented by every major browser: Its the future. For now they are being polyfilled and that works just fine but in the future the Home Assistant web app will be able to run native in the browsers == fast.</p>
<!--more-->
<p>Polymer does not have the nice developer experience that one can have with React and the <a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en">React Dev Tools</a> but thats a matter of time. The developer tools in every browser have seen a lot of improvements recently and each improvement helps support for web components.</p>
<p>Another major benefit of Polymer for Home Assistant is that we get <a href="https://elements.polymer-project.org/browse?package=paper-elements">material design for free</a>. The material design components that come with Polymer have a very high quality. Google is using these components themselves and make sure that performance and accessibility using screen readers/keyboards are great. As an open source project, the more we can outsource, the better - so our contributors can focus on the core product: home automation.</p>
<p>What about Flux, data management and interaction between components? Its actually pretty similar to React or any other component based framework. Flux-like architectures work with Polymer just like with React: whenever data changes it will update the attributes of a component which will propagate to the children. For Home Assistant we use <a href="https://optimizely.github.io/nuclear-js/">NuclearJS</a> with our <a href="http://paulusschoutsen.nl/blog/2015/07/using-polymer-with-flux-and-a-global-app-state/">own Polymer bindings</a>. For data moving from child to parent the Polymer pattern is using DOM events instead of callbacks but the end result is the same. It is so similar in fact, that it took me only two hours to make a <a href="https://github.com/balloob/home-assistant-react-native-ios">React Native frontend for on top of our core</a>.</p>
<p>So what about Babel and ES2015? Also this is covered. Each web component exists of a HTML template and a JavaScript class to back it. Think of the HTML template as the render method in React. In Home Assistant we have the HTML templates import one another and have a separate chain for the JavaScript classes backing each component. This allows us to use Babel and NPM modules for the JavaScript part (<a href="https://github.com/home-assistant/home-assistant-polymer#building-the-app">more info here</a>). This does however come with the downside of other JS based frameworks: the browser blocks any painting while the JavaScript is being parsed instead of upgrading the website incrementally. This, however, is something we take for granted right now and hope that module bundlers will be able to solve this for us eventually. Tree shaking is a very promising improvement in this space.</p>
<p>Most of this blog post has been comparing Polymer to React. In many ways Polymer is similar to React but it is not as far evolved yet. I like React but I do not see it as a technology that will be around forever. Given the trend of previous popular JS frameworks, React will probably get replaced by another framework that works even better. Web components however will be here forever as they are part of the HTML standard. And this gives us peace of mind at the virtual Home Assistant headquarters: we do not have to be afraid of having to rewrite our frontend just to stay relevant or because people dont want to include another dependency just to run this legacy piece.</p>
<p>So there it is, the reason why we use Polymer.</p>
]]></content>
</entry>
</feed>