INNER CODE UNIT · Python
__init_subclass__
volfpeter/htmy · htmy/core.py:106
def __init_subclass__(cls) -> None:
if cls.mro()[1] == ContextAware:
cls._base_context_type = cls
def in_context(self, *children: ComponentType) -> WithContext:
"""
Creates a context provider component that renders the given children using this
instance in its context.
"""
return WithContext(*children, context=self.to_context())
def to_context(self) -> Context:
"""
Creates a context with this instance in it.
See the context registration rules in the class documentation for more information.
"""
result: dict[ContextKey, ContextValue] = {type(self): self}