MCPcopy
hub / github.com/reflex-dev/reflex / preprocess

Method preprocess

reflex/middleware/hydrate_middleware.py:22–51  ·  view source on GitHub ↗

Preprocess the event. Args: app: The app to apply the middleware to. state: The client state. event: The event to preprocess. Returns: An optional delta or list of state updates to return.

(
        self, app: App, state: BaseState, event: Event
    )

Source from the content-addressed store, hash-verified

20 """Middleware to handle initial app hydration."""
21
22 async def preprocess(
23 self, app: App, state: BaseState, event: Event
24 ) -> StateUpdate | None:
25 """Preprocess the event.
26
27 Args:
28 app: The app to apply the middleware to.
29 state: The client state.
30 event: The event to preprocess.
31
32 Returns:
33 An optional delta or list of state updates to return.
34 """
35 # If this is not the hydrate event, return None
36 if event.name != get_hydrate_event(state):
37 return None
38
39 # Clear client storage, to respect clearing cookies
40 state._reset_client_storage()
41
42 # Mark state as not hydrated (until on_loads are complete)
43 setattr(state, constants.CompileVars.IS_HYDRATED, False)
44
45 # Get the initial state.
46 delta = await _resolve_delta(state.dict())
47 # since a full dict was captured, clean any dirtiness
48 state._clean()
49
50 # Return the state update.
51 return StateUpdate(delta=delta, events=[])

Callers

nothing calls this directly

Calls 6

get_hydrate_eventFunction · 0.90
_resolve_deltaFunction · 0.90
StateUpdateClass · 0.90
_reset_client_storageMethod · 0.80
dictMethod · 0.45
_cleanMethod · 0.45

Tested by

no test coverage detected