Closed linonetwo closed 6 years ago
I’m curious, why can’t you just say doc.note.document.nodes[0].leaves[0].text = "..."
?
The reason is that this json is serialized from slate.js editor, and each save can generate a different complex json.
You might be able to use something like assign-deep
to make only the required changes (assignDeep(doc.note, newContent)
)
What's happening here is that automerge is not a diff-based system but an identity one. This is important because when we merge changes across a distributed system we want to guarantee that if two people create, for example, empty TODO items and then subsequently edit the titles after merging we would have two different TODO items with different titles, not one TODO item with one title or the other.
I suspect something like assign-deep would do the job you're looking for.
Further, for a text editor you might look into collecting more granular operations as they occur and updating the document accordingly. I'm afraid I am not familiar with slate.js, but if you're hoping to do something akin to real-time collaboration large infrequent updates are much more likely to generate potential conflicts than regularly synchronized and smaller ones.
See https://github.com/ianstormtaylor/slate/issues/259#issuecomment-377482517 If I do something like this:
Those changes looks like this:
There are lots of ops, though I'm only change a single line.
Will this result in a huge history, just like somebody commits a movie into the git repo?