Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaner attributeFilter/attributeOldValue example (MutationObserver) #32656

Closed
wants to merge 1 commit into from

Conversation

mrienstra
Copy link
Contributor

Description

Simplify callback, in the MutationObserver example illustrating the usage of attributeFilter & 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 been mutation.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

Simplify example callback.

Old version had a typo, ` userStatusChanged(mutation.target.username, mutation.target.status);` ➝ ` userStatusChanged(mutation.oldValue, mutation.target.status);`

Old version added in mdn#9737:
https://github.com/mdn/content/pull/9737/files#diff-fc20b9f4adbc6723e9fe01425cea6512399d9a9bd69451d25f8fd6f0b8f92788R144-R170
@mrienstra mrienstra requested a review from a team as a code owner March 12, 2024 05:46
@mrienstra mrienstra requested review from Elchi3 and removed request for a team March 12, 2024 05:46
@github-actions github-actions bot added Content:WebAPI Web API docs size/s 6-50 LoC changed labels Mar 12, 2024
Copy link
Contributor

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! However, as mentioned in the example explanation, this example is meant to display a real-world relevant example of why you may want to use this API. In general, it's much easier to adapt a real-world example to a runnable example (either stub out the missing function implementation, or replace the function body with a simple log, as you have done), but it's hard to imagine how an example can be real-world relevant by looking at a contrived example like the new one. For example, it's easy to image that userStatusChanged and usernameChanged will each send a request to the server saying "the status of user X has changed to Y", and "the username of user X has changed to Y".

@Josh-Cena Josh-Cena closed this Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/s 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants