- From: Joe Pea <notifications@github.com>
- Date: Sun, 15 Oct 2017 23:14:46 +0000 (UTC)
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/521@github.com>
I only see an `oldValue` when trying to observe attribute changes. Are we expected to access the attribute values on the element, inside the observer's callback?
For example, here's mine:
```js
const observer = new MutationObserver( records => {
for (const record of records) {
behavior.attributeChangedCallback(
this.ownerElement,
record.attributeName,
record.oldValue,
this.ownerElement.getAttribute( record.attributeName )
)
}
} )
```
where in my case `behavior` is part of an implementation of [element behaviors (the `has=""` attribute)](https://github.com/w3c/webcomponents/issues/662), implemented on to of [custom-attributes](https://github.com/matthewp/custom-attributes), but I haven't published it yet.
The `behavior.attributeChangedCallback` signature is `(element, attributeName, oldValue, newValue)`, so as you see I'm getting the new value from the element directly.
But this seems dirty. I might be calling some Custom Element's overriden or extended `getAttribute` method.
How does the MutationObserver implementation get the element's `oldValue`? It seems that the new value should be gotten the same way as the engine gets the old value (if not already) in order to be consistent.
I don't know exactly what "the same way" means though. Does the engine get the original value passed into `HTMLElement.prototype.setAttribute` (the native one, even is monkey patched)? Or what does it do?
Should I be looping on `element.attributes` instead, and using that as the source of truth, rather than `getAttribute`?
I'm wondering about what MutationObserver does for `oldValue`, but in general, considering that nothing will change for a while, I'm looking for advice on what's best to do. Thanks!
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/521
Received on Sunday, 15 October 2017 23:15:09 UTC