reflex/reflex/middleware/middleware.py
Khaleel Al-Adhami 8f937f0417
Remove Pydantic from some classes (#3907)
* half of the way there

* add dataclass support

* Forbid Computed var shadowing (#3843)

* get it right pyright

* fix unit tests

* rip out more pydantic

* fix weird issues with merge_imports

* add missing docstring

* make special props a list instead of a set

* fix moment pyi

* actually ignore the runtime error

* it's ruff out there

---------

Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
2024-09-13 12:53:30 -07:00

49 lines
1.1 KiB
Python

"""Base Reflex middleware."""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional
from reflex.event import Event
from reflex.state import BaseState, StateUpdate
if TYPE_CHECKING:
from reflex.app import App
class Middleware(ABC):
"""Middleware to preprocess and postprocess requests."""
@abstractmethod
async def preprocess(
self, app: App, state: BaseState, event: Event
) -> Optional[StateUpdate]:
"""Preprocess the event.
Args:
app: The app.
state: The client state.
event: The event to preprocess.
Returns:
An optional state update to return.
"""
return None
async def postprocess(
self, app: App, state: BaseState, event: Event, update: StateUpdate
) -> StateUpdate:
"""Postprocess the event.
Args:
app: The app.
state: The client state.
event: The event to postprocess.
update: The current state update.
Returns:
An optional state to return.
"""
return update