Skip to content

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

@DonnC

Description

@DonnC

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions