Skip to content

Commit 4f5b780

Browse files
committed
Re-add 'reactpy.backend.hooks' with deprecation warnings
1 parent 942ad6a commit 4f5b780

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import MutableMapping
4+
from typing import Any
5+
6+
from reactpy._warnings import warn
7+
from reactpy.backend.types import Connection, Location
8+
from reactpy.core.hooks import ConnectionContext, use_context
9+
10+
11+
def use_connection() -> Connection[Any]:
12+
"""Get the current :class:`~reactpy.backend.types.Connection`."""
13+
warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ",
14+
"Call use_connection in reactpy.core.hooks instead.", DeprecationWarning)
15+
16+
conn = use_context(ConnectionContext)
17+
if conn is None: # nocov
18+
msg = "No backend established a connection."
19+
raise RuntimeError(msg)
20+
return conn
21+
22+
23+
def use_scope() -> MutableMapping[str, Any]:
24+
"""Get the current :class:`~reactpy.backend.types.Connection`'s scope."""
25+
warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ",
26+
"Call use_scope in reactpy.core.hooks instead.", DeprecationWarning)
27+
28+
return use_connection().scope
29+
30+
31+
def use_location() -> Location:
32+
"""Get the current :class:`~reactpy.backend.types.Connection`'s location."""
33+
warn("The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ",
34+
"Call use_location in reactpy.core.hooks instead.", DeprecationWarning)
35+
36+
return use_connection().location

0 commit comments

Comments
 (0)