Commit 2907722
authored
ENG-8258: API for linking and sharing states (#6024)
* ENG-8258: API for linking and sharing states
It works by defining a substate of SharedState and then calling
self._link_to(target_token) from some event handler. from that point on,
whenever that user's state is loaded, the StateManager will patch in the linked
shared states. whenever a linked state is modified, we explicitly load all of
the other linked tokens, patch in the modified states, and send a delta to
those clients
You can call ._unlink to remove the link association, which causes the substate
to be subsequently loaded from the client_token's tree as a private state
It is intended to work transparently with computed vars, background events, and
frontend rendering.
* WiP: move _links to root state to avoid extra redis load
* Fix test_mixin_state
* only import ShareStateBaseInternal if there are links present
* Fix delta calculation in certain scenarios
* Add integration test for linked states
* fix test_computed_var assertion
* remove background task deadlock updating linked state
perform the subsequent updates in an asyncio.Task to allow the original caller
to drop the lock for the other shared states.
* do not reuse _modify_linked_states in `_link_to`
the state might have multiple links, and we may have already entered the
context and are holding the lock already, so we don't want to take the lock
again which will hang.
instead, check if the state is already linked to the target token and avoid
doing extra work.
* abstract out _patch_state and use it when linking or unlinking
* _link_to returns the newly linked state
_modify_linked_states context can now release the locks of newly linked states
and send updates for changes in newly linked states.
rehydrating after linking is no longer necessary.
* fix test cases
* mark router and router_data as dirty when patching state
definitely the token will be different. although private-dependent data should
use private states, it's common for llm generated code to define router_data
dependent vars in the linked state itself, so we make that special case work
* AI CR feedback1 parent 224f920 commit 2907722
File tree
9 files changed
+869
-8
lines changed- reflex
- istate
- manager
- tests
- integration
- units
9 files changed
+869
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1562 | 1562 | | |
1563 | 1563 | | |
1564 | 1564 | | |
1565 | | - | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
1566 | 1569 | | |
1567 | 1570 | | |
1568 | 1571 | | |
1569 | 1572 | | |
1570 | 1573 | | |
1571 | 1574 | | |
| 1575 | + | |
1572 | 1576 | | |
1573 | 1577 | | |
1574 | 1578 | | |
| |||
1581 | 1585 | | |
1582 | 1586 | | |
1583 | 1587 | | |
1584 | | - | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
1585 | 1591 | | |
1586 | 1592 | | |
1587 | 1593 | | |
| |||
1769 | 1775 | | |
1770 | 1776 | | |
1771 | 1777 | | |
1772 | | - | |
| 1778 | + | |
1773 | 1779 | | |
1774 | 1780 | | |
1775 | 1781 | | |
| |||
2003 | 2009 | | |
2004 | 2010 | | |
2005 | 2011 | | |
2006 | | - | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
2007 | 2015 | | |
2008 | 2016 | | |
2009 | 2017 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
117 | 146 | | |
118 | 147 | | |
119 | 148 | | |
| |||
0 commit comments