Skip to content

Commit df3c0f7

Browse files
committed
Move some project files around
1 parent f98881e commit df3c0f7

File tree

22 files changed

+145
-94
lines changed

22 files changed

+145
-94
lines changed

middleware.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from starlette.applications import Starlette
2+
from starlette.routing import Route
3+
from starlette.templating import Jinja2Templates
4+
5+
from reactpy import component, hooks, html
6+
from reactpy.backend.middleware import ReactPyMiddleware
7+
8+
templates = Jinja2Templates(
9+
directory="templates", extensions=["reactpy.jinja.ReactPyTemplateTag"]
10+
)
11+
12+
13+
@component
14+
def Counter():
15+
count, set_count = hooks.use_state(0)
16+
17+
def increment(event):
18+
set_count(count + 1)
19+
20+
return html.div(
21+
html.button({"onClick": increment}, "Increment"),
22+
html.p(f"Count: {count}"),
23+
)
24+
25+
26+
async def homepage(request):
27+
return templates.TemplateResponse(request, "index.html")
28+
29+
30+
app = Starlette(
31+
debug=True,
32+
routes=[
33+
Route("/", homepage),
34+
],
35+
)
36+
37+
app = ReactPyMiddleware(app, ["middleware.Counter"])

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ dependencies = [
3737
"asgiref >=3",
3838
"lxml >=4",
3939
"servestatic >=3.0.0",
40-
"jinja2 >=3",
4140
]
4241
dynamic = ["version"]
4342
urls.Changelog = "https://reactpy.dev/docs/about/changelog.html"
@@ -77,7 +76,7 @@ artifacts = []
7776
[project.optional-dependencies]
7877
# TODO: Nuke backends from the optional deps
7978
all = ["reactpy[jinja,uvicorn,testing]"]
80-
jinja = ["jinja2-simple-tags", "jinja2"]
79+
jinja = ["jinja2-simple-tags", "jinja2 >=3"]
8180
uvicorn = ["uvicorn[standard]"]
8281
testing = ["playwright"]
8382

src/reactpy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from reactpy import backend, config, logging, types, web, widgets
1+
from reactpy import asgi, config, logging, types, web, widgets
22
from reactpy._html import html
33
from reactpy.core import hooks
44
from reactpy.core.component import component
@@ -27,7 +27,7 @@
2727
__all__ = [
2828
"Layout",
2929
"Ref",
30-
"backend",
30+
"asgi",
3131
"component",
3232
"config",
3333
"create_context",
File renamed without changes.

src/reactpy/backend/middleware.py renamed to src/reactpy/asgi/middleware.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
from asgiref.compatibility import guarantee_single_callable
1515
from servestatic import ServeStaticASGI
1616

17-
from reactpy.backend.types import Connection, Location
18-
from reactpy.backend.utils import check_path, import_components
17+
from reactpy.asgi.utils import check_path, import_components
1918
from reactpy.config import REACTPY_WEB_MODULES_DIR
2019
from reactpy.core.hooks import ConnectionContext
2120
from reactpy.core.layout import Layout
2221
from reactpy.core.serve import serve_layout
23-
from reactpy.types import RootComponentConstructor
22+
from reactpy.types import Connection, Location, RootComponentConstructor
2423

2524
_logger = logging.getLogger(__name__)
2625

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from typing import Any, Callable
1010

1111
from reactpy import html
12-
from reactpy.backend.middleware import ReactPyMiddleware
13-
from reactpy.backend.utils import (
12+
from reactpy.asgi.middleware import ReactPyMiddleware
13+
from reactpy.asgi.utils import (
1414
dict_to_byte_list,
1515
http_response,
1616
replace_many,
File renamed without changes.

src/reactpy/backend/__init__.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/reactpy/backend/types.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/reactpy/core/hooks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
from typing_extensions import TypeAlias
2020

21-
from reactpy.backend.types import Connection, Location
2221
from reactpy.config import REACTPY_DEBUG_MODE
2322
from reactpy.core._life_cycle_hook import current_hook
2423
from reactpy.core.types import Context, Key, State, VdomDict
24+
from reactpy.types import Connection, Location
2525
from reactpy.utils import Ref
2626

2727
if not TYPE_CHECKING:
@@ -264,12 +264,12 @@ def use_connection() -> Connection[Any]:
264264

265265

266266
def use_scope() -> MutableMapping[str, Any]:
267-
"""Get the current :class:`~reactpy.backend.types.Connection`'s scope."""
267+
"""Get the current :class:`~reactpy.types.Connection`'s scope."""
268268
return use_connection().scope
269269

270270

271271
def use_location() -> Location:
272-
"""Get the current :class:`~reactpy.backend.types.Connection`'s location."""
272+
"""Get the current :class:`~reactpy.types.Connection`'s location."""
273273
return use_connection().location
274274

275275

0 commit comments

Comments
 (0)