We had a lot of trouble until we settled on a principle to help guide us: if you undo a lot, copy something, and redo back to the present (a common operation), the document should not change.
JSON Patch vs Proxy vs Datatype vs Operations
Examples of proxy model:
A proxy system gives you something where you have a closure with a proxied object that you mutate and it uses a JS proxy to detect changes, produce a new state, and share those changes.
- overhead computing changes from what you do with the proxy
- things that produce lots of changes are inefficiently represented as all the changes
Operations means that you define what the set of operations on the data are.
Examples of operation model:
- More efficient for operations that have small parameters but make a lot of change
- Can't remove operations
- Redux-style boilerplate - any changes to data need to be declared possibly in multiple places like in replicache
Datatype requires you to use non-default datatypes (no arrays or objects) and use things like a List or Dict instead.
Examples of datatype model:
- Used by some of the faster implementations
- Less weird that proxies
- Lock-in feels high: if you leave the system, you rewrite a lot.