You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the apply() function in Mutative is primarily designed to work with immutable data structures. While there are workarounds to handle mutable data indirectly, direct support for mutable data structures could enhance the flexibility and usefulness of the apply() function.
Proposal
We propose extending the apply() function to directly support mutable data structures, allowing users to apply patches to both mutable and immutable data without requiring additional wrapper functions or conversions.
Motivation
Improve flexibility: Allow users to work seamlessly with both mutable and immutable data structures.
Reduce complexity: Eliminate the need for workarounds when dealing with mutable data.
Enhance performance: Direct support for mutable data(e.g. observable state) could potentially offer performance benefits in certain scenarios. This allows observable states to support patches.
Possible Implementation
Add a new option to the apply() function, e.g., mutable: boolean.
When mutable is true, modify the internal logic of apply() to handle mutable data structures differently:
Skip creating new drafts when applying patches.
Directly modify the input data structure.
Considerations
Implement safeguards: Prevent unintended mutations of immutable parts of the structure.
Backward compatibility: Ensure that the default behavior remains unchanged for users who rely on the current immutable-only functionality.
Performance impact: Evaluate any potential performance implications of adding this feature.
Type safety: Ensure that TypeScript types are updated to reflect the new functionality.
Questions for Discussion
Should this be implemented as a separate function (e.g., applyMutable()) instead of an option in the existing apply() function?
Are there any security concerns with allowing direct mutation of data structures if immutable data is mixed?
How should this feature interact with other Mutative features like auto-freezing and strict mode if immutable data is mixed?
Next Steps
If this proposal is accepted:
Create a detailed technical specification.
Implement a prototype and benchmark its performance.
Update documentation to reflect the new functionality.
Add comprehensive test cases to cover mutable data scenarios.
We welcome feedback and discussion on this proposal from the Mutative community.
The text was updated successfully, but these errors were encountered:
Overview
Currently, the
apply()
function in Mutative is primarily designed to work with immutable data structures. While there are workarounds to handle mutable data indirectly, direct support for mutable data structures could enhance the flexibility and usefulness of theapply()
function.Proposal
We propose extending the
apply()
function to directly support mutable data structures, allowing users to apply patches to both mutable and immutable data without requiring additional wrapper functions or conversions.Motivation
This allows observable states to support patches.
Possible Implementation
apply()
function, e.g.,mutable: boolean
.mutable
is true, modify the internal logic ofapply()
to handle mutable data structures differently:Considerations
Questions for Discussion
applyMutable()
) instead of an option in the existingapply()
function?Next Steps
If this proposal is accepted:
We welcome feedback and discussion on this proposal from the Mutative community.
The text was updated successfully, but these errors were encountered: