[core/events] simplify args/kwargs detection
This commit is contained in:
parent
86fb4c38ea
commit
9cadcee844
1 changed files with 4 additions and 4 deletions
|
@ -3,7 +3,7 @@ __callbacks = {}
|
||||||
|
|
||||||
def register(event, callback, *args, **kwargs):
|
def register(event, callback, *args, **kwargs):
|
||||||
cb = callback
|
cb = callback
|
||||||
if len(args) + len(kwargs) > 0:
|
if args or kwargs:
|
||||||
cb = lambda: callback(*args, **kwargs)
|
cb = lambda: callback(*args, **kwargs)
|
||||||
|
|
||||||
__callbacks.setdefault(event, []).append(cb)
|
__callbacks.setdefault(event, []).append(cb)
|
||||||
|
@ -19,10 +19,10 @@ def trigger(event, *args, **kwargs):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for callback in cb:
|
for callback in cb:
|
||||||
if len(args) + len(kwargs) == 0:
|
if args or kwargs:
|
||||||
callback()
|
|
||||||
else:
|
|
||||||
callback(*args, **kwargs)
|
callback(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
callback()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue