📜 ⬆️ ⬇️

Understandable and simple about web components and Polymer



Who am I

I am Alexander Kasheverov. By education - Master of Radiophysics. I am a web developer by profession. I have been working in DataArt since 2011, since 2009 I am interested in IT and web technologies.

What is the article short

Consider what are web components and polymer. A little reflection on the development of the web. Look at the technical details, examples, browser support, testing. Briefly, of course, in the case. With pictures.
')
Introduction

The web is constantly evolving. Technologies were invented and implemented based on the needs that were relevant at the time of creation. Ten years ago it was impossible to do what we are implementing now, and it is difficult to imagine what will happen in another 10 years.

The business requires the creation of large and complex web-based software products with rich functionality, beauty, high performance. Such solutions are non-trivial in themselves, and the specificity of web technologies is also superimposed. Often, to reduce the complexity of the product, it is divided into many simpler parts. Such a component approach reduces chaos, improves structure, comprehensibility, and increases the efficiency of teamwork.

To reduce headaches, it would be good if in the context of the web:



This is currently not quite the case. Regarding JavaScript: you have to make sure that it does not work with the global scope and that various components do not accidentally interact with each other. In CSS, there is no encapsulation and there is a need to invent methodologies like MCSS and bem so that nothing breaks once again. And finally, in HTML you can see a lot of unnecessary elements on the page, for example, even now in gmail mail ...



Confused ... Isn't it so?
The frameworks in varying degrees introduce component orientation and try to solve these problems. However, they are also built on the same HTML, CSS, JavaScript.

Web Components - short

The web is slowly but surely moving toward compenmantisation - this is a natural process. Difficult can be simplified by breaking into pieces. In parallel with the development of frameworks, work is proceeding at a lower level. Web components are gaining popularity. This is an implementation of the idea of ​​browser-based componentorization.

The history of web components began in 2011 (the first mention on github). Briefly - what is it:



When using these four technologies together, autonomous reusable blocks are obtained - web components.

In fact, a kind of web component has already been created long ago. The simplest example is the element.
<select> 


There is a separate tag for it. Interacting with the element, a drop-down list appears and this logic is hidden from us, besides it has its own styles.

 <select> <option value="Yandex">Yandex</option> <option value="Google" selected>Google</option> <option value="Yahoo">Yahoo</option> </select> 




Same with HTML5 elements.
 <video> </code>  <code> <audio> 
.

This is the essence of web components - the creation of simple and understandable independent elements with hidden logic, styles.

Surely, many people connected to the project Bootstrap - for this you need to separately register loading of styles and scripts. With components this could be made easier.
 <link rel="import" href="bootstrap.html"> 


Web components are not a framework. This is a set of technologies implemented at the browser level.

Web Components - Browser Support & polyfills

At the moment (November 2015), three of the four technologies are in the “Working Draft” stage at the W3C .
This is what the situation looks like at the moment (November 2015):



Since web components in perspective have high value, but, as usual, are not supported by all browsers, ways are being created to improve support. This is how polyfills appeared.

With their help, browser support is already better .



On the web page, the polyfill connects as standard to the head (up to all scripts that use web components):
 <script src="path/webcomponents.js"></script> 


Web components - links



Polymer

Meanwhile, Google is simplifying and developing everything. Work began in the fall of 2012, judging by the history of commits on github . They took web components, polifila and created another add-on.

Polymer's goal is to simplify the creation of high-quality web applications (quote product manager from the Google IO conference).

Polymer - short

The library is a web-based components, polifila to support older browsers, it is all wrapped in a holistic, more convenient system with the addition of sugar.

Schematically it looks like this:


Google created a set of ready-made components and divided them into logical parts:


Basic building blocks
<iron-icon>, <iron-input>, <iron-list>, ...

Elements based on iron-elements and material design
<paper-input>, <paper-button>, <paper-tooltip>, ...

A collection of web components using various Google APIs.
<google-analytics>, <google-chart>, <google-map>, ...

E-Commerce Specific Items
<gold-cc-input>, <gold-phone-input>, <gold-email-input>, ...

Elements for creating animations
<neon-animation>

Items to help create a real application from a webpage
<platinum-bluetooth-device>, <platinum-sw-cache>, <platinum-push-messaging>, ...

Wrappers for other libraries / applications
<marked-element>



You may notice that the word "element" constantly appears. Google believes that you can make an element for everything. “There is an element for that” (“there is an element for this”) - sounds like a slogan in Google IO 2015 reports.

Yes, even for ajax request there is an element. Looks like that:
 <iron-ajax url="some url" handle-as="json" on-response="onResponse"></iron-ajax> 


When creating applications, we are faced with roughly the same tasks, and Google offers a set of ready-made building blocks for this. Whatever problem we face, there is an element to solve it. "There is an element for that."
The catalog of ready-made Polymer components has been created .

Polymer is not a framework, just like web components are not a framework. Polymer is a wrapper and sugar. I would compare it ideologically with jQuery. jQuery is designed to work with DOM, and Polymer is designed to work with web components.

Polymer - testability

Yes, it is testable, and a separate web-component-tester utility is created for this. Clear description.

I tried. Works (installation may have problems with Java and Selenium).

A few steps to make it work:

Source: https://habr.com/ru/post/270109/


All Articles