20
20
21
21
@component
22
22
def root_manager (child : Any ):
23
+ """This component is serves as the parent component for any ReactPy component tree,
24
+ which allows for the management of the entire component tree."""
23
25
scope = hooks .use_connection ().scope
24
26
_ , set_rerender = hooks .use_state (uuid4 )
25
27
@@ -29,7 +31,7 @@ def setup_asgi_scope():
29
31
any relevant actions."""
30
32
scope ["reactpy" ]["rerender" ] = rerender
31
33
32
- async def rerender ():
34
+ def rerender ():
33
35
"""Event that can force a rerender of the entire component tree."""
34
36
set_rerender (uuid4 ())
35
37
@@ -44,7 +46,7 @@ def auth_manager():
44
46
Used to force persistent authentication between Django's websocket and HTTP stack."""
45
47
from reactpy_django import config
46
48
47
- synchronize_requested , set_synchronize_requested = hooks .use_state (False )
49
+ sync_needed , set_sync_needed = hooks .use_state (False )
48
50
token = hooks .use_ref ("" )
49
51
scope = hooks .use_connection ().scope
50
52
@@ -54,19 +56,19 @@ def setup_asgi_scope():
54
56
any relevant actions."""
55
57
scope ["reactpy" ]["synchronize_auth" ] = synchronize_auth
56
58
57
- @hooks .use_effect (dependencies = [synchronize_requested ])
59
+ @hooks .use_effect (dependencies = [sync_needed ])
58
60
async def synchronize_auth_watchdog ():
59
- """Detected if the client has taken too long to request a auth session synchronization.
61
+ """Detect if the client has taken too long to request a auth session synchronization.
60
62
61
63
This effect will automatically be cancelled if the session is successfully
62
64
synchronized (via effect dependencies)."""
63
- if synchronize_requested :
65
+ if sync_needed :
64
66
await asyncio .sleep (config .REACTPY_AUTH_TOKEN_TIMEOUT + 0.1 )
65
67
await asyncio .to_thread (
66
68
_logger .warning ,
67
69
f"Client did not switch authentication sessions within { config .REACTPY_AUTH_TOKEN_TIMEOUT } (REACTPY_AUTH_TOKEN_TIMEOUT) seconds." ,
68
70
)
69
- set_synchronize_requested (False )
71
+ set_sync_needed (False )
70
72
71
73
async def synchronize_auth ():
72
74
"""Event that can command the client to switch HTTP auth sessions (to match the websocket session)."""
@@ -88,12 +90,12 @@ async def synchronize_auth():
88
90
# Begin the process of synchronizing HTTP and websocket auth sessions
89
91
obj = await AuthToken .objects .acreate (value = token .current , session_key = session .session_key )
90
92
await obj .asave ()
91
- set_synchronize_requested (True )
93
+ set_sync_needed (True )
92
94
93
95
async def synchronize_auth_callback (status_code : int , response : str ):
94
96
"""This callback acts as a communication bridge, allowing the client to notify the server
95
97
of the status of auth session switch."""
96
- set_synchronize_requested (False )
98
+ set_sync_needed (False )
97
99
if status_code >= 300 or status_code < 200 :
98
100
await asyncio .to_thread (
99
101
_logger .error ,
@@ -103,7 +105,7 @@ async def synchronize_auth_callback(status_code: int, response: str):
103
105
# If needed, synchronize authenication sessions by configuring all relevant session cookies.
104
106
# This is achieved by commanding the client to perform a HTTP request to our session manager endpoint,
105
107
# which will set any required cookies.
106
- if synchronize_requested :
108
+ if sync_needed :
107
109
return HttpRequest (
108
110
{
109
111
"method" : "GET" ,
0 commit comments