You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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 and causing unknown side-effects.
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!
The text was updated successfully, but these errors were encountered:
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:
where in my case
behavior
is part of an implementation of element behaviors (thehas=""
attribute), implemented on to of 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 and causing unknown side-effects.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 thangetAttribute
?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!The text was updated successfully, but these errors were encountered: