Problem
The state.Provider's reactivity model had two primary limitations that affected complex data binding scenarios:
- Lack of Non-Leaf Reactivity: Effects that depended on a parent data object (e.g., a formula using
data.user) were not triggered when a nested "leaf" property of that object (e.g., data.user.name) was modified. This made it difficult to react to changes in aggregate objects.
- Non-Atomic Updates: A single
setData() call for a nested property could trigger multiple, unbatched effect runs—one for the leaf change and another for the "bubbled" parent update. This was inefficient and could lead to race conditions or unpredictable behavior in UI components.
These issues were discovered while debugging timing-related errors in the Calendar view, where components failed to update correctly when their underlying state properties were set during initialization.
Solution
To address these issues and make the state management system more robust and intuitive, the following enhancements were implemented:
Reactivity Bubbling: The state.Provider's internalSetData method was enhanced to "bubble up" changes. When a leaf property is updated, it now recursively updates its parent objects, creating new object instances at each level. This ensures that any effect depending on an intermediate object in the data hierarchy is correctly triggered.
Atomic Batched Updates: The public setData() and setDataAtSameLevel() methods in state.Provider are now wrapped with EffectBatchManager.startBatch() and EffectBatchManager.endBatch(). This guarantees that all reactive updates originating from a single setData call are collected, de-duplicated, and executed only once in a single, atomic operation.
Benefits
- Intuitive Reactivity: Developers can now create effects and formulas that reliably react to changes in entire data objects, not just their leaf properties.
- Improved Performance: Batching prevents redundant effect executions, leading to more efficient rendering cycles.
- Increased Stability: The atomic nature of
setData eliminates a class of potential race conditions and makes the state management system more predictable.
- Comprehensive Test Coverage: A new test suite (
ProviderNestedDataConfigs.mjs) has been added to validate and protect this new functionality against future regressions.
Problem
The
state.Provider's reactivity model had two primary limitations that affected complex data binding scenarios:data.user) were not triggered when a nested "leaf" property of that object (e.g.,data.user.name) was modified. This made it difficult to react to changes in aggregate objects.setData()call for a nested property could trigger multiple, unbatched effect runs—one for the leaf change and another for the "bubbled" parent update. This was inefficient and could lead to race conditions or unpredictable behavior in UI components.These issues were discovered while debugging timing-related errors in the Calendar view, where components failed to update correctly when their underlying state properties were set during initialization.
Solution
To address these issues and make the state management system more robust and intuitive, the following enhancements were implemented:
Reactivity Bubbling: The
state.Provider'sinternalSetDatamethod was enhanced to "bubble up" changes. When a leaf property is updated, it now recursively updates its parent objects, creating new object instances at each level. This ensures that any effect depending on an intermediate object in the data hierarchy is correctly triggered.Atomic Batched Updates: The public
setData()andsetDataAtSameLevel()methods instate.Providerare now wrapped withEffectBatchManager.startBatch()andEffectBatchManager.endBatch(). This guarantees that all reactive updates originating from a singlesetDatacall are collected, de-duplicated, and executed only once in a single, atomic operation.Benefits
setDataeliminates a class of potential race conditions and makes the state management system more predictable.ProviderNestedDataConfigs.mjs) has been added to validate and protect this new functionality against future regressions.