mobx-keystone
mobx-keystone copied to clipboard
A way to customize model output snapshots
Though I can have @observable properties instead of the Member extended properties, which is not contained in a snapshot, those @observable properties do not generate patches.
I need a way to define a property that generates patches but also can be excluded from the snapshot. (I need to implement undo/redo features on those properties)
Is there any way to achieve this?
Not currently, since patches are operations to be done over snapshots to achieve the desired next/previous state.
That being said, nothing stops you from cloning the result of getSnapshot and changing it so it doesn't include the wanted properties (or the other way around, changing the object being passed to fromSnapshot so it doesn't include certain properties).
What I do now is iterating from snapshot tree root to the target node to change property value and it's very inconvenient to change deeply nested properties. If BaseModel has a hook to be called when getting a snapshot so that it can change any properties serialized into snapshot, it would greatly reduce my job to iterate from tree root to the target node in the root snapshot.
And also, changing property directly in the Snapshot is prohibited because its properties are declared as read-only. To make it modifiable I'm doing JSON.parse(JSON.stringify(snapshotObj)) which is definitely a bad way.
@rkdrnf Do snapshot pre-/post-processors solve your problem?