SlideShare una empresa de Scribd logo
1 de 41
Polymer
a framework for the evolving web
What is Polymer?
• New type of library for the evolving web
o goal: support latest version of modern browsers
• Set of polyfill libraries
• Web Components are its core
• Sugaring layer
• UI Components (in progress)
Philosophy
• Embrace HTML!
o everything is a custom element
• Leverage the web platform
o gets smaller and better over time
• Minimize boilerplate code
o remove tediousness of building web apps
o feedback loop to web platform standards
• Salt to taste
o designed to be a la carte
Polymer stack
Platform ( platform.js ) ~31KB
o polyfills for Shadow DOM, Custom Elements, MDV,...
Core ( polymer.js ) ~37KB
o includes platform.js
o expresses opinionated way to these new APIs together
Polymer / UI elements
o in progress...
Web Components
Demos
Demos
Key players
• Shadow DOM
• HTML Templates
o <template>
• Custom Elements
o <element>
• HTML Imports
o <link rel="import">
<say-hello></say-hello>
Custom elements
define new HTML elements
var SayHello = document.register(
'say-hello', {prototype: proto});
var el = document.createElement(‘say-hello’);
// var el = new SayHello();
Registering an element
<template>
<style>
p { color: orange; }
</style>
<p>Hello world!</p>
</template>
Template - "inert" markup
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() {
var t = document.querySelector(‘template’);
var copy = t.content.cloneNode(true);
this.createShadowRoot().appendChild(copy);
};
document.register('say-hello', {prototype: proto});
Shadow DOM - gives encapsulation
var proto = Object.create(HTMLElement.prototype);
proto.sayHi = function() { alert('Hiii!'); };
Object.defineProperty(proto, ‘name’, {value: ‘Eric’});
document.register('say-hello', {prototype: proto});
Define a public API
Just like existing DOM elements:
var a = new Audio();
a.loop
a.muted
a.load()
Use today with platform.js
<html>
<head>
<script src="//polymer-project.org/js/platform.min.js">
</script>
</head>
<body>
<script>document.register(‘say-hello’, ...);</script>
<say-hello></say-hello>
</body>
</html>
DEMO
HTML Imports - include definitions
<html>
<head>
<script src="platform.min.js"></script>
<link rel="import" href="path/to/sayhello.html">
</head>
<body>
<say-hello></say-hello>
</body>
</html>
Polymer elements
Polymer elements are custom
elements with special sauce
Polymer: Core
http://www.polymer-project.org/polymer.min.js
Includes the polyfills
in platform.js
Polymer features
• Easier element registration
• Publishing attributes, properties, methods
• Data binding
• Automagic change watchers
• Declarative event-mappings
• Automatic node finding
• Element inheritance is a breeze
Easier element registration
<polymer-element name="say-hello">
<template>Hello world!</template>
<script>
Polymer('say-hello');
</script>
</polymer-element>
Publishing properties/methods
<polymer-element name="say-hello" attributes="name">
<template>Hello world!</template>
<script>
Polymer('say-hello', {
ready: function() {...},
sayHi: function() { alert('Hiii!'); }
name: 'Eric'
});
</script>
</polymer-element>
<say-hello name="Eric"></say-hello>
Two-way data binding
<polymer-element name="say-hello" attributes="name">
<template>
Hello {{name}}!
<template bind if="{{show}}">
<img src="profile.png">
</template>
</template>
<script>
Polymer('say-hello', {
name: 'Eric',
show: true
});
</script>
</polymer-element>
DEMO
Automagic change watchers
<polymer-element name="say-hello" attributes="name color">
<template>
Hello <span style="color:{{color}}">{{name}}!</span>
</template>
<script>
Polymer('say-hello', {
colorChanged: function() {
if (!this.color.match(/red|orange|yellow/)) {
console.log("Color wasn't hot!");
}
}
});
</script>
</polymer-element>
<say-hello color="red" name="Joe"></say-hello>
DEMO
Declarative event-mappings
<polymer-element name="say-hello" attributes="name">
<template>
<input value="{{name}}" on-keypress="doKeyPress"> Hello {{name}}!
</template>
<script>
Polymer('say-hello', {
doKeyPress: function() {
if (this.name.match(/^Larry Page$/i)) {
alert('Googler!');
}
}
});
</script>
</polymer-element> DEMO
<polymer-element name="say-hello" attributes="name">
<template>
<input type="text" id="myInput" value="{{name}}">
</template>
<script>
Polymer('say-hello', {
ready: function() {
this.$.myInput.style.color = 'red';
}
});
</script>
</polymer-element>
Automatic node finding
this.$.<id>
Styling elements
Default styles: @host at-rule
<polymer-element name="say-hello">
<template>
<style>
@host {
:scope {
display: block; background: red; padding: 5px;
transition: opacity 400ms;
}
:scope:hover { opacity: 0.5; }
}
</style>
</template>
<script>Polymer('say-hello');</script>
</polymer-element>
Styling distributed nodes
<polymer-element name="say-hello">
<template>
<style>
/* @polyfill h1 > span */
content::-webkit-distributed(h1 > span) {
color: red;
}
</style>
<content select="h1"></content>
</template>
<script>Polymer('say-hello');</script>
</polymer-element>
DEMO
<polymer-element name="say-hello" attributes="name">
<template>
Hello <span pseudo="x-myname">{{name}}!</span>
</template>
<script>Polymer('say-hello');</script>
</polymer-element>
<style>
say-hello::x-myname { color: red; }
</style>
<say-hello name="Eric"><say-hello>
DEMO
Custom pseudo elements
provide style hooks for internal elements
Advanced Concepts
Advanced features
• Element inheritance
o extending existing HTML elements
• Firing custom events
• Messaging between elements
• Reusing others' elements
o UI-less components
<polymer-element name="polymer-cool">
<script>
Polymer('polymer-cool', {
praise: 'cool',
makeCoolest: function() { this.praise = 'coolest'; }
});
</script>
</polymer-element>
<polymer-element name="polymer-cooler" extends="polymer-cool">
<template>{{praise}}</template>
<script>Polymer('polymer-cooler');</script>
</polymer-element>
DEMO
Element inheritance
extends attribute
Extending existing HTML elements
<polymer-element name="super-li" extends="li">
<template>...</template>
<script>Polymer('super-li');</script>
</polymer-element>
<ul>
<li is="super-li"></li>
<li is="super-li"></li>
...
</ul>
<polymer-element name="say-hello" attributes="name" on-click="clickHandler">
<script>
Polymer('say-hello', {
clickHandler: function() {
this.fire('said-hello', {name: this.name});
}
});
</script>
</polymer-element>
<say-hello name="Eric"></say-hello>
<script>
document.body.addEventListener('said-hello', function(e) {
console.log(e.type, 'to', e.detail.name); // "said-hello to Eric"
});
</script>
DEMO
Sending custom events
this.fire()
Just a wrapper for
new CustomEvent()
"Messaging" between elements
Pick your poison:
1.Data-binding - two-way via attributes
2.API - calling an element's public methods
3.Events - firing custom events
<polymer-element name="say-hello" attributes="name" on-click="restoreName">
<script>
Polymer('say-hello', {
restoreName: function(e, detail, sender) { this.name = 'John Doe'; }
});
</script>
</polymer-element>
<polymer-element name="my-app" attributes="name">
<template>
<input type="text" value="{{name}}">
<say-hello name="{{name}}"></say-hello>
<say-bye name="{{name}}"></say-bye>
</template>
</polymer-element>
<my-app name="Eric Bidelman"></my-app>
DEMO
Communication
using published properties
<polymer-element name="say-hello" attributes="name">
<script>
Polymer('say-hello', {
restoreName: function() {
this.name = 'John Doe';
}
});
</script>
</polymer-element>
<say-hello ="Eric Bidelman"></say-hello> <button>Restore</button>
<script>
document.querySelector('button').addEventListener('click', function(e) {
document.querySelector('say-hello').restoreName();
});
</script>
Communication: calling public API methods
<polymer-element name="say-hello" attributes="name" on-click="sayHi">
<template>...</template>
<script>
Polymer('say-hello', {
sayHi: function() {
alert('Hiiya!');
this.fire('saidhello',
{name: this.name});
}
});
</script>
</polymer-element>
Communication: fire custom events (pub/sub)
<polymer-element name="my-app">
<template>
<div on-saidhello="sayBye">
<say-hello name="Eric" on-saidhello="hiDone"></say-hello>
</div>
</template>
<script>
Polymer('my-app', {
sayBye: function() { alert('kthxbye!'); },
hiDone: function(e, detail, sender) {
alert('Said hi to ' + detail.name +
' from ' + sender.localName);
}
});
</script>
</polymer-element> DEMO
Event bubbling!
"Hiiya!"
"Said hi to Eric from say-hello"
"kthxbye!"
Reusing others' elements
<link rel="import" href="x-icon.html">
<link rel="import" href="x-menu-item.html">
<polymer-element name="my-menu">
<template>
<x-icon></x-icon>
<li is="x-menu-item">Two</li>
<li is="x-menu-item">Three</li>
</template>
<script>Polymer('my-menu');</script>
</polymer-element>
<polymer-element name="polymer-jsonp"><script>...</script></polymer-element>
<polymer-element name="my-menu" attributes="data">
<template>
<polymer-jsonp url="http://example.com/json?callback=" auto
response="{{data}}"></polymer-jsonp>
...
</template>
<script>
Polymer('my-menu', {
dataChanged: function() {...}
});
</script>
</polymer-element>
UI-less components
custom elements don't have to have UI!
CODE
polymer-project.org

