Skip to content

Commit ea46a94

Browse files
committed
self review
1 parent c9d16c3 commit ea46a94

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

docs/source/about/changelog.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Unreleased
1616
----------
1717

1818
**Added**
19-
- :pull:`1113` - Added ``reactpy.asgi.ReactPy`` that can be used to run ReactPy in standalone mode via ASGI.
20-
- :pull:`1269` - Added ``reactpy.asgi.ReactPyPyodide`` that can be used to run ReactPy in standalone mode via ASGI, but rendered entirely client-sided.
21-
- :pull:`1113` - Added ``reactpy.asgi.ReactPyMiddleware`` that can be used to utilize ReactPy within any ASGI compatible framework.
19+
- :pull:`1113` - Added ``reactpy.executors.asgi.ReactPy`` that can be used to run ReactPy in standalone mode via ASGI.
20+
- :pull:`1269` - Added ``reactpy.executors.asgi.ReactPyPyodide`` that can be used to run ReactPy in standalone mode via ASGI, but rendered entirely client-sided.
21+
- :pull:`1113` - Added ``reactpy.executors.asgi.ReactPyMiddleware`` that can be used to utilize ReactPy within any ASGI compatible framework.
2222
- :pull:`1113` :pull:`1269` - Added ``reactpy.templatetags.Jinja`` that can be used alongside ``ReactPyMiddleware`` to embed several ReactPy components into your existing application. This includes the following template tags: ``{% component %}``, ``{% pyscript_component %}``, and ``{% pyscript_setup %}``.
2323
- :pull:`1269` - Added ``reactpy.pyscript_component`` that can be used to embed ReactPy components into your existing application.
2424
- :pull:`1113` - Added ``uvicorn`` and ``jinja`` installation extras (for example ``pip install reactpy[jinja]``).

src/reactpy/executors/asgi/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def match_web_modules_path(self, scope: asgi_types.HTTPScope) -> bool:
136136

137137
def match_extra_paths(self, scope: asgi_types.Scope) -> AsgiApp | None:
138138
# Custom defined routes are unused by default to encourage users to handle
139-
# routing within their root ASGI application.
139+
# routing within their ASGI framework of choice.
140140
return None
141141

142142

src/reactpy/executors/asgi/pyscript.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
are not applicable to CSR and will have no effect.
6565
"""
6666
ReactPyMiddleware.__init__(
67-
self, app=ReactPyPyodideApp(self), root_components=[], **settings
67+
self, app=ReactPyPyscriptApp(self), root_components=[], **settings
6868
)
6969
if not file_paths:
7070
raise ValueError("At least one component file path must be provided.")
@@ -85,8 +85,8 @@ def match_dispatch_path(self, scope: WebSocketScope) -> bool: # pragma: no cove
8585

8686

8787
@dataclass
88-
class ReactPyPyodideApp(ReactPyApp):
89-
"""ReactPy's standalone ASGI application for Client-Side Rendering (CSR)."""
88+
class ReactPyPyscriptApp(ReactPyApp):
89+
"""ReactPy's standalone ASGI application for Client-Side Rendering (CSR) via PyScript."""
9090

9191
parent: ReactPyPyscript
9292
_index_html = ""

src/reactpy/executors/asgi/standalone.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ def __init__(
7171
extra_py = pyscript_options.get("extra_py", [])
7272
extra_js = pyscript_options.get("extra_js", {})
7373
config = pyscript_options.get("config", {})
74-
self.html_head["children"].append( # type: ignore
75-
html_to_vdom(pyscript_setup_html(extra_py, extra_js, config))
74+
pyscript_head_vdom = html_to_vdom(
75+
pyscript_setup_html(extra_py, extra_js, config)
7676
)
77+
pyscript_head_vdom["tagName"] = ""
78+
self.html_head["children"].append(pyscript_head_vdom) # type: ignore
7779

7880
def match_dispatch_path(self, scope: asgi_types.WebSocketScope) -> bool:
7981
"""Method override to remove `dotted_path` from the dispatcher URL."""

src/reactpy/pyscript/components.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from reactpy import component, hooks
77
from reactpy.pyscript.utils import pyscript_component_html
8-
from reactpy.types import ComponentType
8+
from reactpy.types import ComponentType, Key
99
from reactpy.utils import html_to_vdom
1010

1111
if TYPE_CHECKING:
@@ -30,17 +30,18 @@ def _pyscript_component(
3030
set_rendered(True)
3131
return None
3232

33-
result = html_to_vdom(
33+
component_vdom = html_to_vdom(
3434
pyscript_component_html(tuple(str(fp) for fp in file_paths), initial, root)
3535
)
36-
result["tagName"] = ""
37-
return result
36+
component_vdom["tagName"] = ""
37+
return component_vdom
3838

3939

4040
def pyscript_component(
4141
*file_paths: str | Path,
4242
initial: str | VdomDict | ComponentType = "",
4343
root: str = "root",
44+
key: Key | None = None,
4445
) -> ComponentType:
4546
"""
4647
Args:
@@ -57,4 +58,5 @@ def pyscript_component(
5758
*file_paths,
5859
initial=initial,
5960
root=root,
61+
key=key,
6062
)

src/reactpy/pyscript/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def minify_python(source: str) -> str:
3131
# Remove comments
3232
source = re.sub(r"#.*\n", "\n", source)
3333
# Remove docstrings
34-
source = re.sub(r'""".*?"""', "", source, flags=re.DOTALL)
35-
# Remove extra newlines
34+
source = re.sub(r'\n\s*""".*?"""', "", source, flags=re.DOTALL)
35+
# Remove excess newlines
3636
source = re.sub(r"\n+", "\n", source)
3737
# Remove empty lines
3838
source = re.sub(r"\s+\n", "\n", source)

0 commit comments

Comments
 (0)