Hi!
I'm having a rather interesting use case as a part of mswjs/data#346. Consider this:
import { create } from 'mutative'
const record = {
get comments() {
return []
}
}
const nextRecord = create(record, (record) => {
record.comments.push(1)
})
Expected behavior
nextRecord.comments // [1]
Current behavior
nextRecord.comments // []
Insights
Mutative does not recognize this update at all, which is evident if you use the enablePatches: true approach. The patches array for this mutation is [].
Since the update function does not perform any direct reassignment or mutation of the record, Mutative thinks no changes have occurred, while they have.
Proposal
Would it be feasible for Mutative to support updates through getters? With the goal that the use case above would work identically whether record.comments is a getter or a plain array.
Hi!
I'm having a rather interesting use case as a part of mswjs/data#346. Consider this:
Expected behavior
Current behavior
Insights
Mutative does not recognize this update at all, which is evident if you use the
enablePatches: trueapproach. Thepatchesarray for this mutation is[].Since the update function does not perform any direct reassignment or mutation of the
record, Mutative thinks no changes have occurred, while they have.Proposal
Would it be feasible for Mutative to support updates through getters? With the goal that the use case above would work identically whether
record.commentsis a getter or a plain array.