-
Notifications
You must be signed in to change notification settings - Fork 9
How It Works
Jethro Kuan edited this page Mar 29, 2017
·
2 revisions
ShareDB is used as the layer for real-time synchronization of text. This is achieved through operational transformation. ShareDB provides adapters for several databases, including MongoDB and postgresql.
Local changes are converted into shareDB ops, and are then sent to the server. These ops are transformed, and propogated to to client and then applied onto Ace text with deltas.
For example, inserting text where | is the cursor:
abc|
abcd|
Produces the following delta and its corresponding op:
“`
//Delta
{'start':{'row':1,'column':3},'end':{'row':1,'column':4},'action':'insert','lines':['d']}
// Op
op: [{"p":["code",3],"si":"d"}]
Here is what happens when `Ace1` makes a local change:
-
onLocalChange
listener onAce1
triggered. -
delta
transformed to shareDB op, and is sent to server - server accepts
op
, applies OT. - Transformed op is propogated to all listening ace instances:
Ace2
andAce1
-
Ace2
receives shareDB op from server, triggersonRemoteChange
. - shareDB op transformed to ace delta, applied to editor.
- Application of
delta
triggersonLocalChange
onAce2
, but source isself
, and the operation is suppressed. This prevents a feedback loop.