Slide 1

Slide 1 text

Criando aplicações componentizadas com Polymer #cejs17

Slide 2

Slide 2 text

Felipe Sousa Front End Developer GDG Fortaleza

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Aplicação

Slide 7

Slide 7 text

O que é o Polymer?

Slide 8

Slide 8 text

Polymer is a JavaScript library that helps you create custom reusable HTML elements, and use them to build performant, maintainable apps.

Slide 9

Slide 9 text

O que de ‘novo’ ele traz?

Slide 10

Slide 10 text

Our mission is to make life better for users and developers, by helping developers unlock the web platform’s full potential and by spurring the web platform to evolve and improve.

Slide 11

Slide 11 text

#USETHEPLATFORM

Slide 12

Slide 12 text

Web Components

Slide 13

Slide 13 text

Shadow-dom Method of establishing and maintaining functional boundaries between DOM subtrees and how these subtrees interact with each other within a document tree.

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Isolated DOM Scoped CSS Simplifies CSS Productivity

Slide 16

Slide 16 text

const header = document.createElement('header'); const shadowRoot = header.attachShadow({mode: 'open'}); shadowRoot.innerHTML = '

Hello Shadow DOM

';

Slide 17

Slide 17 text

Custom Elements Method for create and use new types of DOM elements in a document.

Slide 18

Slide 18 text

Create Scope Atributes Life-cycles Callbacks

Slide 19

Slide 19 text

Slide 20

Slide 20 text

class FlagIcon extends HTMLElement { constructor() { super(); this._countryCode = null; } static get observedAttributes() { return ["country"]; } attributeChangedCallback(name, oldValue, newValue) { this._countryCode = newValue; this._updateRendering(); } get country() { return this._countryCode; } set country(v) { this.setAttribute("country", v); } _updateRendering() { /* update the flag icon */ } }

Slide 21

Slide 21 text

customElements.define("flag-icon", FlagIcon);

Slide 22

Slide 22 text

extends HTMLElement {

Slide 23

Slide 23 text

class PlasticButton extends HTMLButtonElement { constructor() { super(); this.addEventListener("click", () => { // do something }); } }

Slide 24

Slide 24 text

customElements.define("plastic-button", PlasticButton, { extends: "button" });

Slide 25

Slide 25 text

Click Me!

Slide 26

Slide 26 text

Imports Include and reuse HTML documents in other HTML documents.

Slide 27

Slide 27 text

Slide 28

Slide 28 text

Slide 29

Slide 29 text

Templates Method for declaring inert DOM subtrees in HTML and manipulating them to instantiate document fragments with identical contents

Slide 30

Slide 30 text

Slide 31

Slide 31 text

Cool, but…

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Custom Elements v1 Shadow DOM v1 ES6 2 1

Slide 34

Slide 34 text

:host { … }

Hello! I’m a personal component!

Polymer({ is: “my-personal-component” });

Slide 35

Slide 35 text

:host { … }

Hello! I’m a personal component!

Polymer({ is: “my-personal-component” }); Imports

Slide 36

Slide 36 text

:host { … }

Hello! I’m a personal component!

Polymer({ is: “my-personal-component” }); Custom Elements

Slide 37

Slide 37 text

:host { … }

Hello! I’m a personal component!

Polymer({ is: “my-personal-component” }); Templates

Slide 38

Slide 38 text

:host { … }

Hello! I’m a personal component!

Polymer({ is: “my-personal-component” }); Component!

Slide 39

Slide 39 text

:host { … }

Hello! I’m a component!

Component! - Polymer 2.0 class DomElement extends Polymer.Element { static get is() { return “my-personal-component”; } } customElements.define(DomElement.is, DomElement);

Slide 40

Slide 40 text

Everything is a component!

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Widgets! Web-components pode ser a solução perfeita para widgets.

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Aplicações?

Slide 47

Slide 47 text

• UI • Properties, variables • Binds • Events/Listeners • Routes • Requests • Performance • Accessibility • Tests

Slide 48

Slide 48 text

Progressive Web Apps?! • Offline App • Instalable web app • …

Slide 49

Slide 49 text

UI Definition

Slide 50

Slide 50 text

HTML e CSS

Slide 51

Slide 51 text

Document Title window.Polymer = { dom: 'shadow' } polyfill

Slide 52

Slide 52 text

:host { /*your css here*/ } Polymer({ is: "my-component" });

Slide 53

Slide 53 text

Material Design Concept

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Paper Elements

Slide 59

Slide 59 text

ITEM ONE ITEM TWO ITEM THREE

Slide 60

Slide 60 text

App Layout

Slide 61

Slide 61 text

Header Toolbar Icons

Slide 62

Slide 62 text

Drawer Menu

Slide 63

Slide 63 text

Properties, Binds and Methods

Slide 64

Slide 64 text

:host { /*your css here*/ } Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } });

Slide 65

Slide 65 text

:host { /*your css here*/ }

[[property_name]]

Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } });

