Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5b8862

Browse files
committedJun 21, 2024·
support multi-file pyscript components
1 parent bc58040 commit b5b8862

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed
 

‎src/reactpy_django/templatetags/reactpy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ def validate_host(host: str):
210210
@register.inclusion_tag("reactpy/pyscript_component.html", takes_context=True)
211211
def pyscript_component(
212212
context: template.RequestContext,
213-
file_path: str,
213+
*file_paths: str,
214214
initial: str | VdomDict | ComponentType = "",
215215
root: str = "root",
216216
):
217217
uuid = uuid4().hex
218218
request: HttpRequest | None = context.get("request")
219219
initial = vdom_or_component_to_string(initial, request=request, uuid=uuid)
220-
executor = render_pyscript_template(file_path, uuid, root)
220+
executor = render_pyscript_template(file_paths, uuid, root)
221221

222222
return {
223223
"pyscript_executor": executor,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from reactpy import component, html
2+
3+
4+
@component
5+
def child():
6+
return html.div({"id": "multifile-child"}, "Multifile child")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# pylint: disable=used-before-assignment
2+
from typing import TYPE_CHECKING
3+
4+
from reactpy import component, html
5+
6+
if TYPE_CHECKING:
7+
from .multifile_child import child
8+
9+
10+
@component
11+
def root():
12+
return html.div({"id": "multifile-parent"}, "Multifile root", child())

‎tests/test_app/templates/pyscript.html

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ <h1>ReactPy PyScript Test Page</h1>
1818
<hr>
1919
{% pyscript_component "./test_app/pyscript/components/custom_root.py" root="main" %}
2020
<hr>
21+
{% pyscript_component "./test_app/pyscript/components/multifile_parent.py" "./test_app/pyscript/components/multifile_child.py" %}
22+
<hr>
2123
{% pyscript_component "./test_app/pyscript/components/counter.py" %}
2224
<hr>
2325
{% component "test_app.pyscript.components.server_side.parent" %}

‎tests/test_app/tests/test_components.py

+2
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ def test_pyscript_components(self):
686686
new_page.wait_for_selector("#hello-world-loading")
687687
new_page.wait_for_selector("#hello-world")
688688
new_page.wait_for_selector("#custom-root")
689+
new_page.wait_for_selector("#multifile-parent")
690+
new_page.wait_for_selector("#multifile-child")
689691

690692
new_page.wait_for_selector("#counter")
691693
new_page.wait_for_selector("#counter pre[data-value='0']")

0 commit comments

Comments
 (0)
Please sign in to comment.