Lightweight delta'd object version wrappers using patches #1913
-
Hi all! I'm considering MST for a project with a requirement that a data object in a store can have multiple lightweight versions, where each version consists of a reference to the original plus a list of changes. Patches in MST look like a great fit for maintaining the deltas. I'm lookin for a generic mechanism like ViewModel in mobs-utils, where the versions have the same interface as the original objects, any prop get values are provided by the base object if they don't exist in the delta list, and no state is actually stored in the Version except the delta. Before I go reinvent the wheel, I'm wondering if anyone knows of an existing implementation, or has suggestions on how best to implement generic custom state management of the prop getters and setters in the Version object's MST type. (It's probably worth mentioning that these document models contain nested models, and the version diff needs to track those as well.) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @kcoop! Very interesting. Is it of utmost importance that the It's not an option for you to clone the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply, @EmilTholin! That is in fact what I'm exploring right now, and it's looking promising. It does mean maintaining duplicated cloned state at runtime for every Version... but for the reason you mention, the alternative would be to have all property sets/gets funnel through the Version, which would make for an awkward API. I was hoping to chain these versions together, hoping they'd be lightweight. But it's probably better now to think of these as deltas with a base document rather than a chain of documents. |
Beta Was this translation helpful? Give feedback.
Hi @kcoop!
Very interesting. Is it of utmost importance that the
ViewModel
only has a proper MSTreference
to theModel
? I'm having a hard time imagining how that could be implemented, since there should be able to be more than oneViewModel
of the sameModel
instance.It's not an option for you to clone the
Model
instance when you create theViewModel
instance, and have theViewModel
just record the patches of its own copy ofModel
?