Skip to content

Commit

Permalink
v0.3.2 - Use standard method for capturing overridden getters and set…
Browse files Browse the repository at this point in the history
…ters.
  • Loading branch information
justindarc committed Jan 30, 2015
1 parent ebda6fd commit 27df9c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gaia-component",
"version": "0.3.1",
"version": "0.3.2",
"authors": [
"Wilson Page <[email protected]>"
],
Expand Down
37 changes: 9 additions & 28 deletions gaia-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

var textContent = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent');
var removeAttribute = HTMLElement.prototype.removeAttribute;
var setAttribute = HTMLElement.prototype.setAttribute;
var innerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
var removeAttribute = Element.prototype.removeAttribute;
var setAttribute = Element.prototype.setAttribute;
var noop = function() {};

/**
Expand Down Expand Up @@ -53,8 +54,6 @@ exports.register = function(name, props) {
// Create the prototype, extended from base and
// define the descriptors directly on the prototype
var proto = createProto(baseProto, props);
proto._getInnerHTML = proto.__lookupGetter__('innerHTML');
proto._setInnerHTML = proto.__lookupSetter__('innerHTML');
Object.defineProperties(proto, descriptors);

// Register the custom-element and return the constructor
Expand Down Expand Up @@ -150,25 +149,20 @@ var base = {
descriptors: {
textContent: {
set: function(value) {
var node = firstChildTextNode(this);
if (node) { node.nodeValue = value; }
textContent.set.call(this, value);
if (this.lightStyle) { this.appendChild(this.lightStyle); }
},

get: function() {
var node = firstChildTextNode(this);
return node && node.nodeValue;
}
get: textContent.get
},

innerHTML: {
set: function(value) {
this._setInnerHTML(value);
this.appendChild(this.lightStyle);
innerHTML.set.call(this, value);
if (this.lightStyle) { this.appendChild(this.lightStyle); }
},

get: function() {
return this._getInnerHTML();
}
get: innerHTML.get
}
}
};
Expand Down Expand Up @@ -209,19 +203,6 @@ function createProto(proto, props) {
return Object.assign(Object.create(proto), props);
}

/**
* Return the first child textNode.
*
* @param {Element} el
* @return {TextNode}
*/
function firstChildTextNode(el) {
for (var i = 0; i < el.childNodes.length; i++) {
var node = el.childNodes[i];
if (node && node.nodeType === 3) { return node; }
}
}

/**
* Detects presence of shadow-dom
* CSS selectors.
Expand Down
11 changes: 9 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,18 @@ suite('gaia-component', function() {
assert.isUndefined(this.Component.prototype.globalCss);
});

test('setting textContent doesnt remove light-dom css', function() {
test('setting textContent doesn\'t remove light-dom CSS', function() {
var component = new this.Component();
component.textContent = 'foo';
var style = component.querySelector('style');
assert.isDefined(style);
assert.ok(style);
});

test('setting innerHTML doesn\'t remove light-dom CSS', function() {
var component = new this.Component();
component.innerHTML = 'foo';
var style = component.querySelector('style');
assert.ok(style);
});

test('removeAttr() and setAttr() also set attrs on first shadow-dom child', function() {
Expand Down

0 comments on commit 27df9c7

Please sign in to comment.