Skip to content

Commit 942ad6a

Browse files
committed
Move use_connection to sit next to functions that use them
1 parent 36ca352 commit 942ad6a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/py/reactpy/reactpy/core/hooks.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,6 @@ def context(
229229
return context
230230

231231

232-
# backend implementations should establish this context at the root of an app
233-
ConnectionContext: Context[Connection[Any] | None] = create_context(None)
234-
235-
236-
def use_connection() -> Connection[Any]:
237-
"""Get the current :class:`~reactpy.backend.types.Connection`."""
238-
conn = use_context(ConnectionContext)
239-
if conn is None: # nocov
240-
msg = "No backend established a connection."
241-
raise RuntimeError(msg)
242-
return conn
243-
244-
245232
def use_context(context: Context[_Type]) -> _Type:
246233
"""Get the current value for the given context type.
247234
@@ -263,6 +250,19 @@ def use_context(context: Context[_Type]) -> _Type:
263250
return provider.value
264251

265252

253+
# backend implementations should establish this context at the root of an app
254+
ConnectionContext: Context[Connection[Any] | None] = create_context(None)
255+
256+
257+
def use_connection() -> Connection[Any]:
258+
"""Get the current :class:`~reactpy.backend.types.Connection`."""
259+
conn = use_context(ConnectionContext)
260+
if conn is None: # nocov
261+
msg = "No backend established a connection."
262+
raise RuntimeError(msg)
263+
return conn
264+
265+
266266
def use_scope() -> MutableMapping[str, Any]:
267267
"""Get the current :class:`~reactpy.backend.types.Connection`'s scope."""
268268
return use_connection().scope

0 commit comments

Comments
 (0)