Release Notes
Shared/Linked State
You can use rx.SharedState to define state that is shared among multiple frontends.
import reflex as rx
class MySharedThing(rx.SharedState):
my_counter: int = 0
@rx.event
async def toggle_link(self):
if not self._linked_to:
await self._link_to(await self.get_var_value(State.shared_token))
else:
return await self._unlink()
@rx.event
def increment(self):
self.my_counter += 1
@rx.event
def decrement(self):
self.my_counter -= 1
@rx.var
def linked_to(self) -> str:
return self._linked_to or "not linked"
@rx.var
def linked_from(self) -> str:
return ", ".join(self._linked_from) or "no links"
@rx.event(background=True)
async def delayed_multi_increment(self, amount: int):
import asyncio
for _ in range(amount):
await asyncio.sleep(1)
async with self:
self.my_counter += 1
class State(rx.State):
@rx.var
def shared_token(self) -> str:
return (self.room or "shared_global").replace("_", "-")
@rx.var
async def current_count(self) -> int:
shared_state = await self.get_state(MySharedThing)
return shared_state.my_counter
@rx.event
async def print_current_count(self):
shared_state = await self.get_state(MySharedThing)
print(f"Current count is: {shared_state.my_counter}")
def index() -> rx.Component:
return rx.container(
rx.color_mode.button(position="top-right"),
rx.vstack(
rx.text(f"Shared token: {State.shared_token}"),
rx.button(f"Linked To: {MySharedThing.linked_to}", on_click=MySharedThing.toggle_link),
rx.text(f"Linked From: {MySharedThing.linked_from}"),
rx.heading(State.current_count),
rx.button(
"Increment",
on_click=MySharedThing.increment,
),
rx.button(
"Increment 5 times with 1s delay",
on_click=MySharedThing.delayed_multi_increment(5),
),
rx.button(
"Decrement",
on_click=MySharedThing.decrement,
),
rx.button(
"Print Current Count to Console",
on_click=State.print_current_count,
),
),
)
app = rx.App()
app.add_page(index, route="/[room]")
app.add_page(index)Add ALEMBIC_INCLUDE_SCHEMAS=1/0 to control include_schema migrations
- add alembic include scehmas by @adhami3310 in #6036
Bugfixes
- do not use react lazy by @adhami3310 in #6033
- ENG-8509: computed var dependency tracking for locally imported states by @masenf in #6035
- turn on inconsistentCjsInterop again by @adhami3310 in #6044
- MutableProxy: do not rebind self for classmethods by @masenf in #6045
- [FIX] Clipboard paste handler binding in dynamically rendered components by @debangshu919 in #6037
Error Improvements
- do not treat str bytes as list by @adhami3310 in #6034
Chores
- 0823dev by @adhami3310 in #6030
- reflex-web integration tests: submodules: recursive by @masenf in #6040
- Update link to ComponentState docs by @masenf in #6042
- Fix computed var dep tracking error message by @masenf in #6039
New Contributors
- @debangshu919 made their first contribution in #6037
Full Changelog: v0.8.22...v0.8.23