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

Introduce @xt.method Decorator for AI Code Generation Compatibility #123

Open
anubrag opened this issue Jan 16, 2024 · 0 comments
Open

Introduce @xt.method Decorator for AI Code Generation Compatibility #123

anubrag opened this issue Jan 16, 2024 · 0 comments

Comments

@anubrag
Copy link
Collaborator

anubrag commented Jan 16, 2024

We could introduce @xt.method decorator in Nextpy for defining event handlers within state classes. This feature is intended to enhance code readability, standardize the declaration of methods handling state changes, and align with AI code generation practices.

Current Behavior

Currently, Nextpy requires methods within state classes to be defined directly, without specific decorators. This approach is functional but does not distinguish between regular methods and event handlers explicitly designed to modify the state.

Proposed Behavior

The introduction of the @xt.method decorator would allow developers to clearly mark methods in the state class as event handlers. This not only improves code readability but also aligns with AI code generation patterns, where such decorators are often included by default. It could also facilitate additional framework optimizations or checks.

For example:

@xt.method(ToDoState)
def delete_todo(state, todo):
    state.todos.remove(todo)

Benefits

  • Improved Code Readability and Maintainability: Clearly distinguishes state-modifying methods from regular class methods.
  • Alignment with AI Code Generation: Aligns with default practices of AI code generation tools, which often include method decorators in their outputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant