mirror of
https://github.com/django-components/django-components.git
synced 2025-08-31 03:07:19 +00:00
refactor: fix component recursion (#936)
This commit is contained in:
parent
e105500350
commit
588053803d
25 changed files with 1549 additions and 464 deletions
31
sampleproject/components/recursive.py
Normal file
31
sampleproject/components/recursive.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
from django_components import Component, register, types
|
||||
|
||||
|
||||
@register("recursive")
|
||||
class Recursive(Component):
|
||||
def get(self, request):
|
||||
import time
|
||||
time_before = time.time()
|
||||
output = self.render_to_response(
|
||||
kwargs={
|
||||
"depth": 0,
|
||||
},
|
||||
)
|
||||
time_after = time.time()
|
||||
print("TIME: ", time_after - time_before)
|
||||
return output
|
||||
|
||||
def get_context_data(self, depth: int = 0) -> Dict[str, Any]:
|
||||
return {"depth": depth + 1}
|
||||
|
||||
template: types.django_html = """
|
||||
<div id="recursive">
|
||||
depth: {{ depth }}
|
||||
<hr/>
|
||||
{% if depth <= 100 %}
|
||||
{% component "recursive" depth=depth / %}
|
||||
{% endif %}
|
||||
</div>
|
||||
"""
|
Loading…
Add table
Add a link
Reference in a new issue