mirror of
https://github.com/django-components/django-components.git
synced 2025-07-24 16:53:47 +00:00
fix/263 performance regression (#264)
* Replace deep copies in Component.render * Add 2nd example component to sampleproject
This commit is contained in:
parent
2cfc7285e1
commit
6f49339c91
4 changed files with 32 additions and 7 deletions
|
@ -1,4 +1,3 @@
|
||||||
import copy
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
ClassVar,
|
ClassVar,
|
||||||
|
@ -126,12 +125,13 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
||||||
return self._outer_context or {}
|
return self._outer_context or {}
|
||||||
|
|
||||||
def get_updated_fill_stacks(self, context):
|
def get_updated_fill_stacks(self, context):
|
||||||
current_fill_stacks = context.get(FILLED_SLOTS_CONTEXT_KEY, None)
|
current_fill_stacks: Optional[Dict[str, List[FillNode]]] = context.get(
|
||||||
updated_fill_stacks = (
|
FILLED_SLOTS_CONTEXT_KEY, None
|
||||||
copy.deepcopy(current_fill_stacks)
|
|
||||||
if current_fill_stacks is not None
|
|
||||||
else {}
|
|
||||||
)
|
)
|
||||||
|
updated_fill_stacks = {}
|
||||||
|
if current_fill_stacks:
|
||||||
|
for name, fill_nodes in current_fill_stacks.items():
|
||||||
|
updated_fill_stacks[name] = list(fill_nodes)
|
||||||
for name, fill in self.instance_fills.items():
|
for name, fill in self.instance_fills.items():
|
||||||
if name in updated_fill_stacks:
|
if name in updated_fill_stacks:
|
||||||
updated_fill_stacks[name].append(fill)
|
updated_fill_stacks[name].append(fill)
|
||||||
|
|
|
@ -1 +1,13 @@
|
||||||
<div class="calendar-component">Today's date is <span>{{ date }}</span></div>
|
<div class="calendar-component">
|
||||||
|
<div>Today's date is <span>{{ date }}</span></div>
|
||||||
|
<div>Your to-dos:</div>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
{% component_block "todo" %}
|
||||||
|
{% fill "todo_text" %}
|
||||||
|
Stop forgetting the milk!
|
||||||
|
{% endfill %}
|
||||||
|
{% endcomponent_block %}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
4
sampleproject/components/todo/todo.html
Normal file
4
sampleproject/components/todo/todo.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<div class="todo-item">
|
||||||
|
{% slot "todo_text" %}
|
||||||
|
{% endslot %}
|
||||||
|
</div>
|
9
sampleproject/components/todo/todo.py
Normal file
9
sampleproject/components/todo/todo.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from django_components import component
|
||||||
|
|
||||||
|
|
||||||
|
@component.register("todo")
|
||||||
|
class Calendar(component.Component):
|
||||||
|
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||||
|
# `[project root]/components` dir. To customize which template to use based on context
|
||||||
|
# you can override def get_template_name() instead of specifying the below variable.
|
||||||
|
template_name = "todo/todo.html"
|
Loading…
Add table
Add a link
Reference in a new issue