Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
support document.registerElement
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 6, 2014
1 parent 9e99fcf commit e14a329
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/CustomElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ if (!scope) {
}
var flags = scope.flags;

// native document.register?
// native document.registerElement?

var hasNative = Boolean(document.register);
var hasNative = Boolean(document.registerElement);
var useNative = !flags.register && hasNative;

if (useNative) {
Expand Down Expand Up @@ -73,7 +73,7 @@ if (useNative) {
* element.
*
* @example
* FancyButton = document.register("fancy-button", {
* FancyButton = document.registerElement("fancy-button", {
* extends: 'button',
* prototype: Object.create(HTMLButtonElement.prototype, {
* readyCallback: {
Expand All @@ -86,19 +86,19 @@ if (useNative) {
* @return {Function} Constructor for the newly registered type.
*/
function register(name, options) {
//console.warn('document.register("' + name + '", ', options, ')');
//console.warn('document.registerElement("' + name + '", ', options, ')');
// construct a defintion out of options
// TODO(sjmiles): probably should clone options instead of mutating it
var definition = options || {};
if (!name) {
// TODO(sjmiles): replace with more appropriate error (EricB can probably
// offer guidance)
throw new Error('document.register: first argument `name` must not be empty');
throw new Error('document.registerElement: first argument `name` must not be empty');
}
if (name.indexOf('-') < 0) {
// TODO(sjmiles): replace with more appropriate error (EricB can probably
// offer guidance)
throw new Error('document.register: first argument (\'name\') must contain a dash (\'-\'). Argument provided was \'' + String(name) + '\'.');
throw new Error('document.registerElement: first argument (\'name\') must contain a dash (\'-\'). Argument provided was \'' + String(name) + '\'.');
}
// elements may only be registered once
if (getRegisteredDefinition(name)) {
Expand Down Expand Up @@ -359,7 +359,7 @@ if (useNative) {

// exports

document.register = register;
document.registerElement = register;
document.createElement = createElement; // override
Node.prototype.cloneNode = cloneNode; // override

Expand All @@ -379,6 +379,9 @@ if (useNative) {
scope.upgrade = upgradeElement;
}

// bc
document.register = document.registerElement;

scope.hasNative = hasNative;
scope.useNative = useNative;

Expand Down
2 changes: 1 addition & 1 deletion src/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function bootstrap() {
Platform.endOfMicrotask :
setTimeout;
async(function() {
// set internal 'ready' flag, now document.register will trigger
// set internal 'ready' flag, now document.registerElement will trigger
// synchronous upgrades
CustomElements.ready = true;
// capture blunt profiling data
Expand Down

0 comments on commit e14a329

Please sign in to comment.