MCPcopy
hub / github.com/reflex-dev/reflex / reload_state_module

Function reload_state_module

reflex/state.py:2650–2684  ·  view source on GitHub ↗

Reset rx.State subclasses to avoid conflict when reloading. Args: module: The module to reload. state: Recursive argument for the state class to reload.

(
    module: str,
    state: type[BaseState] = State,
)

Source from the content-addressed store, hash-verified

2648
2649
2650def reload_state_module(
2651 module: str,
2652 state: type[BaseState] = State,
2653) -> None:
2654 """Reset rx.State subclasses to avoid conflict when reloading.
2655
2656 Args:
2657 module: The module to reload.
2658 state: Recursive argument for the state class to reload.
2659
2660 """
2661 from reflex_base.registry import RegistrationContext
2662
2663 # Reset the _app_ref of OnLoadInternalState to avoid stale references.
2664 if state is OnLoadInternalState:
2665 state._app_ref = None
2666 # Clean out all potentially dirty states of reloaded modules.
2667 for pd_state in tuple(state._potentially_dirty_states):
2668 with contextlib.suppress(ValueError):
2669 if (
2670 state.get_root_state().get_class_substate(pd_state).__module__ == module
2671 and module is not None
2672 ):
2673 state._potentially_dirty_states.remove(pd_state)
2674 reg_ctx = RegistrationContext.get()
2675 substates = reg_ctx.get_substates(state)
2676 for subclass in tuple(substates):
2677 reload_state_module(module=module, state=subclass)
2678 if subclass.__module__ == module and module is not None:
2679 all_base_state_classes.pop(subclass.get_full_name(), None)
2680 substates.remove(subclass)
2681 state._always_dirty_substates.discard(subclass.get_name())
2682 state._var_dependencies = {}
2683 state._init_var_dependency_dicts()
2684 state.get_class_substate.cache_clear()

Callers 4

cleanup_dynamic_argFunction · 0.90
compilable_appFunction · 0.90
_reload_state_moduleMethod · 0.90
get_appFunction · 0.90

Calls 8

get_class_substateMethod · 0.80
get_root_stateMethod · 0.80
removeMethod · 0.80
get_full_nameMethod · 0.80
get_nameMethod · 0.80
getMethod · 0.45
get_substatesMethod · 0.45

Tested by 3

cleanup_dynamic_argFunction · 0.72
compilable_appFunction · 0.72
_reload_state_moduleMethod · 0.72