Más contenido relacionado

La actualidad más candente

Web Components with Polymer (extra Polymer 2.0)
Web Components with Polymer (extra Polymer 2.0)Web Components with Polymer (extra Polymer 2.0)
Web Components with Polymer (extra Polymer 2.0)Dhyego Fernando
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkImam Raza
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Gil Fink
 
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17GreeceJS
 
Unlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerUnlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerRob Dodson
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5Jamshid Hashimi
 
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Spyros Ioakeimidis
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVAYash Mody
 
HTML5: the new frontier of the web
HTML5: the new frontier of the webHTML5: the new frontier of the web
HTML5: the new frontier of the webIvano Malavolta
 
HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examplesAlfredo Torre
 
An Introduction To HTML5
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5Robert Nyman
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developersHernan Mammana
 
Introduction to html 5
Introduction to html 5Introduction to html 5
Introduction to html 5Sayed Ahmed
 
HTML5 Essential Training
HTML5 Essential TrainingHTML5 Essential Training
HTML5 Essential TrainingKaloyan Kosev
 
Bringing HTML5 alive in SharePoint
Bringing HTML5 alive in SharePointBringing HTML5 alive in SharePoint
Bringing HTML5 alive in SharePointChad Schroeder
 

La actualidad más candente (20)

Web Components with Polymer (extra Polymer 2.0)
Web Components with Polymer (extra Polymer 2.0)Web Components with Polymer (extra Polymer 2.0)
Web Components with Polymer (extra Polymer 2.0)
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Intro to html 5
Intro to html 5Intro to html 5
Intro to html 5
 
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
 
Unlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerUnlock the next era of UI design with Polymer
Unlock the next era of UI design with Polymer
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5
 
Html5
Html5Html5
Html5
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
 
HTML5: the new frontier of the web
HTML5: the new frontier of the webHTML5: the new frontier of the web
HTML5: the new frontier of the web
 
HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examples
 
An Introduction To HTML5
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developers
 
HTML5
HTML5HTML5
HTML5
 
Introduction to html 5
Introduction to html 5Introduction to html 5
Introduction to html 5
 
HTML5 Essential Training
HTML5 Essential TrainingHTML5 Essential Training
HTML5 Essential Training
 
Bringing HTML5 alive in SharePoint
Bringing HTML5 alive in SharePointBringing HTML5 alive in SharePoint
Bringing HTML5 alive in SharePoint
 
Html 5
Html 5Html 5
Html 5
 

Destacado

El texto y la imagen publicitaria
El texto y la imagen publicitariaEl texto y la imagen publicitaria
El texto y la imagen publicitariaMary Cuenca
 
Molecular weight fundamentals
Molecular weight fundamentalsMolecular weight fundamentals
Molecular weight fundamentalsVaaliban Naan
 
Determination of molecular weight of polymers by visometry
Determination of molecular weight of polymers by visometryDetermination of molecular weight of polymers by visometry
Determination of molecular weight of polymers by visometryudhay roopavath
 
Viscosity measurement using ostwald viscometer
Viscosity measurement using ostwald viscometerViscosity measurement using ostwald viscometer
Viscosity measurement using ostwald viscometerTenison Basumatary
 
