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

[feature-request] Enable class based method hooks #3

Open
DonnC opened this issue Jan 12, 2025 · 0 comments
Open

[feature-request] Enable class based method hooks #3

DonnC opened this issue Jan 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@DonnC
Copy link
Owner

DonnC commented Jan 12, 2025

Currently supported hooks are function based hooks.

It could make sense to support OOP, where some business logic might be in a certain class

Consider the approach like below

# example.hooks.todo.py
class ToDo(AbstractHookArgCls):
    # overriden to initiate current user arg
    def setup_args(self, arg: HookArg):
        self.arg = arg

    def save_todo(self):
       todo = self.arg.user_input
       self.db.save(todo)
       return self.arg
    
    # ..

Calling the hook in template

"SAVE-TODO-STAGE":
    type: text
    message: Enter the new todo
    on-receive: example.hooks.todo:ToDo.save_todo
    routes:
       "re:.*": "VIEW-TODOS-STAGE"
@DonnC DonnC added the enhancement New feature or request label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant