Improving ElementCollection.update_all to use Element.update #2453
Replies: 4 comments 7 replies
-
|
OK. Clearly I'm biased here. 🤣 But, this is a good thing to do for several reasons:
I'm happy for this to become a nice small, neat and tidy PR - @WebReflection do you have any further thoughts? |
Beta Was this translation helpful? Give feedback.
-
|
Element.classList is a pretty simple API that allows if you want to add one or more classes without duplicates as attribute: classes = ['one', 'or', 'more']
class_list = self._dom_element.classList
class_list.add.apply(class_list, classes)that will have Happy to learn or explore more, right now I feel like this is a great opportunity to improve previous state with relative ease. |
Beta Was this translation helpful? Give feedback.
-
|
I just submitted a pull request for the basic bug fix I had described at the beginning of this discussion. I assume further conversation will be needed to determine the final architecture (i.e., more pythonic or less pythonic) of this module, so these changes are simply to resolve the immediate bug! 😃 |
Beta Was this translation helpful? Give feedback.
-
|
OK. Now there's a fix - I'll close this comment. Further |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Initially raised by @ntoll, this discussion proposes a change in the
ElementCollection.update_all()function to eliminate duplicate code.The code in question is contained within
web.py(pyscript/core/src/stdlib/pyscript/web.py).Element.update()ElementCollection.update_all()The current functions are as follows:
Currently,
update_allbypasses the logic found inupdate. Thusupdate_allcould break the Element object's internal state since it usessetattrdirectly. If my understanding is correct,setattr(element, name, value)could replace the classes attribute if a user calledcollection.update_all(classes="active").With the proposed changes below, having
element.update(classes="active")would correctly callself.classes.add('active'). Also, consolidating this logic makes sure that any future improvements to Element.update are automatically applied to collections.The change would modify
update_allexclusively and would look something like:Let me know your thoughts, and I can create a PR if we think this is a change that should be implemented. 😃
Beta Was this translation helpful? Give feedback.
All reactions