Viscosity and its determination
Viscosity and its determinationViscosity and its determination
Viscosity and its determinationUmair hanif
 

Destacado (8)

El texto y la imagen publicitaria
El texto y la imagen publicitariaEl texto y la imagen publicitaria
El texto y la imagen publicitaria
 
Osmometry report.pdf
Osmometry report.pdfOsmometry report.pdf
Osmometry report.pdf
 
Welcome Number average molecular weight.
Welcome Number average molecular weight.Welcome Number average molecular weight.
Welcome Number average molecular weight.
 
Molecular weight fundamentals
Molecular weight fundamentalsMolecular weight fundamentals
Molecular weight fundamentals
 
Determination of molecular weight of polymers by visometry
Determination of molecular weight of polymers by visometryDetermination of molecular weight of polymers by visometry
Determination of molecular weight of polymers by visometry
 
Viscometers
ViscometersViscometers
Viscometers
 
Viscosity measurement using ostwald viscometer
Viscosity measurement using ostwald viscometerViscosity measurement using ostwald viscometer
Viscosity measurement using ostwald viscometer
 
Viscosity and its determination
Viscosity and its determinationViscosity and its determination
Viscosity and its determination
 

Similar a Intro to polymer-Devfest Yaoundé 2013

Web component driven development
Web component driven developmentWeb component driven development
Web component driven developmentGil Fink
 
Александр Кашеверов - Polymer
Александр Кашеверов - PolymerАлександр Кашеверов - Polymer
Александр Кашеверов - PolymerDataArt
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the futureDA-14
 
Web components
Web componentsWeb components
Web componentsNoam Kfir
 
HTML5 & Front-end overview
HTML5 & Front-end overviewHTML5 & Front-end overview
HTML5 & Front-end overviewAshish Mukherjee
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedGil Fink
 
Polymer - Una bella historia de amor
Polymer - Una bella historia de amorPolymer - Una bella historia de amor
Polymer - Una bella historia de amorIsrael Blancas
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Meteor + Ionic Introduction
Meteor + Ionic IntroductionMeteor + Ionic Introduction
Meteor + Ionic IntroductionLearningTech
 
How to build a web application with Polymer
How to build a web application with PolymerHow to build a web application with Polymer
How to build a web application with PolymerSami Suo-Heikki
 
Rawnet Lightning Talk - Web Components
Rawnet Lightning Talk - Web ComponentsRawnet Lightning Talk - Web Components
Rawnet Lightning Talk - Web ComponentsRawnet
 
Web Components
Web ComponentsWeb Components
Web ComponentsFITC
 
Web Components v1
Web Components v1Web Components v1
Web Components v1Mike Wilcox
 
Web design and Development
Web design and DevelopmentWeb design and Development
Web design and DevelopmentShagor Ahmed
 
SW Drupal Summit: HTML5+Drupal
SW Drupal Summit: HTML5+DrupalSW Drupal Summit: HTML5+Drupal
SW Drupal Summit: HTML5+DrupalJen Simmons
 

Similar a Intro to polymer-Devfest Yaoundé 2013 (20)

Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Александр Кашеверов - Polymer
Александр Кашеверов - PolymerАлександр Кашеверов - Polymer
Александр Кашеверов - Polymer
 
Polymer
PolymerPolymer
Polymer
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the future
 
Web components
Web componentsWeb components
Web components
 
HTML5 & Front-end overview
HTML5 & Front-end overviewHTML5 & Front-end overview
HTML5 & Front-end overview
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has Arrived
 
Polymer - Una bella historia de amor
Polymer - Una bella historia de amorPolymer - Una bella historia de amor
Polymer - Una bella historia de amor
 
Web components
Web componentsWeb components
Web components
 
Meteor + Ionic Introduction
Meteor + Ionic IntroductionMeteor + Ionic Introduction
Meteor + Ionic Introduction
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
How to build a web application with Polymer
How to build a web application with PolymerHow to build a web application with Polymer
How to build a web application with Polymer
 
Rawnet Lightning Talk - Web Components
Rawnet Lightning Talk - Web ComponentsRawnet Lightning Talk - Web Components
Rawnet Lightning Talk - Web Components
 
Web Components
Web ComponentsWeb Components
Web Components
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Html5
Html5Html5
Html5
 
