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

Commit

Permalink
Add newValue to attributeChangedCallback; fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Oct 28, 2013
1 parent c3a8217 commit 8aaf3bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/CustomElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,20 @@ if (useNative) {
changeAttribute.call(this, name, value, setAttribute);
}
var removeAttribute = prototype.removeAttribute;
prototype.removeAttribute = function(name, value) {
changeAttribute.call(this, name, value, removeAttribute);
prototype.removeAttribute = function(name) {
changeAttribute.call(this, name, null, removeAttribute);
}
}

// https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/
// index.html#dfn-attribute-changed-callback
function changeAttribute(name, value, operation) {
var oldValue = this.getAttribute(name);
operation.apply(this, arguments);
if (this.attributeChangedCallback
&& (this.getAttribute(name) !== oldValue)) {
this.attributeChangedCallback(name, oldValue);
var newValue = this.getAttribute(name);
if (this.attributeChangedCallback
&& (newValue !== oldValue)) {
this.attributeChangedCallback(name, oldValue, newValue);
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/html/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
this.setAttributeOk = true;
HTMLElement.prototype.setAttribute.call(this, name, value);
};
prototype.attributeChangedCallback = function(name) {
this.attributeChangedOk = (name == 'squid');
prototype.attributeChangedCallback = function(name, oldValue, newValue) {
this.attributeChangedOk = (name === 'squid') && (oldValue === null)
&& (newValue === 'tentacles');
};
document.register('x-foo', {prototype: prototype});

Expand Down

0 comments on commit 8aaf3bc

Please sign in to comment.