I have some code like the following,
const observer = new MutationObserver(records => {
for (const record of records) {
if (record.type !== 'attributes') continue
handleAttributeChange(
record.attributeName!,
record.oldValue,
record.target.attributes.getNamedItem(record.attributeName).value,
)
}
})
where handleAttributeChange parameters are the attribute name, the old value, and the new value.
However, as you can tell, the third argument passed into handleAttributeChange,
record.target.attributes.getNamedItem(record.attributeName!)!.value
is always going to be the very latest attribute value, not the "new value" for the particular mutation record that we are iterating on (i.e. not the "new value" that was observed at the time that the mutation happened).
How do we get the "new value" for each mutation as would've been observed at the time each mutation happened?