LearnNewsExamplesServices
Frontmatter
id6974
titleRefactor `Neo.state.Provider` to use `core.Effect` based reactivity
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 7, 2025, 1:30 PM
updatedAtJul 7, 2025, 7:45 PM
githubUrlhttps://github.com/neomjs/neo/issues/6974
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 7, 2025, 7:45 PM

Refactor Neo.state.Provider to use core.Effect based reactivity

Closed v10.0.0-beta.5 enhancement
tobiu
tobiu commented on Jul 7, 2025, 1:30 PM

Description

This feature refactors Neo.state.Provider to fully integrate the new Neo.core.Effect system and Neo.state.HierarchicalDataProxy. This replaces the previous custom, ad-hoc reactivity mechanism within state.Provider, leading to a more consistent, efficient, and maintainable data binding system.

Motivation

The existing state.Provider used a custom implementation for managing reactive data properties and their bindings to components. This approach had several drawbacks:

  • Inconsistency: It diverged from the Neo.core.Config reactivity model, creating two separate ways to handle reactive data within the framework.
  • Complexity: The manual dependency tracking and update propagation within state.Provider were complex and prone to subtle bugs, especially with nested and hierarchical data.
  • Maintainability: The custom reactivity logic made state.Provider harder to understand, debug, and extend.

This refactoring addresses these issues by leveraging the newly introduced Effect system and HierarchicalDataProxy.

Implementation Details

  1. Internal Data Storage: state.Provider now stores its data properties internally as Neo.core.Config instances, unifying its reactivity with the core framework. The afterSetData method has been updated to manage these Config instances.
  2. Simplified Bindings: The createBinding() method has been completely refactored. It now creates a Neo.core.Effect instance that wraps the component's binding formatter. This Effect automatically tracks dependencies via the HierarchicalDataProxy and updates the component's config when any of those dependencies change.
  3. Hierarchical Data Access: getHierarchyData() now returns the HierarchicalDataProxy, enabling seamless and reactive access to data across the provider hierarchy.
  4. New Helper Methods: getDataConfig(), getOwnerOfDataProperty(), and hasNestedDataStartingWith() have been added to state.Provider to support the HierarchicalDataProxy's operation.
  5. Cleanup: Obsolete methods and manual binding management logic have been removed, including createDataProperty(), onDataPropertyChange(), getFormatterVariables(), and the old manual bindings map. This significantly reduces the complexity and size of state.Provider.
  6. setData() Refactored: The setData() and internalSetData() methods have been updated to interact directly with the Neo.core.Config instances.

Benefits

  • Unified Reactivity: Aligns state.Provider's data binding with the core Neo.core.Config reactivity model, improving consistency across the framework.
  • Increased Robustness: The Effect system provides a more reliable and less error-prone mechanism for dependency tracking and change propagation.
  • Improved Maintainability: Simplifies state.Provider's codebase, making it easier to understand, debug, and extend.
  • Enhanced Performance: The lightweight Effect class and optimized dependency tracking contribute to better overall performance.

Future Considerations

  • Two-Way Binding: The two-way binding mechanism needs to be re-evaluated and adapted to the new Effect system.
  • Formulas: The formulas config in state.Provider will need to be updated to leverage the new Effect system for its reactive computations.
tobiu assigned to @tobiu on Jul 7, 2025, 1:30 PM
tobiu added the enhancement label on Jul 7, 2025, 1:30 PM
tobiu referenced in commit 899f7cc - "Refactor Neo.state.Provider to use core.Effect based reactivity #6974 WIP" on Jul 7, 2025, 1:31 PM
tobiu referenced in commit ec5f191 - "Refactor Neo.state.Provider to use core.Effect based reactivity #6974" on Jul 7, 2025, 7:44 PM
tobiu
tobiu Jul 7, 2025, 7:45 PM
Image
tobiu closed this issue on Jul 7, 2025, 7:45 PM
tobiu referenced in commit f4a7746 - "Refactor Neo.state.Provider to use core.Effect based reactivity #6974 WIP" on Jul 9, 2025, 2:10 AM
tobiu referenced in commit 5ae9c63 - "Refactor Neo.state.Provider to use core.Effect based reactivity #6974" on Jul 9, 2025, 2:10 AM