josephg / ShareJS

Collaborative editing in any app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add update method to json and text apis

dgreisen opened this issue · comments

There is currently a method called applyChange in textarea.js. This function takes the existing text and updated text, and figures out and applies the insert and/or remove operations needed to transform the existing text into the updated text. This is useful in more than just the textarea case. I would like to see this method included in both the text and json apis as something like update(old, new).

@josephg: if this looks ok, I've time to work on it tomorrow. Please let me know.

Its a hack, and I don't want to rely on it in general. The creep will look like "lets add this to JSON for strings" then "Oh, if it works for strings, we should use a diff algorithm for arrays too" "oh why not do full tree-based diff" -> "Hey, all this diffing stuff doesn't preserve intent! ShareJS doesn't work right!" or "ShareJS is so slow!"

So no, I want to inspire the sense of guilt when that dodgy diffing function is invoked. Its not necessarily a bad hack (it works great for isolated changes in small strings), but I don't want to encourage general purpose use.