Right now I just do doc.text = newText when doing content updates, but this isn't good for supporting offline/concurrent edits as it just replaces all the text.
I'm thinking that I could use https://www.npmjs.com/package/diff to compare the old and new string values when an edit is made and then use A.splice to apply each change. I think this would involve migrating to the Next API too:
Doing it this way would allow me to continue using the basic codemirror setup I've got with value and onChange using a basic string type. I could also then contain this functionality within the state actions, and the frontend can be simple as it can just pass the full updated text. This diff processing could be done once on save, and/or on some sort of debounce'd autosave which can automatically save changes after x seconds of inactivity.
I think this will work ok for me here because my use case is not real-time collaborative sync, but is single user cross-device sync with offline support.
Right now I just do
doc.text = newText
when doing content updates, but this isn't good for supporting offline/concurrent edits as it just replaces all the text.I'm thinking that I could use https://www.npmjs.com/package/diff to compare the old and new string values when an edit is made and then use
A.splice
to apply each change. I think this would involve migrating to the Next API too:Doing it this way would allow me to continue using the basic codemirror setup I've got with
value
andonChange
using a basicstring
type. I could also then contain this functionality within the state actions, and the frontend can be simple as it can just pass the full updated text. This diff processing could be done once on save, and/or on some sort of debounce'd autosave which can automatically save changes after x seconds of inactivity. I think this will work ok for me here because my use case is not real-time collaborative sync, but is single user cross-device sync with offline support.