ITADN

Support updates through getters

#157Closedkettanaito 创建于 2025-11-27
K
kettanaitocommented
Hi! I'm having a rather interesting use case as a part of https://github.com/mswjs/data/issues/346. Consider this: ```ts import { create } from 'mutative' const record = { get comments() { return [] } } const nextRecord = create(record, (record) => { record.comments.push(1) }) ``` ## Expected behavior ```ts nextRecord.comments // [1] ``` ## Current behavior ```ts 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.
关闭于 2026-04-21 8 条评论