reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
20.46k stars 1.18k forks source link

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

Closed adhami3310 closed 2 weeks ago

adhami3310 commented 2 weeks ago
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 commented 2 weeks ago

Fixes #4264

adhami3310 commented 2 weeks ago

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

@deserializer
def deserialize_datetime(value: str) -> datetime:
    ...
linear[bot] commented 2 weeks ago

ENG-3793 Event Handlers should accept rx.Base arguments

adhami3310 commented 2 weeks ago

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

masenf commented 2 weeks ago

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