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

Web Components changes Web Development

Web Components changes Web Development

2014/7/28に開催されたHTML5とか勉強会の「Web Componentsが変えるWeb開発の未来」のセッションの資料です。

Shogo Sensui

July 28, 2014
Tweet

More Decks by Shogo Sensui

Other Decks in Technology

Transcript

  1. var XElementPrototype = Object.create(HTMLElement.prototype); XElementPrototype.createdCallback = function () { console.log('created');

    }; XElementPrototype.attachedCallback = function () { console.log('attached'); }; XElementPrototype.detachedCallback = function () { console.log('detached'); }; XElementPrototype.attributeChangedCallback = function () { console.log('attribute changed'); }; var XElement = document.registerElement('x-element', { prototype: XElementPrototype }); new XElement();
  2. <template id='tmpl'> <style> input, button { border: 1px solid #000;

    border-radius: 3px; } </style> <input type='text'> <button>Button</button> </template>
  3. var template = document.querySelector('#tmpl'); var div = document.querySelector('div'); var clone

    = document.importNode(template.content, true); var shadowRoot = div.createShadowRoot(); shadowRoot.appendChild(clone);
  4. var options = { zoom: 10, center: new google.map.LatLng(-34.397, 150.644)

    }; var mapCanvas = document.getElementById('map-canvas'); var map = new google.maps.Map(mapCanvas, options); var marker = new google.maps.Marker({ position: new google.map.LatLng(-34.397, 150.644), map: map, title: 'Hello World!' }); var flightPlanCoordinates = [ new google.maps.LatLng(37.772323, -122.214897), new google.maps.LatLng(21.291982, -157.821856), new google.maps.LatLng(-18.142599, 178.431), new google.maps.LatLng(-27.46758, 153.027892) ]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, geodesic: true, strokeColor: '#FF0000', strokeOpacity: 1.0,
  5. <template> <p>lorem ipsum</p> </template> <script> var XElement = document.registerElement('x-element', {

    prototype: { createdCallback: function () { var template = document.querySelector('template'); var clone = document.importNode(template.content, true); var shadowRoot = element.createShadowRoot(); shadowRoot.appendChild(clone); } } }); </script>
  6. ͒