Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'cronon/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bicknellr committed Apr 4, 2017
2 parents 79445c1 + 07a88c3 commit 5f4ea0a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions custom-elements.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion custom-elements.min.js.map

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/Patch/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ export default function(internals) {
const oldValue = Native.Element_getAttribute.call(this, name);
Native.Element_setAttribute.call(this, name, newValue);
newValue = Native.Element_getAttribute.call(this, name);
if (oldValue !== newValue) {
internals.attributeChangedCallback(this, name, oldValue, newValue, null);
}
internals.attributeChangedCallback(this, name, oldValue, newValue, null);
});

Utilities.setPropertyUnchecked(Element.prototype, 'setAttributeNS',
Expand All @@ -152,9 +150,7 @@ export default function(internals) {
const oldValue = Native.Element_getAttributeNS.call(this, namespace, name);
Native.Element_setAttributeNS.call(this, namespace, name, newValue);
newValue = Native.Element_getAttributeNS.call(this, namespace, name);
if (oldValue !== newValue) {
internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);
}
internals.attributeChangedCallback(this, name, oldValue, newValue, namespace);
});

Utilities.setPropertyUnchecked(Element.prototype, 'removeAttribute',
Expand Down
4 changes: 2 additions & 2 deletions tests/html/Element/setAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
defineWithLocalName(localName, ['attr']);
});

test('Setting an observed attribute to its current value does not trigger a callback.', function() {
test('Setting an observed attribute to its current value does trigger a callback.', function() {
const element = document.createElement(localName);

assert.equal(element.attrCallbackArgs.length, 0);
Expand All @@ -93,7 +93,7 @@

element.setAttribute('attr', 'abc');

assert.equal(element.attrCallbackArgs.length, 1);
assert.equal(element.attrCallbackArgs.length, 2);
});

test('Setting an observed attribute to a different value triggers a callback.', function() {
Expand Down
5 changes: 3 additions & 2 deletions tests/html/Element/setAttributeNS.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
defineWithLocalName(localName, ['attr']);
});

test('Setting an observed attribute to its current value does not trigger a callback.', function() {
test('Setting an observed attribute to its current value triggers a callback.', function() {
const element = document.createElement(localName);

assert.equal(element.attrCallbackArgs.length, 0);
Expand All @@ -98,7 +98,8 @@

element.setAttributeNS('ns', 'attr', 'abc');

assert.equal(element.attrCallbackArgs.length, 1);
assert.equal(element.attrCallbackArgs.length, 2);
assert.deepEqual(element.attrCallbackArgs[0], ['attr', NON_EXISTANT_VALUE, 'abc', 'ns']);
});

test('Setting an observed attribute to a different value triggers a callback.', function() {
Expand Down
20 changes: 20 additions & 0 deletions tests/js/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ suite('Custom Element Reactions', function() {
assert.equal(changed[0].newValue, 'test1', 'newValue');
});

test('called even if attribute value hasn\'t changed', function () {
var calls = 0;
class XBoo extends HTMLElement {
static get observedAttributes () {
return ['foo'];
}
attributeChangedCallback(name, oldValue, newValue) {
calls += 1;
}
}
var element = document.createElement('x-boo-at2');

customElements.define('x-boo-at2', XBoo);
work.appendChild(element);
element.setAttribute('foo', 'foo');
element.setAttribute('foo', 'foo');

assert.equal(calls, 2);
})

});

suite('connectedCallback', function() {
Expand Down

0 comments on commit 5f4ea0a

Please sign in to comment.