Skip to content

Instantly share code, notes, and snippets.

@dgrammatiko
Created January 18, 2017 21:04
Show Gist options
  • Save dgrammatiko/a304896303b7a5fd0e968f3e233c351c to your computer and use it in GitHub Desktop.
Save dgrammatiko/a304896303b7a5fd0e968f3e233c351c to your computer and use it in GitHub Desktop.
(function () {
var ElementPrototype = Object.create(HTMLElement.prototype);
// Lifecycle methods
ElementPrototype.createdCallback = function () {
};
ElementPrototype.attachedCallback = function () {
};
ElementPrototype.detachedCallback = function () {
};
ElementPrototype.attributeChangedCallback = function (attr, oldVal, newVal) {
if (attr in attrs) {
attrs[attr].call(this, oldVal, newVal);
}
};
// Custom methods
ElementPrototype.foo = function () {
};
// Attribute handlers
var attrs = {
'attr': function (oldVal, newVal) {
}
};
// Property handlers
Object.defineProperties(ElementPrototype, {
'prop': {
get : function () {
},
set : function (newVal) {
}
}
});
// Register the element
window.CustomElement = document.registerElement('custom-element', {
prototype: ElementPrototype
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment