refactor: fix component recursion (#936)

This commit is contained in:
Juro Oravec 2025-02-01 17:19:21 +01:00 committed by GitHub
parent e105500350
commit 588053803d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 1549 additions and 464 deletions

View 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>
"""