diff --git a/idom_router/__init__.py b/idom_router/__init__.py index 0598a4a..2ccf316 100644 --- a/idom_router/__init__.py +++ b/idom_router/__init__.py @@ -3,8 +3,8 @@ from .router import ( Route, - RoutesConstructor, - configure, + RouterConstructor, + create_router, link, use_location, use_params, @@ -12,10 +12,10 @@ ) __all__ = [ - "configure", + "create_router", "link", "Route", - "RoutesConstructor", + "RouterConstructor", "use_location", "use_params", "use_query", diff --git a/idom_router/router.py b/idom_router/router.py index 6a68c2c..af6c84f 100644 --- a/idom_router/router.py +++ b/idom_router/router.py @@ -19,14 +19,14 @@ from typing_extensions import Protocol # type: ignore -class RoutesConstructor(Protocol): +class RouterConstructor(Protocol): def __call__(self, *routes: Route) -> ComponentType: ... -def configure( +def create_router( implementation: BackendImplementation[Any] | Callable[[], Location] -) -> RoutesConstructor: +) -> RouterConstructor: if isinstance(implementation, BackendImplementation): use_location = implementation.use_location elif callable(implementation): @@ -38,7 +38,7 @@ def configure( ) @component - def routes(*routes: Route) -> ComponentType | None: + def router(*routes: Route) -> ComponentType | None: initial_location = use_location() location, set_location = use_state(initial_location) compiled_routes = use_memo( @@ -58,7 +58,7 @@ def routes(*routes: Route) -> ComponentType | None: ) return None - return routes + return router @dataclass diff --git a/tests/test_router.py b/tests/test_router.py index ee83f81..378ba28 100644 --- a/tests/test_router.py +++ b/tests/test_router.py @@ -4,8 +4,8 @@ from idom_router import ( Route, - RoutesConstructor, - configure, + RouterConstructor, + create_router, link, use_location, use_params, @@ -14,20 +14,20 @@ @pytest.fixture -def routes(backend: BackendFixture): - return configure(backend.implementation) +def router(backend: BackendFixture): + return create_router(backend.implementation) -def test_configure(backend): - configure(backend.implementation) - configure(backend.implementation.use_location) +def test_create_router(backend): + create_router(backend.implementation) + create_router(backend.implementation.use_location) with pytest.raises( TypeError, match="Expected a 'BackendImplementation' or 'use_location' hook" ): - configure(None) + create_router(None) -async def test_simple_router(display: DisplayFixture, routes: RoutesConstructor): +async def test_simple_router(display: DisplayFixture, router: RouterConstructor): def make_location_check(path, *routes): name = path.lstrip("/").replace("/", "-") @@ -40,7 +40,7 @@ def check_location(): @component def sample(): - return routes( + return router( make_location_check("/a"), make_location_check("/b"), make_location_check("/c"), @@ -68,10 +68,10 @@ def sample(): assert not await root_element.inner_html() -async def test_nested_routes(display: DisplayFixture, routes: RoutesConstructor): +async def test_nested_routes(display: DisplayFixture, router: RouterConstructor): @component def sample(): - return routes( + return router( Route( "/a", html.h1({"id": "a"}, "A"), @@ -94,13 +94,13 @@ def sample(): await display.page.wait_for_selector(selector) -async def test_navigate_with_link(display: DisplayFixture, routes: RoutesConstructor): +async def test_navigate_with_link(display: DisplayFixture, router: RouterConstructor): render_count = Ref(0) @component def sample(): render_count.current += 1 - return routes( + return router( Route("/", link({"id": "root"}, "Root", to="/a")), Route("/a", link({"id": "a"}, "A", to="/b")), Route("/b", link({"id": "b"}, "B", to="/c")), @@ -121,7 +121,7 @@ def sample(): assert render_count.current == 1 -async def test_use_params(display: DisplayFixture, routes: RoutesConstructor): +async def test_use_params(display: DisplayFixture, router: RouterConstructor): expected_params = {} @component @@ -131,7 +131,7 @@ def check_params(): @component def sample(): - return routes( + return router( Route( "/first/{first:str}", check_params(), @@ -157,7 +157,7 @@ def sample(): await display.page.wait_for_selector("#success") -async def test_use_query(display: DisplayFixture, routes: RoutesConstructor): +async def test_use_query(display: DisplayFixture, router: RouterConstructor): expected_query = {} @component @@ -167,7 +167,7 @@ def check_query(): @component def sample(): - return routes(Route("/", check_query())) + return router(Route("/", check_query())) await display.show(sample)