Move the core state machinery into reflex_base.state

MA
12d ago
+2296-2113

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)

Part 3 of 4 of #7302. Stack: 1 field descriptors (#7312) → 2 state locks (#7313) → 3 core state in reflex-base → 4 dispatch_value. Based on #7313.

Description

Moves the core state machinery into a new reflex_base.state package:

  • node.py: StateNode is a node of a state tree. It holds the links to its parent and substates, dirty tracking, computed var invalidation, deltas, async with locking, pickling and the dev-mode typo guard. rx.BaseState now extends it with routing, state loading and the event handler machinery. A plain EvenMoreBasicBaseState class still holds fields with no tree around it.
  • delta.py, proxy.py (MutableProxy) and token.py move here from reflex.istate. Their old import paths (reflex.istate.proxy, reflex.istate.delta, reflex.istate.manager.token) still work through module aliases.
  • Field now wraps mutable values in MutableProxy directly, instead of through a hook that reflex installed.
  • wrapt moves from reflex's dependencies to reflex-base's.

This is mostly a move: reflex/state.py shrinks by about 720 lines. StateNode is typed against reflex.state.BaseState under TYPE_CHECKING, like the rest of reflex-base, so a few pyright: ignore comments cover the places where it returns itself or its class.

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

šŸ¤– Generated with Claude Code

https://claude.ai/code/session_0145YmAVjKSJhdUFDcBP4FB9