Created
January 18, 2017 21:04
-
-
Save dgrammatiko/a304896303b7a5fd0e968f3e233c351c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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