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

[ENG-3793] convert event return types to type hints #4331

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

adhami3310
Copy link
Member

No description provided.

@adhami3310
Copy link
Member Author

import dataclasses
import reflex as rx


@dataclasses.dataclass
class Guy:
    name: str


class State(rx.State):
    """State for the TestApp app."""

    @rx.event
    def on_event(self, payload: Guy):
        print(f"Hello {payload.name}!")


app = rx.App()


@app.add_page
def index():
    return rx.vstack(
        rx.button(
            on_click=State.on_event(Guy("Alice")),
        ),
    )

@adhami3310
Copy link
Member Author

Fixes #4264

@adhami3310 adhami3310 linked an issue Nov 8, 2024 that may be closed by this pull request
@adhami3310
Copy link
Member Author

@benedikt-bartscher how would you imagine hooking into this system? maybe

@deserializer
def deserialize_datetime(value: str) -> datetime:
    ...

@masenf masenf changed the title convert event return types to type hints [ENG-3793] convert event return types to type hints Nov 8, 2024
Copy link

linear bot commented Nov 8, 2024

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.

pretty neat

@adhami3310
Copy link
Member Author

In case we want to improve the system, we can do so in later PRs o7

@adhami3310 adhami3310 merged commit 4c4c59b into main Nov 8, 2024
34 checks passed
@adhami3310 adhami3310 deleted the convert-event-return-types-to-type-hints branch November 8, 2024 00:33
@masenf
Copy link
Collaborator

masenf commented Nov 8, 2024

This is a breaking change, technically, but i think it breaks in the right way because what was there before was incorrect

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.

Cast dict as model type if annotated
2 participants