Let's talk about all the good things and the bad things that may be...
(...about web components)
Imports received the most controversy when in December 2014 Mozilla declared their intention NOT to implement HTML imports -- at least until ES6 modules have received significant implementations.
Mozilla will not ship an implementation of HTML Imports. We expect that once JavaScript modules — a feature derived from JavaScript libraries written by the developer community — is shipped, the way we look at this problem will have changed...
...We have also learned from Gaia and others, that lack of HTML Imports is not a problem as the functionality can easily be provided for with a polyfill if desired.
To date, no browser implementations of ES6 modules exist
<link rel="stylesheet" href="styles.css" />
<div class="class">
Any valid HTML can go in an HTML Import file.
</div>
<script src="some-file.js"></script>
<link rel="import" href="/path/to/my/web-component.html" />
use it
create it
Many have seen ShadowDOM as a means of explaining aspects of how the web -- specifically HTML -- works.
<select>
<audio>/<video>
<details>
Web Components were a Google effort and little negotiation was made with other browsers before shipping.
- Mozilla
Reconciliation was made, and in July all parties agreed on a path forward* which involves breaking ShadowDOM up into two versions.
Chrome has already issued an intent to ship for ShadowDOM v1
*Controversy mostly centered around the so called "light DOM" projection model. Resolution was to implement "slotting"
let shadowHost = document.querySelector('#needsShadow'),
shadowChild = document.createElement('p');
shadowHost.createShadowRoot();
shadowHost.shadowRoot.append(shadowChild);
just replace all references to `this.shadowRoot` with `this`.
HTML Templates are supported by every major evergreen browser.
It's ridiculously easy to polyfill*
*OK, it's more like a patch as the contents won't be inert, but it's better than writing code around it and we're coding for the future right? RIGHT?
<template>
<p>Any <strong>HTML</strong>.</p>
<p>Seriously, <em>any</em> <abbr>HTML<abbr></p>
</template>
build it
var el = document.querySelector(div),
fragment = document.importNode(
document.querySelector('template').content,
true
);
el.appendChild(fragment);
use it
Define Custom Semantic Elements as Components
React to lifecycle events
All other standard events are available to you.
Receive config through attributes (events?)
Expose information via custom events.
This is where the real power is.
Lifecycle callbacks are RAD!*
*All though technically you don't even need this. Mutation Observers can be made to accomplish the same thing. In fact, this is how Custom Elements is polyfilled.
const awesomePrototype = Object.create(HTMLElement, {
// assign methods and properties
});
awesomePrototype.createdCallback = function () { ... };
awesomePrototype.attachedCallback = function () { ... };
awesomePrototype.detachedCallback = function () { ... };
awesomePrototype.attributeChangedCallback = function (attrName, prevVal, currVal) { ... };
document.registerElement('awe-some', {
prototype: awesomePrototype
});
built it.
<awe-some rad="UtahJS">
<p>Composed DOM</p>
<p>AKA Light DOM</p>
</awesmome>
use it.
const awesomePrototype = Object.create(HTMLElement, {
rad: {
get() {
return this.getAttribute('rad');
},
set(val) {
return this.setAttribute('rad', val);
}
}
});
document.registerElement('awe-some', {
prototype: awesomePrototype
});
pro tip: bind attributes to properies with getters/setters.
`But I still need ${lame_framework_feature} to do any real work.`
A library for authoring web components
(shameless self promotion)
(loud applause!)