Cleaner attributeFilter/attributeOldValue example (MutationObserver) #32656
+3
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Simplify callback, in the
MutationObserver
example illustrating the usage ofattributeFilter
&attributeOldValue
.Motivation
I thought the old version had a typo, in
userStatusChanged(mutation.target.username, mutation.target.status);
,mutation.target.username
seems like it should've beenmutation.oldValue
, though after taking a closer look, this was probably intentional.While fixing this "typo", I decided the old callback was unnecessary complex -- e.g. the outer
switch
wasn't doing anything (aside from serving as a future placeholder perhaps) -- so I made it a bit more "to the point". Also seems a tiny bit unusual to have an example that calls functions not provided (userStatusChanged
&usernameChanged
), this new one is a little easier to modify and begin playing with.Related issues and pull requests
Old version added in #9737:
https://github.com/mdn/content/pull/9737/files#diff-fc20b9f4adbc6723e9fe01425cea6512399d9a9bd69451d25f8fd6f0b8f92788R144-R170