Avoid redundant code on Entity reducers with a new update
method that eases the interface for partial updates
#1494
Labels
dev-experience
Developer Experience
feature-request
New feature or request
nice-to-have
package:core
Affects the core package
size: M
Tasks where you have to change some files.
Milestone
Description:
Summary:
This proposal aims to refine the entity updating mechanism in the Booster framework by introducing a method that simplifies updating entities, particularly when dealing with constructors that require numerous parameters.
Specific Challenge:
Currently, when updating entities in response to different events, developers often need to call entity constructors with a long list of parameters, even if only a single field needs to be updated. This results in redundant code where the same parameters are passed repeatedly in different reducers.
Proposed Solution:
We propose the introduction of an
update
method as part of the@Entity
decorator functionality. This method would take a partial object of the entity (an object containing one or more fields from the entity) and the existing instance of the entity. The method would then create a new instance of the entity, copying all fields from the existing instance except those overridden by the partial, providing a more straightforward interface for returning new entity instances.Implementation Options:
update
method, allowing for tailored behavior specific to their entities.update
method, which can be imported and used in entities for standard cases.Example:
Current Approach:
Proposed Approach:
Benefits:
The text was updated successfully, but these errors were encountered: