Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebacondarwin/442f842b6a49d76dbcf5 to your computer and use it in GitHub Desktop.
Save petebacondarwin/442f842b6a49d76dbcf5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<template id='my-component-template'>
<style>
@import url('whatever...');
</style>
</template>
<div id="parent"><my-component></my-component></div>
<script>
function MyComponent() {}
MyComponent.prototype = Object.create(HTMLElement.prototype);
MyComponent.prototype.createdCallback = function() {
var template = document.getElementById('my-component-template');
var clone = document.importNode(template.content, true);
var shadow = this.createShadowRoot();
shadow.appendChild(clone); // this line crashes Chrome 42.0.2311.90
};
document.registerElement('my-component', MyComponent);
var parent = document.getElementById('parent');
var webComponent = parent.firstElementChild;
var newNode = document.createElement('div');
parent.replaceChild(newNode, webComponent);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment