1. Summary
Introduce a new core utility function, Neo.createConfig, to centralize and standardize the process of defining reactive configuration properties in Neo.mjs. This function will be capable of defining reactive properties on both class prototypes (for static config definitions) and individual instances (for dynamic, runtime-defined reactive state).
2. Rationale
Currently, the logic for generating reactive getters and setters (autoGenerateGetSet) is primarily used within Neo.setupClass for class-level configurations. To enable dynamic, instance-level reactive properties with full Neo.mjs reactivity (including beforeGet, beforeSet, and afterSet hooks), and to streamline the core framework, a unified approach is needed. This will make the reactive system more flexible, consistent, and easier to extend.
3. Scope & Implementation Plan
Implement Neo.createConfig:
- Signature:
Neo.createConfig(target, key, initialValue)
target: The object (class prototype or instance) on which the reactive config will be defined.
key: The name of the config property (without the _ suffix).
initialValue: The initial value for the config.
- Internal Logic:
- Create an internal
Neo.core.Config instance to manage the property's value.
- Store this
Neo.core.Config instance in a dedicated, internal map on the target object.
- Call
autoGenerateGetSet(target, key) to define the public getter/setter and private backing property.
- Set the initial value using the newly defined setter (
target[key] = initialValue;) to ensure all associated hooks are triggered.
Refactor Neo.setupClass:
- Modify
setupClass to use Neo.createConfig when processing reactive properties from static config definitions. This has been implemented.
autoGenerateGetSet:
- The logic previously in
autoGenerateGetSet has been fully absorbed into Neo.createConfig.
4. Benefits
- Unified Reactive Config Definition: A single, powerful function handles both static (class-level) and dynamic (instance-level) reactive configurations.
- Full Hook Support: Ensures that dynamically added reactive properties behave identically to statically defined ones, including full
beforeGet, beforeSet, and afterSet hook support.
- Correct Initial Value Handling: The initial value is set via the setter, ensuring all associated hooks are triggered.
- Cleaner
setupClass: Streamlines the class setup process by delegating reactive config definition.
- Enables Dynamic State: Paves the way for easily creating and managing reactive state directly on component instances at runtime.
1. Summary
Introduce a new core utility function,
Neo.createConfig, to centralize and standardize the process of defining reactive configuration properties in Neo.mjs. This function will be capable of defining reactive properties on both class prototypes (for staticconfigdefinitions) and individual instances (for dynamic, runtime-defined reactive state).2. Rationale
Currently, the logic for generating reactive getters and setters (
autoGenerateGetSet) is primarily used withinNeo.setupClassfor class-level configurations. To enable dynamic, instance-level reactive properties with full Neo.mjs reactivity (includingbeforeGet,beforeSet, andafterSethooks), and to streamline the core framework, a unified approach is needed. This will make the reactive system more flexible, consistent, and easier to extend.3. Scope & Implementation Plan
Implement
Neo.createConfig:Neo.createConfig(target, key, initialValue)target: The object (class prototype or instance) on which the reactive config will be defined.key: The name of the config property (without the_suffix).initialValue: The initial value for the config.Neo.core.Configinstance to manage the property's value.Neo.core.Configinstance in a dedicated, internal map on thetargetobject.autoGenerateGetSet(target, key)to define the public getter/setter and private backing property.target[key] = initialValue;) to ensure all associated hooks are triggered.Refactor
Neo.setupClass:setupClassto useNeo.createConfigwhen processing reactive properties fromstatic configdefinitions. This has been implemented.autoGenerateGetSet:autoGenerateGetSethas been fully absorbed intoNeo.createConfig.4. Benefits
beforeGet,beforeSet, andafterSethook support.setupClass: Streamlines the class setup process by delegating reactive config definition.