nextpy icon indicating copy to clipboard operation
nextpy copied to clipboard

Introduce @xt.method Decorator for AI Code Generation Compatibility

Open anubrag opened this issue 1 year ago • 0 comments

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.

anubrag avatar Jan 16 '24 10:01 anubrag