Skip to content

Instantly share code, notes, and snippets.

@arv
Last active December 11, 2015 23:18
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 arv/4675415 to your computer and use it in GitHub Desktop.
Save arv/4675415 to your computer and use it in GitHub Desktop.
document.register with classes
// Create is defined in the latest ES6 spec. Foo[create]() is used to create the instance
// when you do "new Foo". This instance is then passed to Foo.call(instance, <args>)
import {create} from '@reflect';
Element[create] = function() {
return documemt.createElementNS(this.prototype.namespaceURI, this.prototype.localName)
};
class MyBytton extends HTMLButtonElement {
constructor() { // In this case the constructor is not needed since if you
// leave it out you get a constructor that does the same thing.
super();
}
get foo() { ... }
}
document.register('my-button', {
class: MyButton // property name TBD
});
// With potential annotation syntax
class MyButton extends HTMLButtonElement {
+ customElement('my-button')
}
// Or
@customElement('my-button')
class MyButton extends HTMLButtonElement {
}
// Where the annotation function could be defined as.
function customElement(tagName) {
return function(klass) {
return document.register(tagName, {
class: klass
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment