mirror of
https://github.com/django-components/django-components.git
synced 2025-08-07 07:48:00 +00:00
refecator: move defaults applying back to ext, raise on passing Slot to Slot, and docs cleanup (#1214)
* refecator: move defaults applying back to ext, raise on passing Slot to Slot, and docs cleanup * docs: fix typo
This commit is contained in:
parent
bae0f28813
commit
55b1c8bc62
14 changed files with 317 additions and 147 deletions
|
@ -56,7 +56,7 @@ from django_components.extension import (
|
|||
extensions,
|
||||
)
|
||||
from django_components.extensions.cache import ComponentCache
|
||||
from django_components.extensions.defaults import ComponentDefaults, apply_defaults, defaults_by_component
|
||||
from django_components.extensions.defaults import ComponentDefaults
|
||||
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
|
||||
|
@ -2798,22 +2798,11 @@ class Component(metaclass=ComponentMeta):
|
|||
|
||||
render_id = _gen_component_id()
|
||||
|
||||
# Apply defaults to missing or `None` values in `kwargs`
|
||||
defaults = defaults_by_component.get(comp_cls, None)
|
||||
if defaults is not None:
|
||||
apply_defaults(kwargs_dict, defaults)
|
||||
|
||||
# If user doesn't specify `Args`, `Kwargs`, `Slots` types, then we pass them in as plain
|
||||
# dicts / lists.
|
||||
args_inst = comp_cls.Args(*args_list) if comp_cls.Args is not None else args_list
|
||||
kwargs_inst = comp_cls.Kwargs(**kwargs_dict) if comp_cls.Kwargs is not None else kwargs_dict
|
||||
slots_inst = comp_cls.Slots(**slots_dict) if comp_cls.Slots is not None else slots_dict
|
||||
|
||||
component = comp_cls(
|
||||
id=render_id,
|
||||
args=args_inst,
|
||||
kwargs=kwargs_inst,
|
||||
slots=slots_inst,
|
||||
args=args_list,
|
||||
kwargs=kwargs_dict,
|
||||
slots=slots_dict,
|
||||
context=context,
|
||||
request=request,
|
||||
deps_strategy=deps_strategy,
|
||||
|
@ -2841,6 +2830,12 @@ class Component(metaclass=ComponentMeta):
|
|||
if result_override is not None:
|
||||
return result_override
|
||||
|
||||
# If user doesn't specify `Args`, `Kwargs`, `Slots` types, then we pass them in as plain
|
||||
# dicts / lists.
|
||||
component.args = comp_cls.Args(*args_list) if comp_cls.Args is not None else args_list
|
||||
component.kwargs = comp_cls.Kwargs(**kwargs_dict) if comp_cls.Kwargs is not None else kwargs_dict
|
||||
component.slots = comp_cls.Slots(**slots_dict) if comp_cls.Slots is not None else slots_dict
|
||||
|
||||
######################################
|
||||
# 2. Prepare component state
|
||||
######################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue