duck.html.components.utils.staticΒΆ

Module for creating static components.

Module ContentsΒΆ

FunctionsΒΆ

StaticComponent

This is a nested function which you can use directly with component classes without the need of using static_component decorator.

static_component

Decorator for declaring static components.

APIΒΆ

duck.html.components.utils.static.StaticComponent(component_cls: Type, **static_options)[source]ΒΆ

This is a nested function which you can use directly with component classes without the need of using static_component decorator.

Example:

static_btn_func = StaticComponent(
    Button,
    cache_targets=["id", "text"],
) # Returns function for retrieving or creating the button instance.

btn = statc_btn_func(id="my-btn", text="Hello world")
btn.is_from_cache() # Returns False for the first time and True otherwise
btn.is_a_copy() # Returns True by default.
btn.is_a_copy() # True if not isinstance of Page component
duck.html.components.utils.static.static_component(use_caching: bool = True, cache_targets: Optional[List[Union[str, Callable]]] = None, cache_backend: Optional[Any] = None, cache_expiry: Optional[float] = None, cache_namespace: Optional[Union[str, Callable]] = None, cache_ignore_args: Optional[List[int]] = None, cache_ignore_kwargs: Optional[List[str]] = None, skip_cache_attr: str = 'skip_cache', on_cache_result: Optional[Callable] = None, return_copy: bool = True)[source]ΒΆ

Decorator for declaring static components.

Example:

@static_compoment()
class MyStaticButton(Button):
    pass

btn = MyStaticButton(text="hello world") # New instance
btn.is_frozen() # True
btn.is_from_cache() # False for the first time
btn.is_a_copy() # True if not isinstance of Page component

btn = MyStaticButton(text="hello world")
btn.is_from_cache() # True

Do help on cached_component decorator for more information.