Skip to content

Implement decentralized event handlers#5211

Closed
devin-ai-integration[bot] wants to merge 11 commits intomainfrom
devin/1745972901-decentralized-event-handlers
Closed

Implement decentralized event handlers#5211
devin-ai-integration[bot] wants to merge 11 commits intomainfrom
devin/1745972901-decentralized-event-handlers

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Implement Decentralized Event Handlers

This PR implements the ability to use decentralized event handlers in the Reflex framework, as described in ENG-5594.

Features

  • Added support for defining event handlers outside of state classes using the @rx.event decorator
  • Event handlers require an explicit state parameter that identifies the state they operate on
  • Implemented automatic registration of decentralized event handlers in a global registry
  • Updated event processing logic to handle decentralized event handlers
  • Added integration tests to verify the functionality

Example Usage

@rx.event
def on_load(state: ChatState):
    """Event handler for loading the chat state."""
    state.field = 321

...

rx.button(on_mount=on_load)

Testing

  • Added integration tests that verify decentralized event handlers work with on_mount and on_click events
  • All existing tests pass, ensuring backward compatibility

Link to Devin run: https://app.devin.ai/sessions/5954950b5f294e9682d09edc224e891b
Requested by: khaleel@reflex.dev

Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 30, 2025

CodSpeed Performance Report

Merging #5211 will improve performances by 4.82%

Comparing devin/1745972901-decentralized-event-handlers (6e98a68) with main (26f1a7b)

Summary

⚡ 1 improvements
✅ 11 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_compile_stateful[_simple_page] 256.5 µs 244.7 µs +4.82%

Copy link
Copy Markdown
Member

@adhami3310 adhami3310 left a comment

Choose a reason for hiding this comment

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

import reflex as rx


class State(rx.State):
    """The app state."""

    value: int = 32


@rx.event
def set_values(state: State, value: str):
    state.value = int(value)
    print(f"Value set to {state.value}")


def index() -> rx.Component:
    return rx.button(
        "Click me",
        State.value,
        on_click=set_values("100"),
    )


app = rx.App()
app.add_page(index)

that needs to work but:

  File "/home/khaleel/Projects/reflex/reflex/examples/demo/demo/demo.py", line 20, in index
    on_click=set_values("100"),
             ~~~~~~~~~~^^^^^^^
TypeError: set_values() missing 1 required positional argument: 'value'

devin-ai-integration bot and others added 9 commits April 30, 2025 01:06
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

wrong directory :(

Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
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.

2 participants