Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing Web Components

Peter Gasston
September 28, 2013

Introducing Web Components

Front-end London one-day event, September 2013

Peter Gasston

September 28, 2013
Tweet

More Decks by Peter Gasston

Other Decks in Technology

Transcript

  1. .foo { color: #00f; } The problem <div class="foo"> …

    </div> div.foo { color: #f00; } <div class="foo"> … </div>
  2. <iframe src="foo.htm"> • Extra network requests • Multiple rendering contexts

    • CORS conflicts • Generally a bit shit Encapsulation
  3. Templates + Shadow DOM var newRoot = $(foo).createShadowRoot(), clone =

    $(bar).content.cloneNode(true), newRoot.innerHTML = clone;
  4. Templates + Shadow DOM var newRoot = $(foo).createShadowRoot(), el =

    document.createElement('content'); newRoot.innerHTML = el;
  5. HTML Imports var lnk = 'link[rel="import"]', impt = document.querySelector(lnk), tpl

    = lnk.import.getElementById('foo'), clone = tpl.content.cloneNode(true);
  6. Custom element API var fe = Object.create( HTMLElement.prototype ); fe.foo

    = function() { // Something }; document.register('front-end', { prototype: fe });
  7. The part attribute var newRoot = el.createShadowRoot(), newEl = '<h2

    part="apes">…</h2>'; newRoot.appendChild(newEl);
  8. <p>Hello</p> <div> <style scoped> p { color: #f00; } </style>

    <p>World!</p> </div> <p>Again</p> Scoped styles
  9. Shadow DOM Shadow DOM API Templates HTML imports Custom elements

    Scoped styles Custom properties Browser support