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
320
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
290
Shared web-components with StencilJS
felipesousa
0
400
Progressive Web Apps Done Right
felipesousa
1
560
Criando aplicações componentizadas com Polymer - C4P CEJS 2017
felipesousa
1
230
Criando Aplicações Componentizadas com Polymer
felipesousa
0
130
Uma introdução a Angular 2
felipesousa
2
370
Other Decks in Programming
See All in Programming
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
260
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
710
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
Security_for_introducing_eBPF
kentatada
0
110
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
350
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
MCP with Cloudflare Workers
yusukebe
2
220
testcontainers のススメ
sgash708
1
120
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Designing for humans not robots
tammielis
250
25k
Rails Girls Zürich Keynote
gr2m
94
13k
What's in a price? How to price your products and services
michaelherold
243
12k
Scaling GitHub
holman
458
140k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
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