Top Banner
@granze Polymer is production ready. How about you? Maurizio Mangione ROME 18-19 MARCH 2016
56

Polymer is production ready, how about you?

Jan 09, 2017

Download

Software

Codemotion
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Polymer is production ready, how about you?

@granze

Polymer is production ready. How about you? Maurizio Mangione

ROME 18-19 MARCH 2016

Page 2: Polymer is production ready, how about you?

@granze

@Granze

Google Developers Expert

Milano JS Founder

Page 3: Polymer is production ready, how about you?

@granze

What is this talk about?

Page 4: Polymer is production ready, how about you?

@granze

I ♥ Polymer

Page 5: Polymer is production ready, how about you?

@granze

Web Components

Page 6: Polymer is production ready, how about you?

@granze

Custom Elements<my-component></my-component>

<x-element attribute="test"></x-element>

Page 7: Polymer is production ready, how about you?

@granze

HTML Imports<link rel="import" href="path/to/component.html">

Page 8: Polymer is production ready, how about you?

@granze

Templates<template id="template">

<div>

<h1>Web Components</h1>

<img src="http://webcomponents.org/img/logo.svg">

</div>

</template>

Page 9: Polymer is production ready, how about you?

@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: Polymer is production ready, how about you?

@granze

webcomponents-lite.js

Page 11: Polymer is production ready, how about you?

@granze

Standards

Page 12: Polymer is production ready, how about you?

@granze

“Always bet on Javascript”

Brendan Eich

Page 13: Polymer is production ready, how about you?

@granze

“Always bet onthe Web Platform”

Me

Page 14: Polymer is production ready, how about you?

@granze

Page 15: Polymer is production ready, how about you?

@granze

Let’s build an App

Page 16: Polymer is production ready, how about you?

@granze

1 Create reusable elements

● Start with the seed-element

● Use Polyserve

● Publish via Bower

Page 17: Polymer is production ready, how about you?

@granze

<seed-element>

● Element boilerplate

● Test ready

● Auto generated docs

Page 18: Polymer is production ready, how about you?

@granze

Page 19: Polymer is production ready, how about you?

@granze

Visual and non-visual elements

Page 20: Polymer is production ready, how about you?

@granze

2 Put things together

Page 21: Polymer is production ready, how about you?

@granze

How elements talk to each other

API API

<child-component><child-component>

Page 22: Polymer is production ready, how about you?

@granze

<g-tag my-attr="true">Polymer({

is: 'g-tag',

properties: {

myAttr: {

type: Boolean

}

}

});

Page 23: Polymer is production ready, how about you?

@granze

Mediator Pattern

API API

BUSINESS LOGIC

wrapper

<child-component><child-component>

Page 24: Polymer is production ready, how about you?

@granze

The wrapper

Page 25: Polymer is production ready, how about you?

@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: Polymer is production ready, how about you?

@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: Polymer is production ready, how about you?

@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: Polymer is production ready, how about you?

@granze

Should I use Mediator Pattern?

Page 29: Polymer is production ready, how about you?

@granze

Use what you like the most

● Events (fire, listen)

● Flux-like architecture

● Your own solution

Page 30: Polymer is production ready, how about you?

@granze

3 Testing

Page 31: Polymer is production ready, how about you?

@granze

Web component tester

> npm i -g web-component-tester

> wct

Page 32: Polymer is production ready, how about you?

@granze

Web component tester

Page 33: Polymer is production ready, how about you?

@granze

4 The build step

Page 34: Polymer is production ready, how about you?

@granze

Tools of the trade

● Vulcanize

● Crisper

● NPM scripts or Gulp

Page 35: Polymer is production ready, how about you?

@granze

Vulcanize> vulcanize target.html > build.html

Page 36: Polymer is production ready, how about you?

@granze

Crisper> cat index.html | crisper -h build.html -j build.js

Page 37: Polymer is production ready, how about you?

@granze

So, what I need?

● Elements

● Let them talk to each other

● Test all the things

● Build/deploy

Page 38: Polymer is production ready, how about you?

@granze

Polymer Starter Kit

Page 39: Polymer is production ready, how about you?

@granze

PSK’s Hot features

● Offline support

● Complete build chain

● Responsive app layout

Page 40: Polymer is production ready, how about you?

@granze

Yeoman> npm i -g yo

> npm install -g generator-polymer

> yo polymer

Page 41: Polymer is production ready, how about you?

@granze

Ok sold, but is not so easy...

Page 42: Polymer is production ready, how about you?

@granze

Page 43: Polymer is production ready, how about you?

@granze

You can win!One component at a time

Page 44: Polymer is production ready, how about you?

@granzeCredits: http://nocamels.com/2014/06/israeli-researchers-create-trojan-horse-of-chemotherapy

Page 45: Polymer is production ready, how about you?

@granze

I don’t want to add more stuff to my legacy app

Page 46: Polymer is production ready, how about you?

@granze

Think about jQuery plugins

Page 47: Polymer is production ready, how about you?

@granze

Useful resources

Page 48: Polymer is production ready, how about you?

@granze

Community

http://polymer-slack.herokuapp.com

Page 49: Polymer is production ready, how about you?

@granze

Polycasts

Page 50: Polymer is production ready, how about you?

@granze

Page 51: Polymer is production ready, how about you?

@granze

Awesome Polymer

Page 52: Polymer is production ready, how about you?

@granze

Should you build your appentirely with Web Components?

Page 53: Polymer is production ready, how about you?

@granze

Is up to you!

Page 54: Polymer is production ready, how about you?

@granze

Polymer is good because

● Built on standards

● Freedom of choice

● Production ready...

Page 55: Polymer is production ready, how about you?

@granze

...how about you?