feat: component URL (#1088)

* feat: allow to set defaults

* refactor: remove input validation and link to it

* feat: component URL

* refactor: fix linter errors

* refactor: fix linter errors + update examples to use Component.View..get

* docs: update comment

* refactor: revert change to hash_comp_cls

* docs: update comment
This commit is contained in:
Juro Oravec 2025-04-07 10:44:41 +02:00 committed by GitHub
parent 3555411f1e
commit a49f5e51dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 987 additions and 314 deletions

View file

@ -60,7 +60,9 @@ from django_components.extension import (
OnComponentInputContext,
extensions,
)
from django_components.extensions.view import ViewFn
from django_components.extensions.defaults import ComponentDefaults
from django_components.extensions.url import ComponentUrl
from django_components.extensions.view import ComponentView, ViewFn
from django_components.node import BaseNode
from django_components.perfutil.component import ComponentRenderer, component_context_cache, component_post_render
from django_components.perfutil.provide import register_provide_reference, unregister_provide_reference
@ -570,6 +572,19 @@ class Component(
"""
pass
# #####################################
# EXTENSIONS
# #####################################
# NOTE: These are the classes and instances added by defaults extensions. These fields
# are actually set at runtime, and so here they are only marked for typing.
Defaults: Type[ComponentDefaults]
defaults: ComponentDefaults
View: Type[ComponentView]
view: ComponentView
Url: Type[ComponentUrl]
url: ComponentUrl
# #####################################
# MISC
# #####################################
@ -899,6 +914,8 @@ class Component(
def as_view(cls, **initkwargs: Any) -> ViewFn:
"""
Shortcut for calling `Component.View.as_view` and passing component instance to it.
Read more on [Component views and URLs](../../concepts/fundamentals/component_views_urls).
"""
# NOTE: `Component.View` may not be available at the time that URLs are being