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

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
Imam Raza
 

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 (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

Александр Кашеверов - Polymer
Александр Кашеверов - PolymerАлександр Кашеверов - Polymer
Александр Кашеверов - Polymer
DataArt
 
HTML5 & Front-end overview
HTML5 & Front-end overviewHTML5 & Front-end overview
HTML5 & Front-end overview
Ashish Mukherjee
 
SW Drupal Summit: HTML5+Drupal
SW Drupal Summit: HTML5+DrupalSW Drupal Summit: HTML5+Drupal
SW Drupal Summit: HTML5+Drupal
Jen 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 (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

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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