Web components
-
Upload
matjaz-lipus -
Category
Software
-
view
121 -
download
1
Transcript of Web components
WEB COMPONENTSFUTURE OF WEB DEV
/ Matjaž Lipuš @MatjazL
SPA FRAMEWORKSrouter (state, url)componentstemplatinghelpers (http, url)dependency injectionsimple testing
ES6 - ES 2015official standard since last week ;)class syntax, arrow functions, maps, sets, promises,generatorsStill JavaScript (prototypal inheritance)
ES6 PROMISEnew Promise(function(resolve, reject) { async(function(error, response) { if (error) { reject(error); } else { resolve(response); } })});
Promise.all([])Promise.resolve()Promise.reject()
FETCH()bower install fetch
fetch('/users') .then(function(response) { return response.json(); }).then(function(json) { console.log('parsed json', json); }).catch(function(ex) { console.error('parsing failed', ex); })
fetch('/users', { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Bart', login: 'user' })})
ES7 DECORATORS@inject(Users)class List { constructor(Users) { this.Users = Users; } fetchUser(id) { return this.Users.fetch(id); }}
class Person { firstName = 'John'; lastName = 'Doe';
@computedFrom('firstName', 'lastName') get fullName() { return ̀${this.firstName} ${this.lastName}̀; }}
WEB COMPONENTS<hello-there name="everybody"></hello-there>
Abstraction and encapsulation
TemplatesHTML importsShadow DOMCustom elements
WEB COMPONENTS TODAYChrome's "built-in" components
dd/mm/yyyy --:--
1:10
Can I use?
<HELLO-THERE><hello-there name="everybody"></hello-there>
<template id="hello-there-tpl"> <style> p { color: orange; } </style> <p>Hello <span></span>!</p></template>
Hello everybody!
<HELLO-THERE> 2/2var HelloThere = document.registerElement('hello-there', { prototype: Object.create(HTMLElement.prototype, { createdCallback: { value: function() { this.name = this.getAttribute('name') || 'world'; var tmpl = document.querySelector('#hello-there-tpl'); var clone = document.importNode(tmpl.content, true); clone.querySelector('span').textContent = this.name; this.createShadowRoot().appendChild(clone); } }, alert: { value: function() { alert(this.name); } } })
PRESENT
polyfillssimplified API for web components
Polymer project
X-TagComponents kitchen
FUTUREAngular 2, Aurelia, Ember 2built on web components conceptsrouter, components, templates, DI, component's lifecycle
Aurelia Angular 2
Object.observe() zone.js
two way binding immutable data O(1)
convention overconfiguration
decorators
attr.bind, click.trigger templates using *, () & []
MOBILEweb viewAppcelerator, cordova + ionic (2)
(iOS) (all platforms)
React nativeNativeScript
LETS START!git clone -b step-1 \ https://github.com/matjaz/webcomponents-workshop.git
cd webcomponents-workshopcd aurelianpm installnpm install -g gulp jspmjspm install -y
gulp watch
ADDING POLYMER COMPONENTSbower install google-mapbower install pazguille/github-cardgit checkout step-6
Frameworks co-existanceCode re-use
THANK YOU!github.com/matjaz/webcomponents-workshop
/ Matjaž Lipuš @MatjazL