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

Um futuro chamado Web Components

Um futuro chamado Web Components

BrazilJS 2013

Zeno Rocha

August 22, 2013
Tweet

More Decks by Zeno Rocha

Other Decks in Programming

Transcript

  1. <brazil-js></brazil-js> usando JS var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function()

    { this.textContent = 'BrazilJS!'; }; document.register('brazil-js', { prototype: proto });
  2. // 1. Acessa o conteúdo do template var t =

    document.querySelector('#meuTemplate').content; // 2. Manipula elemento interno do template t.querySelector('img').src = 'logo.png'; // 3. Clona e insere no DOM document.body.appendChild(t.cloneNode(true)); como usar?
  3. estilo, marcação e script encapsulados <h1>Documento</h1> <div id=”cuia”></div> var cuia

    = document.querySelector('#cuia') .createShadowRoot(); cuia.innerHTML = '<h1>Mate</h1>' + '<style>h1 { color: #f00; }</style>';