-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
WebUI: Replace getElements & getChildren #22220
base: master
Are you sure you want to change the base?
Conversation
@@ -490,7 +490,9 @@ window.addEventListener("DOMContentLoaded", () => { | |||
const categoryList = document.getElementById("categoryFilterList"); | |||
if (!categoryList) | |||
return; | |||
categoryList.getChildren().each(c => c.destroy()); | |||
|
|||
for (const category of categoryList.querySelectorAll("li")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this be fragile? Also it looks like it will get grandchildren too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, totally forgot about subcategories - will fix to get only direct children.
Won't this be fragile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this be fragile?
I was concerned about it limits itself to li
elements. Previously the code would not care about the type of elements, just direct children. Or do you think it make sense to target specific type of children elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would it be wrong if you used Element.children
property? It is a live HTMLCollection
but it shouldn't matter when we only call destroy()
on each element. I mean, the live collection iterator shouldn't be invalidated with this kind of operation, unless destroy()
is doing more than expected...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We can do something like this:
for (const category of [...categoryList.children])
- but we can't do this:
for (const category of categoryList.children)
I mean, the live collection iterator shouldn't be invalidated with this kind of operation, unless
destroy()
is doing more than expected...
destroy()
detaches child from the parent and that causes children collection to be updated. For example, this is what happens if we add category in second case (it's all mangled):
I was concerned about it limits itself to
li
elements. Previously the code would not care about the type of elements, just direct children. Or do you think it make sense to target specific type of children elements?
No, I think you are right in that it should be generic. Should I change everything to use 1)? Or maybe keep querySelectorAll and do something like this container.querySelectorAll(":scope > *")
? Which one do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destroy() detaches child from the parent and that causes children collection to be updated. For example, this is what happens if we add category in second case (it's all mangled):
Thanks for confirming!
Which one do you prefer?
I would go with the first option.
Also, it could be written like this to make it one line: Array.from().forEach();
This PR further reduces Mootools usage.