-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,45 @@ | ||
from __future__ import annotations | ||
from __future__ import annotations # nocov | ||
|
||
from collections.abc import MutableMapping | ||
from typing import Any | ||
from collections.abc import MutableMapping # nocov | ||
from typing import Any # nocov | ||
|
||
from reactpy.backend.types import Connection, Location | ||
from reactpy.core.hooks import create_context, use_context | ||
from reactpy.core.types import Context | ||
from reactpy._warnings import warn # nocov | ||
from reactpy.backend.types import Connection, Location # nocov | ||
from reactpy.core.hooks import ConnectionContext, use_context # nocov | ||
|
||
# backend implementations should establish this context at the root of an app | ||
ConnectionContext: Context[Connection[Any] | None] = create_context(None) | ||
|
||
|
||
def use_connection() -> Connection[Any]: | ||
def use_connection() -> Connection[Any]: # nocov | ||
"""Get the current :class:`~reactpy.backend.types.Connection`.""" | ||
warn( | ||
"The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", | ||
"Call reactpy.use_connection instead.", | ||
DeprecationWarning, | ||
) | ||
|
||
conn = use_context(ConnectionContext) | ||
if conn is None: # nocov | ||
if conn is None: | ||
msg = "No backend established a connection." | ||
raise RuntimeError(msg) | ||
return conn | ||
|
||
|
||
def use_scope() -> MutableMapping[str, Any]: | ||
def use_scope() -> MutableMapping[str, Any]: # nocov | ||
"""Get the current :class:`~reactpy.backend.types.Connection`'s scope.""" | ||
warn( | ||
"The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", | ||
"Call reactpy.use_scope instead.", | ||
DeprecationWarning, | ||
) | ||
|
||
return use_connection().scope | ||
|
||
|
||
def use_location() -> Location: | ||
def use_location() -> Location: # nocov | ||
"""Get the current :class:`~reactpy.backend.types.Connection`'s location.""" | ||
warn( | ||
"The module reactpy.backend.hooks has been deprecated and will be deleted in the future. ", | ||
"Call reactpy.use_location instead.", | ||
DeprecationWarning, | ||
) | ||
|
||
return use_connection().location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters