Skip to content

Support updates through getters #157

@kettanaito

Description

@kettanaito

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions