Add support for calling register as a decorator (#38)

This commit is contained in:
Emil Stenström 2021-02-27 16:38:16 +01:00 committed by GitHub
commit b9446c2818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -97,3 +97,20 @@ def is_slot_node(node):
# This variable represents the global component registry
registry = ComponentRegistry()
def register(name):
"""Class decorator to register a component.
Usage:
@register("my_component")
class MyComponent(component.Component):
...
"""
def decorator(component):
registry.register(name=name, component=component)
return component
return decorator