Get an instance of the state associated with this token. Allows for arbitrary access to sibling states from within an event handler. Args: state_cls: The class of the state. Returns: The instance of state_cls associated with this state's client_toke
(self, state_cls: type[T_STATE])
| 1722 | return substate |
| 1723 | |
| 1724 | async def get_state(self, state_cls: type[T_STATE]) -> T_STATE: |
| 1725 | """Get an instance of the state associated with this token. |
| 1726 | |
| 1727 | Allows for arbitrary access to sibling states from within an event handler. |
| 1728 | |
| 1729 | Args: |
| 1730 | state_cls: The class of the state. |
| 1731 | |
| 1732 | Returns: |
| 1733 | The instance of state_cls associated with this state's client_token. |
| 1734 | """ |
| 1735 | # Fast case - if this state instance is already cached, get_substate from root state. |
| 1736 | try: |
| 1737 | return self._get_state_from_cache(state_cls) |
| 1738 | except ValueError: |
| 1739 | pass |
| 1740 | |
| 1741 | # Slow case - fetch missing parent states from redis. |
| 1742 | return await self._get_state_from_redis(state_cls) |
| 1743 | |
| 1744 | async def get_var_value(self, var: Var[VAR_TYPE]) -> VAR_TYPE: |
| 1745 | """Get the value of an rx.Var from another state. |