forked from reflex-dev/reflex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF-1988] API to Get instance of Arbitrary State class (reflex-dev#2678
) * WiP get_state * Refactor get_state fast path Rudimentary protection for state instance access from a background task (StateProxy) * retain dirty substate marking per `_mark_dirty` call to avoid test changes * Find common ancestor by part instead of by character Fix StateProxy for substates and parent_state attributes (have to handle in __getattr__, not property) Fix type annotation for `get_state` * test_state: workflow test for `get_state` functionality * Do not reset _always_dirty_substates when adding vars Reset the substate tracking only when the class is instantiated. * test_state_tree: test substate access in a larger state tree Ensure that `get_state` returns the proper "branch" of the state tree depending on what substate is requested. * test_format: fixup broken tests from adding substates of TestState * Fix flaky integration tests with more polling * AppHarness: reset _always_dirty_substates on rx.State * RuntimeError unless State is instantiated with _reflex_internal_init=True Avoid user errors trying to directly instantiate State classes * Helper functions for _substate_key and _split_substate_key Unify the implementation of generating and decoding the token + state name format used for redis state sharding. * StateManagerRedis: use create_task in get_state and set_state read and write substates concurrently (allow redis to shine) * test_state_inheritance: use polling cuz life too short for flaky tests kthnxbai ❤️ * Move _is_testing_env to reflex.utils.exec.is_testing_env Reuse the code in app.py * Break up `BaseState.get_state` and friends into separate methods * Add test case for pre-fetching cached var dependency * Move on_load_internal and update_vars_internal to substates Avoid loading the entire state tree to process these common internal events. If the state tree is very large, this allow page navigation to occur more quickly. Pre-fetch substates that contain cached vars, as they may need to be recomputed if certain vars change. * Do not copy ROUTER_DATA into all substates. This is a waste of time and memory, and can be handled via a special case in __getattribute__ * Track whether State instance _was_touched Avoid wasting time serializing states that have no modifications * Do not persist states in `StateManagerRedis.get_state` Wait until the state is actually modified, and then persist it as part of `set_state`. Factor out common logic into helper methods for readability and to reduce duplication of common logic. To avoid having to recursively call `get_state`, which would require persisting the instance and then getting it again, some of the initialization logic regarding parent_state and substates is duplicated when creating a new instance. This is for performance reasons. * Remove stray print() * context.js.jinja2: fix check for empty local storage / cookie vars * Add comments for onLoadInternalEvent and initialEvents * nit: typo * split _get_was_touched into _update_was_touched Improve clarity in cases where _get_was_touched was being called for its side effects only. * Remove extraneous information from incorrect State instantiation error * Update missing redis exception message
- Loading branch information
1 parent
445cdc7
commit fb4e00d
Showing
15 changed files
with
1,208 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.