Skip to content

Commit

Permalink
eliminate need to mock HTMLElement in node
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Jun 8, 2017
1 parent 9266cfd commit 30c3faf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/core/a-cubemap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global HTMLElement */
var debug = require('../utils/debug');
var registerElement = require('./a-register-element').registerElement;

Expand All @@ -9,7 +8,7 @@ var warn = debug('core:cubemap:warn');
* Does not listen to updates.
*/
module.exports = registerElement('a-cubemap', {
prototype: Object.create(HTMLElement.prototype, {
prototype: Object.create(window.HTMLElement.prototype, {
/**
* Calculates this.srcs.
*/
Expand Down
13 changes: 6 additions & 7 deletions src/core/a-entity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global HTMLElement */
var ANode = require('./a-node');
var COMPONENTS = require('./component').components;
var registerElement = require('./a-register-element').registerElement;
Expand Down Expand Up @@ -384,7 +383,7 @@ var proto = Object.create(ANode.prototype, {
// the component with the empty string.
if (!this.hasAttribute(attrName)) {
component.justInitialized = true;
HTMLElement.prototype.setAttribute.call(this, attrName, '');
window.HTMLElement.prototype.setAttribute.call(this, attrName, '');
}

debug('Component initialized: %s', attrName);
Expand Down Expand Up @@ -416,7 +415,7 @@ var proto = Object.create(ANode.prototype, {
// Call getAttribute to initialize the data from the DOM.
self.initComponent(
componentName,
HTMLElement.prototype.getAttribute.call(self, componentName) || undefined,
window.HTMLElement.prototype.getAttribute.call(self, componentName) || undefined,
true
);
});
Expand Down Expand Up @@ -580,7 +579,7 @@ var proto = Object.create(ANode.prototype, {
this.mixinUpdate('');
}

HTMLElement.prototype.removeAttribute.call(this, attr);
window.HTMLElement.prototype.removeAttribute.call(this, attr);
}
},

Expand Down Expand Up @@ -701,7 +700,7 @@ var proto = Object.create(ANode.prototype, {
// Initialize component first if not yet initialized.
if (!this.components[attrName] && this.hasAttribute(attrName)) {
this.updateComponent(attrName,
HTMLElement.prototype.getAttribute.call(this, attrName));
window.HTMLElement.prototype.getAttribute.call(this, attrName));
}

// Determine which type of setAttribute to call based on the types of the arguments.
Expand Down Expand Up @@ -779,7 +778,7 @@ var proto = Object.create(ANode.prototype, {
// If component, return component data.
var component = this.components[attr];
if (component) { return component.data; }
return HTMLElement.prototype.getAttribute.call(this, attr);
return window.HTMLElement.prototype.getAttribute.call(this, attr);
},
writable: window.debug
},
Expand Down Expand Up @@ -813,7 +812,7 @@ var proto = Object.create(ANode.prototype, {
// If cached value exists, return partial component data.
var component = this.components[attr];
if (component) { return component.attrValue; }
return HTMLElement.prototype.getAttribute.call(this, attr);
return window.HTMLElement.prototype.getAttribute.call(this, attr);
},
writable: window.debug
},
Expand Down
7 changes: 3 additions & 4 deletions src/core/a-mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global HTMLElement */
var ANode = require('./a-node');
var registerElement = require('./a-register-element').registerElement;
var components = require('./component').components;
Expand Down Expand Up @@ -39,7 +38,7 @@ module.exports = registerElement('a-mixin', {
setAttribute: {
value: function (attr, value) {
this.cacheAttribute(attr, value);
HTMLElement.prototype.setAttribute.call(this, attr, value);
window.HTMLElement.prototype.setAttribute.call(this, attr, value);
}
},

Expand All @@ -52,7 +51,7 @@ module.exports = registerElement('a-mixin', {
var component = components[componentName];
if (!component) { return; }
if (value === undefined) {
value = HTMLElement.prototype.getAttribute.call(this, attr);
value = window.HTMLElement.prototype.getAttribute.call(this, attr);
}
this.componentCache[attr] = component.parseAttrValueForCache(value);
}
Expand All @@ -65,7 +64,7 @@ module.exports = registerElement('a-mixin', {
getAttribute: {
value: function (attr) {
return this.componentCache[attr] ||
HTMLElement.prototype.getAttribute.call(this, attr);
window.HTMLElement.prototype.getAttribute.call(this, attr);
}
},

Expand Down
6 changes: 3 additions & 3 deletions src/core/a-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global HTMLElement, MutationObserver */
/* global MutationObserver */
var registerElement = require('./a-register-element').registerElement;
var utils = require('../utils/');

Expand All @@ -12,7 +12,7 @@ var warn = utils.debug('core:a-node:warn');
* Nodes emit a `loaded` event when they and their children have initialized.
*/
module.exports = registerElement('a-node', {
prototype: Object.create(HTMLElement.prototype, {
prototype: Object.create(window.HTMLElement.prototype, {
createdCallback: {
value: function () {
this.hasLoaded = false;
Expand Down Expand Up @@ -160,7 +160,7 @@ module.exports = registerElement('a-node', {
setAttribute: {
value: function (attr, newValue) {
if (attr === 'mixin') { this.updateMixins(newValue); }
HTMLElement.prototype.setAttribute.call(this, attr, newValue);
window.HTMLElement.prototype.setAttribute.call(this, attr, newValue);
}
},

Expand Down
4 changes: 2 additions & 2 deletions src/core/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global HTMLElement, Node */
/* global Node */
var schema = require('./schema');
var scenes = require('./scene/scenes');
var systems = require('./system');
Expand Down Expand Up @@ -214,7 +214,7 @@ Component.prototype = {
flushToDOM: function (isDefault) {
var attrValue = isDefault ? this.data : this.attrValue;
if (!attrValue) { return; }
HTMLElement.prototype.setAttribute.call(this.el, this.attrName,
window.HTMLElement.prototype.setAttribute.call(this.el, this.attrName,
this.stringify(attrValue));
},

Expand Down
3 changes: 1 addition & 2 deletions src/core/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global HTMLElement */
var components = require('./component');
var schema = require('./schema');
var utils = require('../utils/');
Expand Down Expand Up @@ -80,7 +79,7 @@ System.prototype = {
buildData: function (rawData) {
var schema = this.schema;
if (!Object.keys(schema).length) { return; }
rawData = rawData || HTMLElement.prototype.getAttribute.call(this.sceneEl, this.name);
rawData = rawData || window.HTMLElement.prototype.getAttribute.call(this.sceneEl, this.name);
if (isSingleProp(schema)) {
this.data = parseProperty(rawData, schema);
} else {
Expand Down
2 changes: 0 additions & 2 deletions tests/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ suite('node acceptance tests', function () {
let _window = global.window = jsdom.jsdom().defaultView;
global.navigator = _window.navigator;
global.document = _window.document;
global.HTMLElement = _window.HTMLElement;
});

teardown(function () {
delete global.window;
delete global.navigator;
delete global.document;
delete global.HTMLElement;
});

test('can run in node', function () {
Expand Down

0 comments on commit 30c3faf

Please sign in to comment.