edifice.register_props

class edifice.register_props(f)[source]

Decorator for Component __init__ method to record props.

This decorator will record all arguments (both vector and keyword arguments) of the __init__ function as belonging to the props of the component. It will call Component.register_props to store these arguments in the props field of the Component.

Arguments that begin with an underscore will be ignored.

Example:

class MyComponent(Component):

    @register_props
    def __init__(self, a, b=2, c="xyz", _d=None):
        pass

    def render(self):
        return View()(
            Label(self.props.a),
            Label(self.props.b),
            Label(self.props.c),
        )

MyComponent(5, c=”w”) will then have props.a=5, props.b=2, and props.c=”w”. props._d is undefined

Parameters

f – the __init__ function of a Component subclass

Returns

decorated function