Problem Description
In the Neo.state.Provider, the onDataPropertyChange() hook was being invoked even when a data property's value had not semantically changed. This led to unnecessary processing and potential feedback loops within applications using the state provider, particularly in scenarios involving two-way data binding and URL hash synchronization.
Solution Implemented
The #setConfigValue() method within src/state/Provider.mjs has been refined to conditionally call onDataPropertyChange().
- For existing data properties: The method now leverages the boolean return value of
currentConfig.set(newValue). The Neo.core.Config.set() method, which internally uses Neo.isEqual(), accurately determines if a value has truly changed.
- For newly created data properties:
onDataPropertyChange() is always triggered, as these represent a new addition to the state.
Rationale
This change ensures that onDataPropertyChange() is only executed when there is a genuine, semantic change in the data property's value. This aligns the StateProvider's behavior with the consistency model established by Neo.createConfig().set(), where the Config instance itself is responsible for determining if a value has changed.
The EffectManager.pause() mechanism already provides atomicity for reactive effects during bulk updates, meaning additional batching for onDataPropertyChange() calls is not required, as these notifications will not trigger effects until the EffectManager is resumed.
This refinement improves the efficiency and robustness of the StateProvider by preventing redundant change notifications and contributing to a more predictable state management system.
Problem Description
In the
Neo.state.Provider, theonDataPropertyChange()hook was being invoked even when a data property's value had not semantically changed. This led to unnecessary processing and potential feedback loops within applications using the state provider, particularly in scenarios involving two-way data binding and URL hash synchronization.Solution Implemented
The
#setConfigValue()method withinsrc/state/Provider.mjshas been refined to conditionally callonDataPropertyChange().currentConfig.set(newValue). TheNeo.core.Config.set()method, which internally usesNeo.isEqual(), accurately determines if a value has truly changed.onDataPropertyChange()is always triggered, as these represent a new addition to the state.Rationale
This change ensures that
onDataPropertyChange()is only executed when there is a genuine, semantic change in the data property's value. This aligns theStateProvider's behavior with the consistency model established byNeo.createConfig().set(), where theConfiginstance itself is responsible for determining if a value has changed.The
EffectManager.pause()mechanism already provides atomicity for reactive effects during bulk updates, meaning additional batching foronDataPropertyChange()calls is not required, as these notifications will not trigger effects until theEffectManageris resumed.This refinement improves the efficiency and robustness of the
StateProviderby preventing redundant change notifications and contributing to a more predictable state management system.