Skip to content

Instantly share code, notes, and snippets.

@AVGP
Last active May 4, 2023 14:05
Show Gist options
  • Save AVGP/d693b4954a1e004c298e to your computer and use it in GitHub Desktop.
Save AVGP/d693b4954a1e004c298e to your computer and use it in GitHub Desktop.
A simple web component boilerplate
<template>
<style>
</style>
</template>
<script>
var Element = null;
(function(currentScript) {
var elemPrototype = Object.create(HTMLDivElement.prototype); // pick the appropriate prototype for your element!
// Private properties
// Public Properties
// Helpers
// Lifecycle callbacks
elemPrototype.createdCallback = function() {
this.root = this.createShadowRoot();
var tplContent = currentScript.ownerDocument.querySelector('template').content,
node = document.importNode(tplContent, true);
this.root.appendChild(node);
};
elemPrototype.attachedCallback = function() {
};
Element = document.registerElement('my-element', { prototype: elemPrototype });
}(document.currentScript || document._currentScript));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment