-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat: add Media.extend #890
feat: add Media.extend #890
Conversation
for more information, see https://pre-commit.ci
media_cls = comp_media.media_class or MediaCls | ||
media_js = getattr(comp_media.Media, "js", []) | ||
media_css = getattr(comp_media.Media, "css", {}) | ||
comp_media.media = media_cls(js=media_js, css=media_css) if comp_media.Media is not None else None |
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.
Previously, the media
instance contained only the JS / CSS files from the current Component class, so it was enough to just instantiate it. Now, the _get_comp_cls_media
travels up the Component's parent classes to find all the JS / CSS. And so the child component class end up inheriting them all.
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.
This looks awesome. Ready to merge. Really like the tests, simple and effective.
I think I remember you describing that we've implemented Media "except for the extends" somewhere in the docs, but I don't see that removed here?
@EmilStenstrom Yeah that's true, thanks for reminding me that! |
This PR:
Component.media
instance to inherit the JS and CSS from parent componentsextend
attribute onComponent.Media
, which behaves similarly to Django's Media.extend.This addresses points 4. and 5. from this discussion.
Examples:
Normal media inheritance:
Disable media inheritance:
Specific set of parent Media classes
In this case, the media files are inherited ONLY
from the specified components, and NOT from the original parent components:
And some documentation :)
Screen.Recording.2025-01-07.at.20.18.19.mov