On Github thedeeno / web-component-presentation
Created by Dane O'Connor / @thedeeno
Understand the tech driving a more composable web
↓
Refactor a well-written traditional component
What's in the way?
↓
are a suite of standards
that increase our application's
The WC Standards + Declarative Sugar + Data-Binding
An opinionated way to create web components
and also Polyfills for browser support
include and reuse HTML documents in other HTML documents.
<link rel="import" href="path/to/resource.html">
var link = document.createElement('link'); link.rel = 'import'; link.href = 'path/to/resource.html' link.onload = function(e) {...}; link.onerror = function(e) {...}; document.head.appendChild(link); // you can work with the imported document var content = document.querySelector('link[rel="import"]').import;
define and register new DOM elements
document.registerElement('x-foo');
var myProto = Object.create(HTMLElement.prototype); myProto.awesome = function() { alert('yeah!') }; document.registerElement('x-foo', { prototype: myProto });
<x-foo></x-foo>
var xFoo = document.createElement('x-foo');
var xFoo = new XFoo(); document.body.appendChild(xFoo);
Inert HTML
<template id="mytemplate"> <div>my content</div> </template>
// clone and append the template var t = document.querySelector('mytemplate'); var clone = document.importNode(t, true); document.body.appendChild(clone);
<template id="mytemplate"> <div>my content</div> </template>
No more hacks!
Create and layout isolated DOM trees
<style>my-foo { background: red; }</style> <my-foo> <my-bar></my-bar> </my-foo>
var host = document.querySelector('#my-bar'); var root = host.createShadowRoot(); root.innerHTML = [ '<style>my-foo { background: red; }</style>' '<my-foo></my-foo>' ].join('\n');
<style>my-foo { background: red; }</style> <my-foo><!-- red --> <my-bar> $shadowRoot$ <style>my-foo { background: blue; }</style> <my-foo></my-foo><!-- blue --> </my-bar> </my-foo>
An opinionated way to do everything we just did
<link rel="import" href="polymer.html"> <polymer-element name="rapidsynapse-dial"> <template> <!-- content --> </template> <script type="text/javascript"> Polymer({ <!-- prototype --> }); </script> </polymer-element>
<polymer-element name="rapidsynapse-dial"> <template> <div on-click="{{ increment }}">{{ formattedMessage }}</div> </template> <script type="text/javascript"> Polymer({ // read-write (bindable) publish: { 'message': 'hello world' }, // read-only (bindable) computed: { 'formattedMessage': 'format(message)' }, // private count: 0, // methods formatMessage: function(message) { return 'foo bar' + this.count; }, increment: function() { this.count = this.count + 1; } }); </script> </polymer-element>
debug issues
tooling (like testing)
browser support
performance
Created by Dane O'Connor / @thedeeno
Contact: dane@rapidsynapse.com