Skip to content

Commit

Permalink
feat: component method decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWii committed Jun 17, 2022
1 parent 282d825 commit af94217
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions integrity/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def run(self, event_name: str):
def setmethod(self, name: str, function: Callable[["Component"], Any]):
self.methods[name] = partial(function, self)

def method(self, arg):
def decorator(func):
self.setmethod(arg, func)
return func

if isinstance(arg, str):
return decorator
if callable(arg):
self.setmethod(arg.__name__, arg)
return arg

def __getattr__(self, key: str):
return self.methods[key]

Expand Down

0 comments on commit af94217

Please sign in to comment.