On Github cbalit / prez-webcomponents
4 specifications
Html Import Shadow Dom Template Custom ElementInclude an HTML element inside another one
HTML and CSS are just loaded but not included (available) We retrieve the content using the import property
Load and Error Event
Browsers already use it
It's all about Encapsulation
Normal button! Hello, world!
Hello
Reusable DOM template
No side effect
Declaration vs register
registerRegister
var myElemtProto = Object.create(HTMLElement.prototype); myElemtProto.createdCallback = function() {}; var myElemt = document.registerElement('my-element', myElemtProto);
myEltProto.createdCallback = function() { this.innerHTML = "un peu de contenu!"; };
myEltProto.createdCallback = function() { var shadow = this.createShadowRoot(); shadow.innerHTML = "un peu de contenu!"; };
myEltProto.createdCallback = function() { var t = document.querySelector('#sdtemplate'); var clone = document.importNode(t.content, true); this.createShadowRoot().appendChild(clone); };
myEltProto.myFctn=function(){...} Object.defineProperty(myEltProto, "bar", {value: 5});
Can be used alone
But a weak support
So what can we do ?
Credits: Eric Bidelman,Rob Dodson,Dominic Cooney