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

[REF-2523] Implement new public Component API #3203

Merged
merged 5 commits into from
May 1, 2024

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented May 1, 2024

add_imports (dict str: list of str or importvar)
add_hooks (list of str)
add_custom_code (list of str)

These functions are treated specially in that they don't have to call super(), ever. Internally the Component will walk up all of the base Component classes and call each add_* method and collect the return values.

All the downstream user has to do is implement these add_* functions and return the value they want to add.

add_imports (dict str: list of str or importvar)
add_hooks (list of str)
add_custom_code (list of str)

These functions are treated specially in that they don't have to call
`super()`, ever. Internally the Component will walk up all of the base
Component classes and call each `add_*` method and collect the return values.

All the downstream user has to do is implement these add_* functions and return
the value they want to add.
Copy link

linear bot commented May 1, 2024

picklelo
picklelo previously approved these changes May 1, 2024
return {}

def add_hooks(self) -> list[str]:
"""Add hooks inside the component function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can include an example of how it's used in practice (along with the other ones) for the autogenerated API docs

@@ -932,6 +989,30 @@ def _has_event_triggers(self) -> bool:
return True
return False

@classmethod
def _iter_parent_classes_with_method(cls, method: str) -> Iterator[Type[Component]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this affect compile time noticeably at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

on reflex-web, there is no change in compile time 😅, i expect this iter operation to be quite fast; although it does have to look at all parent classes in the mro chain, it doesn't actually call the method unless it's been defined, and it only calls each unique method once.

picklelo
picklelo previously approved these changes May 1, 2024
@picklelo picklelo merged commit 19d8f6c into main May 1, 2024
46 checks passed
@masenf masenf deleted the masenf/component-add-apis branch May 1, 2024 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants