init
__all__ = ['AbstractFrontendUpdatable', 'HasUpdatableVars', 'ReflexStateUpdater']
module-attribute
AbstractFrontendUpdatable
Bases: UpdatableProtocol, ABC
pending_events = asyncio.Queue()
instance-attribute
state_updater = state_updater
instance-attribute
update_mapping
abstractmethod
property
Mapping of Update classes to the function that applies them.
__call__(updates)
async
__init__(state_updater)
get_all_events()
HasUpdatableVars
Bases: Base, ABC
update(update)
abstractmethod
async
Update vars with provided update.
update: The update instance to update the vars with
ReflexStateUpdater
dataclass
Utility class for setting/updating reflex states during processing.
An instance of this class should be used by the ReflexInterface for a given page (if it needs one). The ReflexInterface for a given page will handle coordinating updates etc. during any processing done by event handlers.
Additionally, linking a state will result in all updates that are called on one state also being called on any linked states. This is helpful for updating information elsewhere in the app to mirror that in a main process (e.g. showing more detailed run info in a separate page).
self_state: The current event handler `self` state (for self.get_state(...) etc.)
sync_key: A key to use for syncing redis data (applies to backend state values only)
background: Whether the current task is a rx.event(background=True)_task
background = False
class-attribute
instance-attribute
self_state
instance-attribute
sync_key = None
class-attribute
instance-attribute
__init__(*, self_state, background=False, sync_key=None)
apply_updates(updatable_states, updates, *, update_dependent_states=True)
async
Update the Updatable states with the provided updates (including all dependent states).
Note: This should only be called by subclasses of ReflexControllerBase. Outside of that, an additional update
method(s) should be provided that then call this appropriately for the page states.
updatable_states: The state to update (and find dependent states for)
updates: The updates to apply to the state(s)
update_dependent_states: Whether to also update all dependent states
get_vars(state_class)
async
Get the current vars from a reflex state.
Note: This class holds a reference to the rx.State that can be used to get other states.
register_linked_states(state, linked_state)
classmethod
Register the linked_state as linked to state.
So that when an update is called on state, the same update will be called on all linked_states.
state: The state that if updated should trigger an update on linked_state
linked_state: The state that should be updated when state is updated
with_self()
async
Similar to reflex async with self.
If running from a background task, this will apply the async with self block to allow access to the state.
If not running from a background task, then it will just yield and do nothing.
I.e. Always use async with self.with_self() whenever it might be called from a background task.