Slide 66

Slide 66 text

:host { /*your css here*/ }

{{property_name}}

Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } });

Slide 67

Slide 67 text

:host { /*your css here*/ }

{{property_name}}

Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } });

Slide 68

Slide 68 text

:host { /*your css here*/ } Click here Polymer({ is: "my-component", my_method: function () { // do something } });

Slide 69

Slide 69 text

Life-cycle Events

Slide 70

Slide 70 text

- created - ready - attached - detached - attributeChanged

Slide 71

Slide 71 text

Data flow, Custom Events and Listeners.

Slide 72

Slide 72 text

events properties

Slide 73

Slide 73 text

:host { display: block; } Polymer({ is: "my-component", properties: { name_property: { type: String, value: "CEJS" } } });

Slide 74

Slide 74 text

:host { display: block; }

[[name]]

// “CEJS” Polymer({ is: "my-second-component", properties: { name: { type: String, value: "" } } });

Slide 75

Slide 75 text

this.fire("custom_event", { // content event })

Slide 76

Slide 76 text

:host { display: block; } click here Polymer({ is: "my-component", my_method: function () { this.fire("custom_event", { // your data here }) } });

Slide 77

Slide 77 text

:host { display: block; } Polymer({ is: "my-component", listeners: { "custom_event": "listen_custom_event" }, listen_custom_event: function (e) { console.log(e.detail); // contain detail os method. } });

Slide 78

Slide 78 text

Route

Slide 79

Slide 79 text

/home /about

Slide 80

Slide 80 text

Slide 81

Slide 81 text

1. Captura do estado/url

Slide 82

Slide 82 text

Slide 83

Slide 83 text

URL BAR YOUR APP

Slide 84

Slide 84 text

http://url.com/#/home

Slide 85

Slide 85 text

Slide 86

Slide 86 text

App location Response Padrão da rota Dados da Rota Dados da Sub-rota

Slide 87

Slide 87 text

/home/list {{_data}} = “home” {{_tail}} = “list”

Slide 88

Slide 88 text

/home/list/all {{_data}} = “home” {{_tail}} = “/list/all

Slide 89

Slide 89 text

2. Show/hide Component

Slide 90

Slide 90 text

Slide 91

Slide 91 text

Drawer Menu pages content

Slide 92

Slide 92 text

Slide 93

Slide 93 text

Slide 94

Slide 94 text

Slide 95

Slide 95 text

Slide 96

Slide 96 text

Slide 97

Slide 97 text

<404—app name="404">404-app>

Slide 98

Slide 98 text

Request

Slide 99

Slide 99 text

R.E.Q.U.E.S.T via HTML!

Slide 100

Slide 100 text

Slide 101

Slide 101 text

Slide 102

Slide 102 text

[[planet.name]]

[[planet.description]]

Slide 103

Slide 103 text

Utils

Slide 104

Slide 104 text

[[alias.name]]

[[alias.age]]

Slide 105

Slide 105 text

// your conditional true here

Slide 106

Slide 106 text

Example

Slide 107

Slide 107 text

> polymer-cli

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

webcomponents.org

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

speakerdeck.com/felipesousa

Slide 112

Slide 112 text

github.com/felipesousa twitter.com/felipz_sousa

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

THANK`S! #usetheplatform