Skip to content

Commit 819e25d

Browse files
committed
rename configure to create_router
1 parent f049d67 commit 819e25d

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

Diff for: idom_router/router.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
from typing_extensions import Protocol # type: ignore
2020

2121

22-
class RoutesConstructor(Protocol):
22+
class RouterConstructor(Protocol):
2323
def __call__(self, *routes: Route) -> ComponentType:
2424
...
2525

2626

27-
def configure(
27+
def create_router(
2828
implementation: BackendImplementation[Any] | Callable[[], Location]
29-
) -> RoutesConstructor:
29+
) -> RouterConstructor:
3030
if isinstance(implementation, BackendImplementation):
3131
use_location = implementation.use_location
3232
elif callable(implementation):
@@ -38,7 +38,7 @@ def configure(
3838
)
3939

4040
@component
41-
def routes(*routes: Route) -> ComponentType | None:
41+
def router(*routes: Route) -> ComponentType | None:
4242
initial_location = use_location()
4343
location, set_location = use_state(initial_location)
4444
compiled_routes = use_memo(
@@ -58,7 +58,7 @@ def routes(*routes: Route) -> ComponentType | None:
5858
)
5959
return None
6060

61-
return routes
61+
return router
6262

6363

6464
@dataclass

Diff for: tests/test_router.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from idom_router import (
66
Route,
7-
RoutesConstructor,
8-
configure,
7+
RouterConstructor,
8+
create_router,
99
link,
1010
use_location,
1111
use_params,
@@ -14,20 +14,20 @@
1414

1515

1616
@pytest.fixture
17-
def routes(backend: BackendFixture):
18-
return configure(backend.implementation)
17+
def router(backend: BackendFixture):
18+
return create_router(backend.implementation)
1919

2020

21-
def test_configure(backend):
22-
configure(backend.implementation)
23-
configure(backend.implementation.use_location)
21+
def test_create_router(backend):
22+
create_router(backend.implementation)
23+
create_router(backend.implementation.use_location)
2424
with pytest.raises(
2525
TypeError, match="Expected a 'BackendImplementation' or 'use_location' hook"
2626
):
27-
configure(None)
27+
create_router(None)
2828

2929

30-
async def test_simple_router(display: DisplayFixture, routes: RoutesConstructor):
30+
async def test_simple_router(display: DisplayFixture, router: RouterConstructor):
3131
def make_location_check(path, *routes):
3232
name = path.lstrip("/").replace("/", "-")
3333

@@ -40,7 +40,7 @@ def check_location():
4040

4141
@component
4242
def sample():
43-
return routes(
43+
return router(
4444
make_location_check("/a"),
4545
make_location_check("/b"),
4646
make_location_check("/c"),
@@ -68,10 +68,10 @@ def sample():
6868
assert not await root_element.inner_html()
6969

7070

71-
async def test_nested_routes(display: DisplayFixture, routes: RoutesConstructor):
71+
async def test_nested_routes(display: DisplayFixture, router: RouterConstructor):
7272
@component
7373
def sample():
74-
return routes(
74+
return router(
7575
Route(
7676
"/a",
7777
html.h1({"id": "a"}, "A"),
@@ -94,13 +94,13 @@ def sample():
9494
await display.page.wait_for_selector(selector)
9595

9696

97-
async def test_navigate_with_link(display: DisplayFixture, routes: RoutesConstructor):
97+
async def test_navigate_with_link(display: DisplayFixture, router: RouterConstructor):
9898
render_count = Ref(0)
9999

100100
@component
101101
def sample():
102102
render_count.current += 1
103-
return routes(
103+
return router(
104104
Route("/", link({"id": "root"}, "Root", to="/a")),
105105
Route("/a", link({"id": "a"}, "A", to="/b")),
106106
Route("/b", link({"id": "b"}, "B", to="/c")),
@@ -121,7 +121,7 @@ def sample():
121121
assert render_count.current == 1
122122

123123

124-
async def test_use_params(display: DisplayFixture, routes: RoutesConstructor):
124+
async def test_use_params(display: DisplayFixture, router: RouterConstructor):
125125
expected_params = {}
126126

127127
@component
@@ -131,7 +131,7 @@ def check_params():
131131

132132
@component
133133
def sample():
134-
return routes(
134+
return router(
135135
Route(
136136
"/first/{first:str}",
137137
check_params(),
@@ -157,7 +157,7 @@ def sample():
157157
await display.page.wait_for_selector("#success")
158158

159159

160-
async def test_use_query(display: DisplayFixture, routes: RoutesConstructor):
160+
async def test_use_query(display: DisplayFixture, router: RouterConstructor):
161161
expected_query = {}
162162

163163
@component
@@ -167,7 +167,7 @@ def check_query():
167167

168168
@component
169169
def sample():
170-
return routes(Route("/", check_query()))
170+
return router(Route("/", check_query()))
171171

172172
await display.show(sample)
173173

0 commit comments

Comments
 (0)