Build operational transformation for plain text: compose, transform, a server history and a client that buffers edits

hardAbout 70 minutesUpdated CodingProjavascriptoperational-transformationcollaborative-editingreal-timealgorithms
Not solved

Share this question

Problem

Google Docs-style editors let two people type into the same text at once. With operational transformation (OT), every edit is an operation, and when two operations were made concurrently on the same version, one is transformed past the other so both sides end with the same text. The classic design (Jupiter, used by Google Wave and the ot.js library) has one central server that orders operations, and clients that keep at most one operation in flight.

const a = new TextOperation().retain(3).insert("A").retain(2);
const b = new TextOperation().retain(3).insert("B").retain(2);
const [aPrime, bPrime] = TextOperation.transform(a, b);
bPrime.apply(a.apply("abcde")); // "abcABde"
aPrime.apply(b.apply("abcde")); // "abcABde"

Ref. UR-1444 · © UIRound · uiround.com/questions/build-operational-transformation-for-plain-text-compose-transform-a-server-history-and-a-client-that-buffers

Stuck? Take a hint

Try it in the editor

Run your code as often as you like. Submitting it to the full test suite is part of Pro.

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment