Page 1
@granze
Polymer is production ready. How about you? Maurizio Mangione
ROME 18-19 MARCH 2016
Page 2
@granze
@Granze
Google Developers Expert
Milano JS Founder
Page 3
@granze
What is this talk about?
Page 4
@granze
I ♥ Polymer
Page 5
@granze
Web Components
Page 6
@granze
Custom Elements<my-component></my-component>
<x-element attribute="test"></x-element>
Page 7
@granze
HTML Imports<link rel="import" href="path/to/component.html">
Page 8
@granze
Templates<template id="template">
<div>
<h1>Web Components</h1>
<img src="http://webcomponents.org/img/logo.svg">
</div>
</template>
Page 9
@granze
Shadow DOMvar progressBar = document.createElement('div');
var shadowRoot = progressBar.attachShadow({mode:
'closed'});
var template = document.getElementById('template');
shadowRoot.appendChild(template).content.cloneNode
(true));
V1
Page 10
@granze
webcomponents-lite.js
Page 11
@granze
Standards
Page 12
@granze
“Always bet on Javascript”
Brendan Eich
Page 13
@granze
“Always bet onthe Web Platform”
Me
Page 15
@granze
Let’s build an App
Page 16
@granze
1 Create reusable elements
● Start with the seed-element
● Use Polyserve
● Publish via Bower
Page 17
@granze
<seed-element>
● Element boilerplate
● Test ready
● Auto generated docs
Page 19
@granze
Visual and non-visual elements
Page 20
@granze
2 Put things together
Page 21
@granze
How elements talk to each other
API API
<child-component><child-component>
Page 22
@granze
<g-tag my-attr="true">Polymer({
is: 'g-tag',
properties: {
myAttr: {
type: Boolean
}
}
});
Page 23
@granze
Mediator Pattern
API API
BUSINESS LOGIC
wrapper
<child-component><child-component>
Page 24
@granze
The wrapper
Page 25
@granze
<x-app><link rel="import" href="polymer/polymer.html">
<dom-module id="x-app">
<template>
<!-- add elements here -->
</template>
<script>
Polymer({ is: 'x-app' });
</script>
</dom-module>
Page 26
@granze
index.html<!DOCTYPE html>
<html lang="en">
<head>
<link rel="import" href="x-app/x-app.html">
</head>
<body>
<x-app></x-app>
</body>
</html>
Page 27
@granze
<template is="dom-bind"><body>
<template id="app" is="dom-bind">
<a href="#" on-click="sayHello">Click me!</a>
</template>
<script>
const app = document.querySelector('#app');
app.sayHello = () => { console.log('Hello') };
</script>
</body>
Page 28
@granze
Should I use Mediator Pattern?
Page 29
@granze
Use what you like the most
● Events (fire, listen)
● Flux-like architecture
● Your own solution
Page 30
@granze
3 Testing
Page 31
@granze
Web component tester
> npm i -g web-component-tester
> wct
Page 32
@granze
Web component tester
Page 33
@granze
4 The build step
Page 34
@granze
Tools of the trade
● Vulcanize
● Crisper
● NPM scripts or Gulp
Page 35
@granze
Vulcanize> vulcanize target.html > build.html
Page 36
@granze
Crisper> cat index.html | crisper -h build.html -j build.js
Page 37
@granze
So, what I need?
● Elements
● Let them talk to each other
● Test all the things
● Build/deploy
Page 38
@granze
Polymer Starter Kit
Page 39
@granze
PSK’s Hot features
● Offline support
● Complete build chain
● Responsive app layout
Page 40
@granze
Yeoman> npm i -g yo
> npm install -g generator-polymer
> yo polymer
Page 41
@granze
Ok sold, but is not so easy...
Page 43
@granze
You can win!One component at a time
Page 44
@granzeCredits: http://nocamels.com/2014/06/israeli-researchers-create-trojan-horse-of-chemotherapy
Page 45
@granze
I don’t want to add more stuff to my legacy app
Page 46
@granze
Think about jQuery plugins
Page 47
@granze
Useful resources
Page 48
@granze
Community
http://polymer-slack.herokuapp.com
Page 49
@granze
Polycasts
Page 51
@granze
Awesome Polymer
Page 52
@granze
Should you build your appentirely with Web Components?
Page 53
@granze
Is up to you!
Page 54
@granze
Polymer is good because
● Built on standards
● Freedom of choice
● Production ready...
Page 55
@granze
...how about you?