LearnNewsExamplesServices
Frontmatter
id6967
titleFeature: Core Reactivity Enhancements: Effect Dependency Tracking & Dynamic Functions
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 7, 2025, 12:48 AM
updatedAtJul 7, 2025, 1:45 AM
githubUrlhttps://github.com/neomjs/neo/issues/6967
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 7, 2025, 1:45 AM

Feature: Core Reactivity Enhancements: Effect Dependency Tracking & Dynamic Functions

Closed v10.0.0-beta.5 enhancement
tobiu
tobiu commented on Jul 7, 2025, 12:48 AM

Description

This feature introduces fundamental enhancements to the Neo.mjs core reactivity system, enabling automatic and dynamic dependency tracking for Neo.core.Effect instances and improving the flexibility of effect functions. These changes are crucial for building more robust and efficient reactive components and data bindings.

Motivation

To achieve truly automatic and dynamic reactivity, the Neo.core.Effect system needs a reliable mechanism to:

  1. Automatically discover its dependencies: Instead of manually declaring what data an effect depends on, the system should infer dependencies by observing which reactive properties are accessed during the effect's execution.
  2. Dynamically update dependencies: The set of dependencies an effect relies on can change during its lifetime (e.g., due to conditional logic within the effect's function). The system must be able to clear old dependencies and establish new ones on demand.

Changes Made

  1. src/core/Config.mjs - get() method modification:

    • The get() method of Neo.core.Config has been enhanced to integrate with the Neo.core.EffectManager.
    • When an Effect is actively running (as determined by EffectManager.getActiveEffect()), any Config instance whose value is accessed via config.get() will automatically register itself as a dependency of that active Effect.
    • This change enables the Effect system to automatically track which Config instances its function relies on, replacing the need for manual dependency declaration or static analysis (like regex parsing).
  2. src/core/Effect.mjs - fn property as getter/setter:

    • The fn property of Neo.core.Effect has been converted into a getter/setter.
    • Assigning a new function to effect.fn (e.g., effect.fn = newFunction;) now automatically triggers effect.run().
    • This ensures that whenever the effect's logic changes, its run() method is immediately invoked. The run() method, in turn, clears all previous dependencies and re-establishes new ones based on the newly assigned function's execution. This is vital for effects whose dependency set changes dynamically.
  3. test/siesta/tests/core/Effect.mjs - Comprehensive Test Suite:

    • A dedicated test file has been created/updated to thoroughly validate the behavior of Neo.core.Effect and its interaction with Neo.core.Config and Neo.core.EffectManager.
    • The tests cover:
      • Basic dependency tracking and re-execution on dependency change.
      • The dynamic re-tracking of dependencies when effect.fn is reassigned, ensuring old dependencies are cleaned up and new ones are established.
      • The correct functioning of EffectManager's stack for managing active effects.

Benefits

  • True Automatic Reactivity: Eliminates manual dependency management, making reactive programming more intuitive and less error-prone.
  • Dynamic Dependency Sets: Effects can now adapt to changing conditions within their functions, automatically tracking and reacting to new data sources.
  • Improved Code Clarity: The core reactivity logic is encapsulated within Effect and Config, leading to cleaner and more declarative component code.
  • Foundation for Advanced Features: These enhancements lay critical groundwork for more sophisticated reactive patterns, such as computed properties and highly optimized data flows.
tobiu assigned to @tobiu on Jul 7, 2025, 12:48 AM
tobiu added the enhancement label on Jul 7, 2025, 12:48 AM
tobiu referenced in commit 873cec0 - "Feature: Core Reactivity Enhancements: Effect Dependency Tracking & Dynamic Functions #6967" on Jul 7, 2025, 1:29 AM
tobiu referenced in commit 2bf8804 - "#6967 tests/core/Effect: sum verification tests" on Jul 7, 2025, 1:45 AM
tobiu closed this issue on Jul 7, 2025, 1:45 AM
tobiu referenced in commit a80f853 - "Feature: Core Reactivity Enhancements: Effect Dependency Tracking & Dynamic Functions #6967" on Jul 9, 2025, 2:10 AM
tobiu referenced in commit 5d1db29 - "#6967 tests/core/Effect: sum verification tests" on Jul 9, 2025, 2:10 AM