Description
The Neo.state.Provider currently requires the use of setData() to trigger reactivity when updating data properties. To enhance developer experience and align with more intuitive JavaScript patterns, we should implement a Proxy set trap on the stateProvider.data object. This will allow direct assignments (e.g., stateProvider.data.myProperty = 'newValue') to automatically trigger the underlying setData() mechanism, ensuring reactivity.
Problem
Developers accustomed to direct property assignments for state management in other reactive frameworks may find the explicit setData() calls cumbersome or non-idiomatic. This can lead to confusion and potential bugs if setData() is not used, as direct assignments currently do not trigger the Effect system.
Proposed Solution
Modify src/state/createHierarchicalDataProxy.mjs to include a set trap within the Proxy returned by createHierarchicalDataProxy.
The set trap should:
- Intercept direct assignments to properties on the
stateProvider.data proxy.
- Determine the correct
Neo.state.Provider instance (current or a parent in the hierarchy) that "owns" the property being assigned. This can be achieved by leveraging the existing getOwnerOfDataProperty method.
- Call the
setData() method on the identified owning StateProvider with the fullPath of the property and the new value. This will ensure that the Neo.core.Config instances are updated and the Effect system is triggered, maintaining full reactivity.
Benefits
- Improved developer ergonomics: Allows for more natural and concise data updates.
- Reduced boilerplate: Eliminates the need for explicit
setData() calls in many common scenarios.
- Enhanced consistency: Aligns the
StateProvider's data manipulation with common reactive programming paradigms.
Acceptance Criteria
- Direct assignments to
stateProvider.data.someProperty (including nested properties like stateProvider.data.user.firstName) successfully trigger reactive updates in bound components.
- The
onDataPropertyChange method in Neo.state.Provider is correctly invoked when data is updated via direct assignment.
- Existing
setData() calls continue to function as expected.
- No regressions are introduced in the
StateProvider's reactivity or hierarchical data access.
- Comprehensive unit tests are added to
test/siesta/tests/state/Provider.mjs to cover direct assignment scenarios, including nested properties and various data types.
Description The
Neo.state.Providercurrently requires the use ofsetData()to trigger reactivity when updating data properties. To enhance developer experience and align with more intuitive JavaScript patterns, we should implement aProxysettrap on thestateProvider.dataobject. This will allow direct assignments (e.g.,stateProvider.data.myProperty = 'newValue') to automatically trigger the underlyingsetData()mechanism, ensuring reactivity.Problem Developers accustomed to direct property assignments for state management in other reactive frameworks may find the explicit
setData()calls cumbersome or non-idiomatic. This can lead to confusion and potential bugs ifsetData()is not used, as direct assignments currently do not trigger theEffectsystem.Proposed Solution Modify
src/state/createHierarchicalDataProxy.mjsto include asettrap within theProxyreturned bycreateHierarchicalDataProxy.The
settrap should:stateProvider.dataproxy.Neo.state.Providerinstance (current or a parent in the hierarchy) that "owns" the property being assigned. This can be achieved by leveraging the existinggetOwnerOfDataPropertymethod.setData()method on the identified owningStateProviderwith thefullPathof the property and the newvalue. This will ensure that theNeo.core.Configinstances are updated and theEffectsystem is triggered, maintaining full reactivity.Benefits
setData()calls in many common scenarios.StateProvider's data manipulation with common reactive programming paradigms.Acceptance Criteria
stateProvider.data.someProperty(including nested properties likestateProvider.data.user.firstName) successfully trigger reactive updates in bound components.onDataPropertyChangemethod inNeo.state.Provideris correctly invoked when data is updated via direct assignment.setData()calls continue to function as expected.StateProvider's reactivity or hierarchical data access.test/siesta/tests/state/Provider.mjsto cover direct assignment scenarios, including nested properties and various data types.