LearnNewsExamplesServices
Frontmatter
id6973
titlestate/createHierarchicalDataProxy.mjs
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 7, 2025, 1:24 PM
updatedAtJul 7, 2025, 1:25 PM
githubUrlhttps://github.com/neomjs/neo/issues/6973
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 7, 2025, 1:25 PM

state/createHierarchicalDataProxy.mjs

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

Description

This feature introduces Neo.state.createHierarchicalDataProxy, a new Proxy class designed to provide reactive and hierarchical access to data managed by Neo.state.Provider instances. It acts as a crucial bridge, enabling the new Neo.core.Effect system to automatically track dependencies within the state provider's data hierarchy.

Motivation

The Neo.state.Provider system allows for nested and hierarchical data structures, where components can bind to data properties that might reside in their own provider or any parent provider. To integrate this complex data model with the new Neo.core.Effect system, a specialized mechanism is required that can:

  • Transparently resolve data properties across the provider hierarchy.
  • Intercept property access to dynamically register dependencies with the currently running Effect.
  • Maintain the performance and reactivity expected from the framework.

Implementation Details

  1. Neo.state.createHierarchicalDataProxy (New funtion: src/state/createHierarchicalDataProxy.mjs):
    • A Proxy that wraps the conceptual merged data of a state.Provider and its ancestors.
    • Its get trap is the core of its functionality:
      • When a property is accessed (e.g., data.user.firstname), it dynamically searches up the state.Provider hierarchy to find the state.Provider instance that "owns" that specific data property.
      • It then retrieves the corresponding Neo.core.Config instance for that data property from the owning provider.
      • Crucially, if an Neo.core.Effect is currently running (as determined by Neo.core.EffectManager), the HierarchicalDataProxy registers this Neo.core.Config instance as a dependency for that Effect.
      • It returns the value from the Neo.core.Config instance.
    • Supports nested property access by returning new HierarchicalDataProxy instances for intermediate paths (e.g., accessing data.user returns a proxy for the user object, which then allows access to data.user.firstname).

Benefits

  • Seamless Integration: Provides a transparent way to access hierarchical state provider data within reactive computations.
  • Automatic Dependency Tracking: Eliminates the need for manual dependency declaration, simplifying binding logic and reducing potential errors.
  • Performance: Optimized to efficiently traverse the provider hierarchy and interact with Neo.core.Config instances.
  • Foundation for Refactoring: Lays the essential groundwork for refactoring Neo.state.Provider to fully utilize the new Effect system.
tobiu assigned to @tobiu on Jul 7, 2025, 1:24 PM
tobiu added the enhancement label on Jul 7, 2025, 1:24 PM
tobiu referenced in commit da95519 - "state/createHierarchicalDataProxy.mjs #6973" on Jul 7, 2025, 1:24 PM
tobiu closed this issue on Jul 7, 2025, 1:25 PM
tobiu referenced in commit cc47232 - "state/createHierarchicalDataProxy.mjs #6973" on Jul 9, 2025, 2:10 AM