Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Criando aplicações componentizadas com Polymer
Search
Felipe Sousa
May 16, 2017
Programming
0
290
Criando aplicações componentizadas com Polymer
Slides da palestra completa que aconteceu no CEJS 2017 em Fortaleza, no dia 13 de Maio de 2017.
Felipe Sousa
May 16, 2017
Tweet
Share
More Decks by Felipe Sousa
See All by Felipe Sousa
DevFest Santiago 2019 - Progressive Web Apps Done Right
felipesousa
0
280
Shared web-components with StencilJS
felipesousa
0
320
Progressive Web Apps Done Right
felipesousa
1
530
Criando aplicações componentizadas com Polymer - C4P CEJS 2017
felipesousa
1
190
Criando Aplicações Componentizadas com Polymer
felipesousa
0
130
Uma introdução a Angular 2
felipesousa
2
340
Other Decks in Programming
See All in Programming
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
230
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
490
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.4k
VS Code をプロダクトにどう取り込むか
onomax
1
360
Fragment Composition of GraphQL
quramy
7
1k
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
23
15k
1BRC--Nerd Sniping the Java Community
gunnarmorling
0
340
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
1
180
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
800
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
340
Netty Chicago Java User Group 2024-04-17
sullis
0
180
Hanami and htmx
bkuhlmann
0
210
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
Embracing the Ebb and Flow
colly
80
4.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
274
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
7
1k
Designing for Performance
lara
601
67k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
A designer walks into a library…
pauljervisheath
200
23k
Into the Great Unknown - MozCon
thekraken
10
990
Unsuck your backbone
ammeep
663
57k
The Art of Programming - Codeland 2020
erikaheidi
42
12k
Optimising Largest Contentful Paint
csswizardry
8
2.4k
Transcript
Criando aplicações componentizadas com Polymer #cejs17
Felipe Sousa Front End Developer GDG Fortaleza
None
None
None
Aplicação
O que é o Polymer?
Polymer is a JavaScript library that helps you create custom
reusable HTML elements, and use them to build performant, maintainable apps.
O que de ‘novo’ ele traz?
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.
#USETHEPLATFORM
Web Components
Shadow-dom Method of establishing and maintaining functional boundaries between DOM
subtrees and how these subtrees interact with each other within a document tree.
None
Isolated DOM Scoped CSS Simplifies CSS Productivity
const header = document.createElement('header'); const shadowRoot = header.attachShadow({mode: 'open'}); shadowRoot.innerHTML
= '<h1>Hello Shadow DOM</h1>';
Custom Elements Method for create and use new types of
DOM elements in a document.
Create Scope Atributes Life-cycles Callbacks
<flag-icon country=“br”> </flag-icon>
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 */ } }
customElements.define("flag-icon", FlagIcon);
extends HTMLElement {
class PlasticButton extends HTMLButtonElement { constructor() { super(); this.addEventListener("click", ()
=> { // do something }); } }
customElements.define("plastic-button", PlasticButton, { extends: "button" });
<button is="plastic-button">Click Me!</button>
Imports Include and reuse HTML documents in other HTML documents.
<?php require("file.php"); ?>
<link rel=“import” href=“file.html”>
Templates Method for declaring inert DOM subtrees in HTML and
manipulating them to instantiate document fragments with identical contents
<template> <!--your content here--> </template>
Cool, but…
None
Custom Elements v1 Shadow DOM v1 ES6 2 1
<link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …
} </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module>
<link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …
} </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Imports
<link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …
} </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Custom Elements
<link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …
} </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Templates
<link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …
} </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Component!
<link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …
} </style> <h1> Hello! I’m a component! </h1> </template> <script> </script> </dom-module> Component! - Polymer 2.0 class DomElement extends Polymer.Element { static get is() { return “my-personal-component”; } } customElements.define(DomElement.is, DomElement);
Everything is a component!
None
Widgets! Web-components pode ser a solução perfeita para widgets.
None
<link rel="import" href=“components/google-map/google-map.html”> <google-map latitude="37.790" longitude="-122.390"></google-map>
None
Aplicações?
• UI • Properties, variables • Binds • Events/Listeners •
Routes • Requests • Performance • Accessibility • Tests
Progressive Web Apps?! • Offline App • Instalable web app
• …
UI Definition
HTML e CSS
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,
minimum-scale=1, initial-scale=1, user-scalable=yes"> <title>Document Title</title> <meta name="description" content="space description"> <link rel="manifest" href="/manifest.json"> <script> window.Polymer = { dom: 'shadow' } </script> <script src="/bower_components/webcomponentsjs/webcomponents.js"></script> <link rel="import" href="my-app.html"> </head> <body> <my-app></my-app> </body> </html> polyfill
<link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your
css here*/ } </style> <!-- Your content here --> </template> <script> Polymer({ is: "my-component" }); </script> </dom-module>
Material Design Concept
None
None
None
None
Paper Elements
<paper-tabs selected="0"> <paper-tab>ITEM ONE</paper-tab> <paper-tab>ITEM TWO</paper-tab> <paper-tab>ITEM THREE</paper-tab> </paper-tabs>
App Layout
Header Toolbar Icons
Drawer Menu
Properties, Binds and Methods
<link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your
css here*/ } </style> <!-- Your content here --> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
<link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your
css here*/ } </style> <h1>[[property_name]]</h1> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
<link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your
css here*/ } </style> <h1>{{property_name}}</h1> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
<link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your
css here*/ } </style> <h1>{{property_name}}</h1> <input type=“text” value=“{{property_name::input}}”> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
<link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your
css here*/ } </style> <button on-click=“my_method”>Click here</button> </template> <script> Polymer({ is: "my-component", my_method: function () { // do something } }); </script> </dom-module>
Life-cycle Events
- created - ready - attached - detached - attributeChanged
Data flow, Custom Events and Listeners.
<my-element> events properties
<link rel="import" href="/polymer/polymer.html"> <link rel="import" href="./my-second-component.html"> <dom-module id="my-component"> <template> <style>
:host { display: block; } </style> <my-second-component name="name_property"> </my-second-component> </template> <script> Polymer({ is: "my-component", properties: { name_property: { type: String, value: "CEJS" } } }); </script> </dom-module>
<link rel="import" href="/polymer/polymer.html"> <dom-module id=“my-second-component”> <template> <style> :host { display:
block; } </style> <p> [[name]] </p> // “CEJS” </template> <script> Polymer({ is: "my-second-component", properties: { name: { type: String, value: "" } } }); </script> </dom-module>
this.fire("custom_event", { // content event })
<link rel="import" href="/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { display:
block; } </style> <button on-click=“my_method”>click here</button> </template> <script> Polymer({ is: "my-component", my_method: function () { this.fire("custom_event", { // your data here }) } }); </script> </dom-module>
<link rel="import" href="/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { display:
block; } </style> <!-- your content here --> </template> <script> Polymer({ is: "my-component", listeners: { "custom_event": "listen_custom_event" }, listen_custom_event: function (e) { console.log(e.detail); // contain detail os method. } }); </script> </dom-module>
Route
/home /about
<app-route>
1. Captura do estado/url
<app-location>
URL BAR YOUR APP
http://url.com/#/home <app-location route="{{route}}" use-hash-as-path> </app-location>
<app-route>
App location Response Padrão da rota Dados da Rota Dados
da Sub-rota <app-route route="{{route}}" pattern="/:page" data="{{_data}}" tail="{{_tail}}"> </app-route>
/home/list {{_data}} = “home” {{_tail}} = “list”
/home/list/all {{_data}} = “home” {{_tail}} = “/list/all
2. Show/hide Component
<iron-pages>
Drawer Menu pages content
<iron-pages> <home-app></home-app> <curiosities-app></curiosities-app> <favorites-app></favorites-app> <about-app></about-app> </iron-pages>
<iron-pages selected="{{_data.page}}"> <home-app></home-app> <curiosities-app></curiosities-app> <favorites-app></favorites-app> <about-app></about-app> </iron-pages>
<iron-pages selected="{{_data.page}}" attr-for-selected="name"> <home-app></home-app> <curiosities-app></curiosities-app> <favorites-app></favorites-app> <about-app></about-app> </iron-pages>
<iron-pages selected="{{_data.page}}" attr-for-selected="name"> <home-app name="home"></home-app> <curiosities-app name="curiosities"></curiosities-app> <favorites-app name="favorites"></favorites-app> <about-app
name="about"></about-app> </iron-pages>
<iron-pages selected="{{_data.page}}" attr-for-selected="name"> <home-app name="home" route="_tail"></home-app> <curiosities-app name="curiosities" route="_tail"></curiosities-app> <favorites-app
name="favorites" route="_tail"></favorites-app> <about-app name="about" route="_tail"></about-app> </iron-pages>
<iron-pages selected="{{_data.page}}" attr-for-selected="name" selected- attribute="visible" fallback-selection="404"> <home-app name="home" route="_tail"></home-app> <curiosities-app
name="curiosities" route="_tail"></curiosities-app> <favorites-app name="favorites" route="_tail"></favorites-app> <about-app name="about" route=“_tail"></about-app> <404—app name="404"></404-app> </iron-pages>
Request
R.E.Q.U.E.S.T via HTML!
<iron-ajax>
<iron-ajax id="requestRepos" url="your.api.com/planets" params='{"type":"all"}' handle-as="json" on-response="handleResponse" last-response="{{dataResponse}}"> </iron-ajax>
<template is="dom-repeat" items="dataResponse" as="planet"> <h1>[[planet.name]]</h1> <p>[[planet.description]]</p> </template>
Utils
<template is=“dom-repeat” items=“{{yourdata}} as=“alias” > <p> [[alias.name]] </p> <span> [[alias.age]]
</span> </template>
<template is=“dom-if” if=“{{yourCondition}}> // your conditional true here </template>
Example
> polymer-cli
None
webcomponents.org
None
speakerdeck.com/felipesousa
github.com/felipesousa twitter.com/felipz_sousa
None
THANK`S! #usetheplatform