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

New API to define triggers #1820

Merged
merged 24 commits into from
Sep 21, 2023
Merged

New API to define triggers #1820

merged 24 commits into from
Sep 21, 2023

Conversation

Lendemor
Copy link
Collaborator

@Lendemor Lendemor commented Sep 15, 2023

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

Change the API for defining the signature expected for any event triggers (uncontrolled or controlled):

def get_event_triggers(self):
    return super().get_event_triggers() | { 
        "trigger_name": lambda: [], #uncontrolled 
        "trigger_name": lambda e0: [e0], #1 args 
        "trigger_name": lambda e0,e1: [e0, e1.target.value], #2 args or more
    }

Deprecate the following : get_controlled_triggers, EVENT_ARG, get_triggers, EventChain

Also remove the unused and not working component CopyToClipboard

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

This looks awesome!

reflex/constants.py Outdated Show resolved Hide resolved
reflex/event.py Outdated Show resolved Hide resolved
@Lendemor Lendemor marked this pull request as ready for review September 18, 2023 20:03
reflex/components/component.py Outdated Show resolved Hide resolved
reflex/event.py Outdated Show resolved Hide resolved
masenf
masenf previously approved these changes Sep 19, 2023
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

Love the new API. This is great!

reflex/components/component.py Show resolved Hide resolved
reflex/components/component.py Outdated Show resolved Hide resolved
@@ -48,14 +49,15 @@ class Checkbox(ChakraComponent):
# The spacing between the checkbox and its label text (0.5rem)
spacing: Var[str]

def get_controlled_triggers(self) -> Dict[str, Var]:
def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

We could define a type Callable[Var, List[Var]] for the lambda type and use that instead of Any. Also, when would Var be the dictionary value type, wouldn't it always be a Callable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put Any because my previous definition using LambdaTypes was causing a lot of pyright errors.

Also the Union[Var, ...] is for backward compatibility until removal of deprecated features.

reflex/utils/format.py Show resolved Hide resolved
masenf
masenf previously approved these changes Sep 20, 2023
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

re-approve

@picklelo picklelo merged commit 211dc15 into main Sep 21, 2023
35 checks passed
Alek99 pushed a commit that referenced this pull request Sep 26, 2023
@picklelo picklelo deleted the lendemor/improve_triggers_api branch October 9, 2023 21:07
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.

[REF-554] Wrapping event triggers of React components with more than one parameter
3 participants