|
1 |
| -from __future__ import annotations |
| 1 | +from __future__ import annotations # nocov |
2 | 2 |
|
3 |
| -from collections.abc import MutableMapping |
4 |
| -from typing import Any |
| 3 | +from collections.abc import MutableMapping # nocov |
| 4 | +from typing import Any # nocov |
5 | 5 |
|
6 |
| -from reactpy.backend.types import Connection, Location |
7 |
| -from reactpy.core.hooks import create_context, use_context |
8 |
| -from reactpy.core.types import Context |
| 6 | +from reactpy._warnings import warn # nocov |
| 7 | +from reactpy.backend.types import Connection, Location # nocov |
| 8 | +from reactpy.core.hooks import ConnectionContext, use_context # nocov |
9 | 9 |
|
10 |
| -# backend implementations should establish this context at the root of an app |
11 |
| -ConnectionContext: Context[Connection[Any] | None] = create_context(None) |
12 | 10 |
|
13 |
| - |
14 |
| -def use_connection() -> Connection[Any]: |
| 11 | +def use_connection() -> Connection[Any]: # nocov |
15 | 12 | """Get the current :class:`~reactpy.backend.types.Connection`."""
|
| 13 | + warn( |
| 14 | + "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", |
| 15 | + "Call reactpy.use_connection instead.", |
| 16 | + DeprecationWarning, |
| 17 | + ) |
| 18 | + |
16 | 19 | conn = use_context(ConnectionContext)
|
17 |
| - if conn is None: # nocov |
| 20 | + if conn is None: |
18 | 21 | msg = "No backend established a connection."
|
19 | 22 | raise RuntimeError(msg)
|
20 | 23 | return conn
|
21 | 24 |
|
22 | 25 |
|
23 |
| -def use_scope() -> MutableMapping[str, Any]: |
| 26 | +def use_scope() -> MutableMapping[str, Any]: # nocov |
24 | 27 | """Get the current :class:`~reactpy.backend.types.Connection`'s scope."""
|
| 28 | + warn( |
| 29 | + "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", |
| 30 | + "Call reactpy.use_scope instead.", |
| 31 | + DeprecationWarning, |
| 32 | + ) |
| 33 | + |
25 | 34 | return use_connection().scope
|
26 | 35 |
|
27 | 36 |
|
28 |
| -def use_location() -> Location: |
| 37 | +def use_location() -> Location: # nocov |
29 | 38 | """Get the current :class:`~reactpy.backend.types.Connection`'s location."""
|
| 39 | + warn( |
| 40 | + "The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", |
| 41 | + "Call reactpy.use_location instead.", |
| 42 | + DeprecationWarning, |
| 43 | + ) |
| 44 | + |
30 | 45 | return use_connection().location
|
0 commit comments