reflex/pynecone/middleware/middleware.py
2022-11-18 12:44:06 -08:00

46 lines
1.1 KiB
Python

"""Base Pynecone middelware."""
from __future__ import annotations
from abc import ABC
from typing import TYPE_CHECKING, Optional
from pynecone.base import Base
from pynecone.event import Event
from pynecone.state import Delta, State
if TYPE_CHECKING:
from pynecone.app import App
class Middleware(Base, ABC):
"""Middleware to preprocess and postprocess requests."""
def preprocess(self, app: App, state: State, event: Event) -> Optional[Delta]:
"""Preprocess the event.
Args:
app: The app.
state: The client state.
event: The event to preprocess.
Returns:
An optional state to return.
"""
return None
def postprocess(
self, app: App, state: State, event: Event, delta
) -> Optional[Delta]:
"""Postprocess the event.
Args:
app: The app.
state: The client state.
event: The event to postprocess.
delta: The delta to postprocess.
Returns:
An optional state to return.
"""
return None