original_docstring: Decorator turning a render function into a Component.
  
      Some components do not have internal state, and these components are often little more than
      a render function. Creating a Component class results in a lot of boiler plate code::
  
          class MySimpleComp(Component):
              @register_props
              def __init__(self, prop1, prop2, prop3):
                  super().__init__()
  
              def render(self):
                  # Only here is there actual logic.
  
      To cut down on the amount of boilerplate, you can use the make_component decorator::
  
          @make_component
          def MySimpleComp(self, prop1, prop2, prop3, children):
              # Here you put what you'd normally put in the render logic
              # Note that you can access prop1 via the variable, or via self.props
              return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
      Of course, you could have written::
  
          # No decorator
          def MySimpleComp(prop1, prop2, prop3):
              return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
      instead. The difference is, with the decorator, an actual Component object is created,
      which can be viewed, for example, in the inspector.
      If this component uses :doc:`State Values or State Managers</state>`,
      only this component and (possibly) its children will be re-rendered.
      If you don't use the decorator, the returned components are directly attached to the
      Component that called the function, and so any re-renders will have to start from that level.
  
      Args:
          f: the function to wrap. Its first argument must be self, and children must be one of its parameters.
      Returns:
          Component class.
      
docstring: Decorator turning a render function into a Component.
  Some components do not have internal state, and these components are often little more than
  a render function. Creating a Component class results in a lot of boiler plate code:.
  
  
  
  def render(self):
  Only here is there actual logic.
  
  To cut down on the amount of boilerplate, you can use the make_component decorator:.
  
  @make_component
  def MySimpleComp(self, prop1, prop2, prop3, children):
  Here you put what you'd normally put in the render logic
  Note that you can access prop1 via the variable, or via self.props
  return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
  Of course, you could have written:.
  
  
  
  instead. The difference is, with the decorator, an actual Component object is created,
  which can be viewed, for example, in the inspector.
  If this component uses :doc:`State Values or State Managers`,
  only this component and (possibly) its children will be re-rendered.
  If you don't use the decorator, the returned components are directly attached to the
  Component that called the function, and so any re-renders will have to start from that level.
docstring_tokens: Decorator turning a render function into a Component . Some components do not have internal state and these components are often little more than a render function . Creating a Component class results in a lot of boiler plate code : . def render ( self ) : Only here is there actual logic . To cut down on the amount of boilerplate you can use the make_component decorator : . @make_component def MySimpleComp ( self prop1 prop2 prop3 children ) : Here you put what you ' d normally put in the render logic Note that you can access prop1 via the variable or via self . props return View () ( Label ( prop1 ) Label ( self . prop2 ) Label ( prop3 )) Of course you could have written : . instead . The difference is with the decorator an actual Component object is created which can be viewed for example in the inspector . If this component uses : doc : ` State Values or State Managers ` only this component and ( possibly ) its children will be re - rendered . If you don ' t use the decorator the returned components are directly attached to the Component that called the function and so any re - renders will have to start from that level .
code: def make_component(f):
      """Decorator turning a render function into a Component.
  
      Some components do not have internal state, and these components are often little more than
      a render function. Creating a Component class results in a lot of boiler plate code::
  
          class MySimpleComp(Component):
              @register_props
              def __init__(self, prop1, prop2, prop3):
                  super().__init__()
  
              def render(self):
                  # Only here is there actual logic.
  
      To cut down on the amount of boilerplate, you can use the make_component decorator::
  
          @make_component
          def MySimpleComp(self, prop1, prop2, prop3, children):
              # Here you put what you'd normally put in the render logic
              # Note that you can access prop1 via the variable, or via self.props
              return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
      Of course, you could have written::
  
          # No decorator
          def MySimpleComp(prop1, prop2, prop3):
              return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
      instead. The difference is, with the decorator, an actual Component object is created,
      which can be viewed, for example, in the inspector.
      If this component uses :doc:`State Values or State Managers</state>`,
      only this component and (possibly) its children will be re-rendered.
      If you don't use the decorator, the returned components are directly attached to the
      Component that called the function, and so any re-renders will have to start from that level.
  
      Args:
          f: the function to wrap. Its first argument must be self, and children must be one of its parameters.
      Returns:
          Component class.
      """
      varnames = f.__code__.co_varnames[1:]
      signature = inspect.signature(f).parameters
      defaults = {
          k: v.default for k, v in signature.items() if v.default is not inspect.Parameter.empty and k[0] != "_"
      }
      if "children" not in signature:
          raise ValueError("All function components must take children as last argument.")
  
      class MyComponent(Component):
  
          def __init__(self, *args, **kwargs):
              name_to_val = defaults.copy()
              name_to_val.update(filter((lambda tup: (tup[0][0] != "_")), zip(varnames, args)))
              name_to_val.update(((k, v) for (k, v) in kwargs.items() if k[0] != "_"))
              name_to_val["children"] = name_to_val.get("children") or []
              self.register_props(name_to_val)
              super().__init__()
  
          def render(self):
              return f(self, **self.props._d)
      MyComponent.__name__ = f.__name__
      return MyComponent
code_tokens: def make_component ( f ) : varnames = f . __code__ . co_varnames [ 1 : ] signature = inspect . signature ( f ) . parameters defaults = { k : v . default for k , v in signature . items ( ) if v . default is not inspect . Parameter . empty and k [ 0 ] != "_" } if "children" not in signature : raise ValueError ( "All function components must take children as last argument." ) class MyComponent ( Component ) : def __init__ ( self , * args , ** kwargs ) : name_to_val = defaults . copy ( ) name_to_val . update ( filter ( ( lambda tup : ( tup [ 0 ] [ 0 ] != "_" ) ) , zip ( varnames , args ) ) ) name_to_val . update ( ( ( k , v ) for ( k , v ) in kwargs . items ( ) if k [ 0 ] != "_" ) ) name_to_val [ "children" ] = name_to_val . get ( "children" ) or [ ] self . register_props ( name_to_val ) super ( ) . __init__ ( ) def render ( self ) : return f ( self , ** self . props . _d ) MyComponent . __name__ = f . __name__ return MyComponent
short_docstring: Decorator turning a render function into a Component.
short_docstring_tokens: Decorator turning a render function into a Component .
comment: """Decorator turning a render function into a Component.
  
      Some components do not have internal state, and these components are often little more than
      a render function. Creating a Component class results in a lot of boiler plate code::
  
          class MySimpleComp(Component):
              @register_props
              def __init__(self, prop1, prop2, prop3):
                  super().__init__()
  
              def render(self):
                  # Only here is there actual logic.
  
      To cut down on the amount of boilerplate, you can use the make_component decorator::
  
          @make_component
          def MySimpleComp(self, prop1, prop2, prop3, children):
              # Here you put what you'd normally put in the render logic
              # Note that you can access prop1 via the variable, or via self.props
              return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
      Of course, you could have written::
  
          # No decorator
          def MySimpleComp(prop1, prop2, prop3):
              return View()(Label(prop1), Label(self.prop2), Label(prop3))
  
      instead. The difference is, with the decorator, an actual Component object is created,
      which can be viewed, for example, in the inspector.
      If this component uses :doc:`State Values or State Managers</state>`,
      only this component and (possibly) its children will be re-rendered.
      If you don't use the decorator, the returned components are directly attached to the
      Component that called the function, and so any re-renders will have to start from that level.
  
      Args:
          f: the function to wrap. Its first argument must be self, and children must be one of its parameters.
      Returns:
          Component class.
      """