Fundamentals of HTML5
Fundamentals of HTML5Fundamentals of HTML5
Fundamentals of HTML5
 
HTML5 Refresher
HTML5 RefresherHTML5 Refresher
HTML5 Refresher
 
Web design and Development
Web design and DevelopmentWeb design and Development
Web design and Development
 
SW Drupal Summit: HTML5+Drupal
SW Drupal Summit: HTML5+DrupalSW Drupal Summit: HTML5+Drupal
SW Drupal Summit: HTML5+Drupal
 

Más de gdgyaounde

Html5-Devfest Yaoundé 2013
Html5-Devfest Yaoundé 2013Html5-Devfest Yaoundé 2013
Html5-Devfest Yaoundé 2013gdgyaounde
 
Android Intro-DevFest Yde 2013
Android Intro-DevFest Yde 2013Android Intro-DevFest Yde 2013
Android Intro-DevFest Yde 2013gdgyaounde
 
Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013gdgyaounde
 
Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013gdgyaounde
 
Tic et agriculture- Devfest Yde 2013
Tic et agriculture- Devfest Yde 2013Tic et agriculture- Devfest Yde 2013
Tic et agriculture- Devfest Yde 2013gdgyaounde
 
Web rtc présentation-Devfest Yde 2013
Web rtc présentation-Devfest Yde 2013Web rtc présentation-Devfest Yde 2013
Web rtc présentation-Devfest Yde 2013gdgyaounde
 
Présentation Devfest Yde 2013- Devfest Yde 2013
Présentation Devfest Yde 2013- Devfest Yde 2013Présentation Devfest Yde 2013- Devfest Yde 2013
Présentation Devfest Yde 2013- Devfest Yde 2013gdgyaounde
 
Communication android
Communication androidCommunication android
Communication androidgdgyaounde
 
App engineday 1-Devfest Yde 2013
App engineday 1-Devfest Yde 2013App engineday 1-Devfest Yde 2013
App engineday 1-Devfest Yde 2013gdgyaounde
 
Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013
Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013
Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013gdgyaounde
 

Más de gdgyaounde (10)

Html5-Devfest Yaoundé 2013
Html5-Devfest Yaoundé 2013Html5-Devfest Yaoundé 2013
Html5-Devfest Yaoundé 2013
 
Android Intro-DevFest Yde 2013
Android Intro-DevFest Yde 2013Android Intro-DevFest Yde 2013
Android Intro-DevFest Yde 2013
 
Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013
 
Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013Ict4AgriDev-Devfest Yde 2013
Ict4AgriDev-Devfest Yde 2013
 
Tic et agriculture- Devfest Yde 2013
Tic et agriculture- Devfest Yde 2013Tic et agriculture- Devfest Yde 2013
Tic et agriculture- Devfest Yde 2013
 
Web rtc présentation-Devfest Yde 2013
Web rtc présentation-Devfest Yde 2013Web rtc présentation-Devfest Yde 2013
Web rtc présentation-Devfest Yde 2013
 
Présentation Devfest Yde 2013- Devfest Yde 2013
Présentation Devfest Yde 2013- Devfest Yde 2013Présentation Devfest Yde 2013- Devfest Yde 2013
Présentation Devfest Yde 2013- Devfest Yde 2013
 
Communication android
Communication androidCommunication android
Communication android
 
App engineday 1-Devfest Yde 2013
App engineday 1-Devfest Yde 2013App engineday 1-Devfest Yde 2013
App engineday 1-Devfest Yde 2013
 
Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013
Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013
Apport de la psychologie dans les sciences informatiques -Devfest Yde 2013
 

