Skip to content

Commit 6dea8b3

Browse files
committed
move standalone to executors module
1 parent 58a4e37 commit 6dea8b3

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

src/reactpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from reactpy import asgi, config, logging, types, web, widgets
22
from reactpy._html import html
3+
from reactpy.asgi.executors.standalone import ReactPy
34
from reactpy.asgi.middleware import ReactPyMiddleware
4-
from reactpy.asgi.standalone import ReactPy
55
from reactpy.core import hooks
66
from reactpy.core.component import component
77
from reactpy.core.events import event

src/reactpy/asgi/executors/__init__.py

Whitespace-only changes.

src/reactpy/asgi/standalone.py renamed to src/reactpy/asgi/executors/standalone.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class ReactPyApp:
151151
to a user provided ASGI app."""
152152

153153
parent: ReactPy
154-
_cached_index_html = ""
154+
_index_html = ""
155155
_etag = ""
156156
_last_modified = ""
157157

@@ -173,8 +173,8 @@ async def __call__(
173173
return
174174

175175
# Store the HTTP response in memory for performance
176-
if not self._cached_index_html:
177-
self.process_index_html()
176+
if not self._index_html:
177+
self.render_index_template()
178178

179179
# Response headers for `index.html` responses
180180
request_headers = dict(scope["headers"])
@@ -183,7 +183,7 @@ async def __call__(
183183
"last-modified": self._last_modified,
184184
"access-control-allow-origin": "*",
185185
"cache-control": "max-age=60, public",
186-
"content-length": str(len(self._cached_index_html)),
186+
"content-length": str(len(self._index_html)),
187187
"content-type": "text/html; charset=utf-8",
188188
**self.parent.extra_headers,
189189
}
@@ -203,12 +203,12 @@ async def __call__(
203203
return await response(scope, receive, send) # type: ignore
204204

205205
# Send the index.html
206-
response = ResponseHTML(self._cached_index_html, headers=response_headers)
206+
response = ResponseHTML(self._index_html, headers=response_headers)
207207
await response(scope, receive, send) # type: ignore
208208

209-
def process_index_html(self) -> None:
210-
"""Process the index.html and store the results in memory."""
211-
self._cached_index_html = (
209+
def render_index_template(self) -> None:
210+
"""Process the index.html and store the results in this class."""
211+
self._index_html = (
212212
"<!doctype html>"
213213
f'<html lang="{self.parent.html_lang}">'
214214
f"{vdom_head_to_html(self.parent.html_head)}"
@@ -217,8 +217,7 @@ def process_index_html(self) -> None:
217217
"</body>"
218218
"</html>"
219219
)
220-
221-
self._etag = f'"{hashlib.md5(self._cached_index_html.encode(), usedforsecurity=False).hexdigest()}"'
220+
self._etag = f'"{hashlib.md5(self._index_html.encode(), usedforsecurity=False).hexdigest()}"'
222221
self._last_modified = formatdate(
223222
datetime.now(tz=timezone.utc).timestamp(), usegmt=True
224223
)

src/reactpy/testing/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import uvicorn
1111
from asgiref import typing as asgi_types
1212

13+
from reactpy.asgi.executors.standalone import ReactPy
1314
from reactpy.asgi.middleware import ReactPyMiddleware
14-
from reactpy.asgi.standalone import ReactPy
1515
from reactpy.config import REACTPY_TESTS_DEFAULT_TIMEOUT
1616
from reactpy.core.component import component
1717
from reactpy.core.hooks import use_callback, use_effect, use_state

tests/test_asgi/test_standalone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import reactpy
1010
from reactpy import html
11-
from reactpy.asgi.standalone import ReactPy
11+
from reactpy.asgi.executors.standalone import ReactPy
1212
from reactpy.testing import BackendFixture, DisplayFixture, poll
1313
from reactpy.testing.common import REACTPY_TESTS_DEFAULT_TIMEOUT
1414
from reactpy.types import Connection, Location

tests/test_web/test_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from servestatic import ServeStaticASGI
55

66
import reactpy
7-
from reactpy.asgi.standalone import ReactPy
7+
from reactpy.asgi.executors.standalone import ReactPy
88
from reactpy.testing import (
99
BackendFixture,
1010
DisplayFixture,

0 commit comments

Comments
 (0)