✨ Announcing our seed funding led by Lux Capital! Read more about it on our blog
DocsBlogChangelog

Search documentation...

/

Star

12k+

[ Learn ]

[ Concepts ]

[ Reference ]

State


reflex.state.State
The state of the app.

Class Fields


FieldDescription
vars A map from the var name to the var.
base_vars The base vars of the class.
computed_vars The computed vars of the class.
inherited_vars Vars inherited by the parent state.
backend_vars Backend vars that are never sent to the client.
inherited_backend_vars Backend vars inherited
event_handlers The event handlers.

Fields


FieldDescription
parent_state The parent state.
substates The substates of the state.
dirty_vars The set of dirty vars.
dirty_substates The set of dirty substates.
router_data The routing path that triggered the state
computed_var_dependencies Mapping of var name to set of computed variables that depend on it
substate_var_dependencies Mapping of var name to set of substates that depend on it

Methods


SignatureDescription
__init__(self, *args, parent_state: 'State | None' = None, **kwargs)Initialize the state.
_init_event_handlers(self, state: 'State | None' = None)Initialize event handlers. Allow event handlers to be called directly on the instance. This is called recursively for all parent states.
__repr__(self) -> 'str'Get the string representation of the state.
_get_base_functions() -> 'dict[str, FunctionType]'Get all functions of the state class excluding dunder methods.
get_token(self) -> 'str'Return the token of the client associated with this state.
get_sid(self) -> 'str'Return the session ID of the client associated with this state.
get_headers(self) -> 'Dict'Return the headers of the client associated with this state.
get_client_ip(self) -> 'str'Return the IP of the client associated with this state.
get_current_page(self, origin=False) -> 'str'Obtain the path of current page from the router data.
get_query_params(self) -> 'dict[str, str]'Obtain the query parameters for the queried page. The query object contains both the URI parameters and the GET parameters.
get_cookies(self) -> 'dict[str, str]'Obtain the cookies of the client stored in the browser.
__getattribute__(self, name: 'str') -> 'Any'Get the state var. If the var is inherited, get the var from the parent state.
__setattr__(self, name: 'str', value: 'Any')Set the attribute. If the attribute is inherited, set the attribute on the parent state.
reset(self)Reset all the base vars to their default values.
_reset_client_storage(self)Reset client storage base vars to their default values.
get_substate(self, path: 'Sequence[str]') -> 'State | None'Get the substate.
_get_event_handler(self, event: 'Event') -> 'tuple[State | StateProxy, EventHandler]'Get the event handler for the given event.
_process(self, event: 'Event') -> 'AsyncIterator[StateUpdate]'Obtain event info and process event.
_check_valid(self, handler: 'EventHandler', events: 'Any') -> 'Any'Check if the events yielded are valid. They must be EventHandlers or EventSpecs.
_as_state_update(self, handler: 'EventHandler', events: 'EventSpec | list[EventSpec] | None', final: 'bool') -> 'StateUpdate'Convert the events to a StateUpdate. Fixes the events and checks for validity before converting.
_process_event(self, handler: 'EventHandler', state: 'State | StateProxy', payload: 'Dict') -> 'AsyncIterator[StateUpdate]'Process event.
_always_dirty_computed_vars(self) -> 'set[str]'The set of ComputedVars that always need to be recalculated.
_mark_dirty_computed_vars(self) -> 'None'Mark ComputedVars that need to be recalculated based on dirty_vars.
_dirty_computed_vars(self, from_vars: 'set[str] | None' = None) -> 'set[str]'Determine ComputedVars that need to be recalculated based on the given vars.
get_delta(self) -> 'Delta'Get the delta for the state.
_mark_dirty(self)Mark the substate and all parent states as dirty.
_clean(self)Reset the dirty vars.
dict(self, include_computed: 'bool' = True, **kwargs) -> 'dict[str, Any]'Convert the object to a dictionary.
__aenter__(self) -> 'State'Enter the async context manager protocol. This should not be used for the State class, but exists for type-compatibility with StateProxy. Raises: TypeError: always, because async contextmanager protocol is only supported for background task.
__aexit__(self, *exc_info: 'Any') -> 'None'Exit the async context manager protocol. This should not be used for the State class, but exists for type-compatibility with StateProxy.
set_is_hydrated(*args: 'Var') -> 'EventSpec'An event handler responds to an event to update the state.
← HydrateMiddlewareVar →

Copyright © 2023 Pynecone, Inc.