Skip to content

add event_action flags to rx.event decorator#5574

Merged
adhami3310 merged 1 commit into
mainfrom
lendemor/event-decorator-enhancement
Jul 17, 2025
Merged

add event_action flags to rx.event decorator#5574
adhami3310 merged 1 commit into
mainfrom
lendemor/event-decorator-enhancement

Conversation

@Lendemor
Copy link
Copy Markdown
Contributor

@Lendemor Lendemor commented Jul 15, 2025

Allow to attach default value for event actions flag on an event_handler decorated by @rx.event

closes #5441

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR introduces a significant enhancement to the @rx.event decorator, allowing event action flags to be specified directly in the decorator rather than through method chaining. This change improves code readability and maintainability while maintaining backward compatibility.

The changes include:

  1. Adding support for event action parameters directly in the decorator (stop_propagation, prevent_default, throttle, debounce, and temporal)
  2. Fixing a bug in event_actions dictionary merging order to ensure correct precedence
  3. Enhancing the _create_event_handler method to handle decorator-attached event actions

Before:

MyState.handler.stop_propagation().throttle(500)

After:

@event(stop_propagation=True, throttle=500)
def handler(self):
    pass

Confidence score: 5/5

  1. This PR is very safe to merge as it adds new functionality without breaking existing behavior
  2. Score is 5 because the changes are well-tested, maintain backward compatibility, and fix an existing bug in event action precedence
  3. The changes are focused and well-contained within the event handling system

3 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jul 15, 2025

CodSpeed Performance Report

Merging #5574 will not alter performance

Comparing lendemor/event-decorator-enhancement (2c3ca72) with main (c5bfad4)

Summary

✅ 8 untouched benchmarks

Comment thread reflex/event.py
prevent_default: Whether to prevent the default behavior of the event.
throttle: Throttle the event handler to limit calls (in milliseconds).
debounce: Debounce the event handler to delay calls (in milliseconds).
temporal: Whether the event should be temporal.
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.

Suggested change
temporal: Whether the event should be temporal.
temporal: Whether the event should be dropped when the backend is down.

@adhami3310 adhami3310 merged commit ec40c48 into main Jul 17, 2025
41 checks passed
@adhami3310 adhami3310 deleted the lendemor/event-decorator-enhancement branch July 17, 2025 18:57
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.

Set default actions on event handlers with rx.event()

3 participants