Último

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Último (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Intro to polymer-Devfest Yaoundé 2013

  • 1. Polymer a framework for the evolving web
  • 2. What is Polymer? • New type of library for the evolving web o goal: support latest version of modern browsers • Set of polyfill libraries • Web Components are its core • Sugaring layer • UI Components (in progress)
  • 3.
  • 4. Philosophy • Embrace HTML! o everything is a custom element • Leverage the web platform o gets smaller and better over time • Minimize boilerplate code o remove tediousness of building web apps o feedback loop to web platform standards • Salt to taste o designed to be a la carte
  • 5. Polymer stack Platform ( platform.js ) ~31KB o polyfills for Shadow DOM, Custom Elements, MDV,... Core ( polymer.js ) ~37KB o includes platform.js o expresses opinionated way to these new APIs together Polymer / UI elements o in progress...
  • 8. Key players • Shadow DOM • HTML Templates o <template> • Custom Elements o <element> • HTML Imports o <link rel="import">
  • 10. var SayHello = document.register( 'say-hello', {prototype: proto}); var el = document.createElement(‘say-hello’); // var el = new SayHello(); Registering an element
  • 11. <template> <style> p { color: orange; } </style> <p>Hello world!</p> </template> Template - "inert" markup
  • 12. var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { var t = document.querySelector(‘template’); var copy = t.content.cloneNode(true); this.createShadowRoot().appendChild(copy); }; document.register('say-hello', {prototype: proto}); Shadow DOM - gives encapsulation
  • 13. var proto = Object.create(HTMLElement.prototype); proto.sayHi = function() { alert('Hiii!'); }; Object.defineProperty(proto, ‘name’, {value: ‘Eric’}); document.register('say-hello', {prototype: proto}); Define a public API Just like existing DOM elements: var a = new Audio(); a.loop a.muted a.load()
  • 14. Use today with platform.js <html> <head> <script src="//polymer-project.org/js/platform.min.js"> </script> </head> <body> <script>document.register(‘say-hello’, ...);</script> <say-hello></say-hello> </body> </html> DEMO
  • 15. HTML Imports - include definitions <html> <head> <script src="platform.min.js"></script> <link rel="import" href="path/to/sayhello.html"> </head> <body> <say-hello></say-hello> </body> </html>
  • 17. Polymer elements are custom elements with special sauce
  • 19. Polymer features • Easier element registration • Publishing attributes, properties, methods • Data binding • Automagic change watchers • Declarative event-mappings • Automatic node finding • Element inheritance is a breeze
  • 20. Easier element registration <polymer-element name="say-hello"> <template>Hello world!</template> <script> Polymer('say-hello'); </script> </polymer-element>
  • 21. Publishing properties/methods <polymer-element name="say-hello" attributes="name"> <template>Hello world!</template> <script> Polymer('say-hello', { ready: function() {...}, sayHi: function() { alert('Hiii!'); } name: 'Eric' }); </script> </polymer-element> <say-hello name="Eric"></say-hello>
  • 22. Two-way data binding <polymer-element name="say-hello" attributes="name"> <template> Hello {{name}}! <template bind if="{{show}}"> <img src="profile.png"> </template> </template> <script> Polymer('say-hello', { name: 'Eric', show: true }); </script> </polymer-element> DEMO
  • 23. Automagic change watchers <polymer-element name="say-hello" attributes="name color"> <template> Hello <span style="color:{{color}}">{{name}}!</span> </template> <script> Polymer('say-hello', { colorChanged: function() { if (!this.color.match(/red|orange|yellow/)) { console.log("Color wasn't hot!"); } } }); </script> </polymer-element> <say-hello color="red" name="Joe"></say-hello> DEMO
  • 24. Declarative event-mappings <polymer-element name="say-hello" attributes="name"> <template> <input value="{{name}}" on-keypress="doKeyPress"> Hello {{name}}! </template> <script> Polymer('say-hello', { doKeyPress: function() { if (this.name.match(/^Larry Page$/i)) { alert('Googler!'); } } }); </script> </polymer-element> DEMO
  • 25. <polymer-element name="say-hello" attributes="name"> <template> <input type="text" id="myInput" value="{{name}}"> </template> <script> Polymer('say-hello', { ready: function() { this.$.myInput.style.color = 'red'; } }); </script> </polymer-element> Automatic node finding this.$.<id>
  • 27. Default styles: @host at-rule <polymer-element name="say-hello"> <template> <style> @host { :scope { display: block; background: red; padding: 5px; transition: opacity 400ms; } :scope:hover { opacity: 0.5; } } </style> </template> <script>Polymer('say-hello');</script> </polymer-element>
  • 28. Styling distributed nodes <polymer-element name="say-hello"> <template> <style> /* @polyfill h1 > span */ content::-webkit-distributed(h1 > span) { color: red; } </style> <content select="h1"></content> </template> <script>Polymer('say-hello');</script> </polymer-element> DEMO
  • 29. <polymer-element name="say-hello" attributes="name"> <template> Hello <span pseudo="x-myname">{{name}}!</span> </template> <script>Polymer('say-hello');</script> </polymer-element> <style> say-hello::x-myname { color: red; } </style> <say-hello name="Eric"><say-hello> DEMO Custom pseudo elements provide style hooks for internal elements
  • 31. Advanced features • Element inheritance o extending existing HTML elements • Firing custom events • Messaging between elements • Reusing others' elements o UI-less components
  • 32. <polymer-element name="polymer-cool"> <script> Polymer('polymer-cool', { praise: 'cool', makeCoolest: function() { this.praise = 'coolest'; } }); </script> </polymer-element> <polymer-element name="polymer-cooler" extends="polymer-cool"> <template>{{praise}}</template> <script>Polymer('polymer-cooler');</script> </polymer-element> DEMO Element inheritance extends attribute
  • 33. Extending existing HTML elements <polymer-element name="super-li" extends="li"> <template>...</template> <script>Polymer('super-li');</script> </polymer-element> <ul> <li is="super-li"></li> <li is="super-li"></li> ... </ul>
  • 34. <polymer-element name="say-hello" attributes="name" on-click="clickHandler"> <script> Polymer('say-hello', { clickHandler: function() { this.fire('said-hello', {name: this.name}); } }); </script> </polymer-element> <say-hello name="Eric"></say-hello> <script> document.body.addEventListener('said-hello', function(e) { console.log(e.type, 'to', e.detail.name); // "said-hello to Eric" }); </script> DEMO Sending custom events this.fire() Just a wrapper for new CustomEvent()
  • 35. "Messaging" between elements Pick your poison: 1.Data-binding - two-way via attributes 2.API - calling an element's public methods 3.Events - firing custom events
  • 36. <polymer-element name="say-hello" attributes="name" on-click="restoreName"> <script> Polymer('say-hello', { restoreName: function(e, detail, sender) { this.name = 'John Doe'; } }); </script> </polymer-element> <polymer-element name="my-app" attributes="name"> <template> <input type="text" value="{{name}}"> <say-hello name="{{name}}"></say-hello> <say-bye name="{{name}}"></say-bye> </template> </polymer-element> <my-app name="Eric Bidelman"></my-app> DEMO Communication using published properties
  • 37. <polymer-element name="say-hello" attributes="name"> <script> Polymer('say-hello', { restoreName: function() { this.name = 'John Doe'; } }); </script> </polymer-element> <say-hello ="Eric Bidelman"></say-hello> <button>Restore</button> <script> document.querySelector('button').addEventListener('click', function(e) { document.querySelector('say-hello').restoreName(); }); </script> Communication: calling public API methods
  • 38. <polymer-element name="say-hello" attributes="name" on-click="sayHi"> <template>...</template> <script> Polymer('say-hello', { sayHi: function() { alert('Hiiya!'); this.fire('saidhello', {name: this.name}); } }); </script> </polymer-element> Communication: fire custom events (pub/sub) <polymer-element name="my-app"> <template> <div on-saidhello="sayBye"> <say-hello name="Eric" on-saidhello="hiDone"></say-hello> </div> </template> <script> Polymer('my-app', { sayBye: function() { alert('kthxbye!'); }, hiDone: function(e, detail, sender) { alert('Said hi to ' + detail.name + ' from ' + sender.localName); } }); </script> </polymer-element> DEMO Event bubbling! "Hiiya!" "Said hi to Eric from say-hello" "kthxbye!"
  • 39. Reusing others' elements <link rel="import" href="x-icon.html"> <link rel="import" href="x-menu-item.html"> <polymer-element name="my-menu"> <template> <x-icon></x-icon> <li is="x-menu-item">Two</li> <li is="x-menu-item">Three</li> </template> <script>Polymer('my-menu');</script> </polymer-element>
  • 40. <polymer-element name="polymer-jsonp"><script>...</script></polymer-element> <polymer-element name="my-menu" attributes="data"> <template> <polymer-jsonp url="http://example.com/json?callback=" auto response="{{data}}"></polymer-jsonp> ... </template> <script> Polymer('my-menu', { dataChanged: function() {...} }); </script> </polymer-element> UI-less components custom elements don't have to have UI! CODE

Notas del editor

  1. Fetch nodes in the Shadow DOM by id