Skip to content

Instantly share code, notes, and snippets.

@erukiti
Created December 1, 2017 11:58
Show Gist options
  • Save erukiti/a16a87ee2cbfb3b030edf066d63f5b2b to your computer and use it in GitHub Desktop.
Save erukiti/a16a87ee2cbfb3b030edf066d63f5b2b to your computer and use it in GitHub Desktop.
telettype-crdtの実験
const { Document, serializeOperation, deserializeOperation } = require('@atom/teletype-crdt')
const doc1 = new Document({siteId: 1})
const doc2 = new Document({siteId: 2})
const ZP = {...{row: 0, column: 0}}
doc1.setTextInRange(ZP, ZP, 'a')
doc2.setTextInRange(ZP, ZP, 'b')
doc1.integrateOperations(doc2.getOperations())
doc2.integrateOperations(doc1.getOperations())
console.log(1, doc1.getText())
console.log(2, doc2.getText())
const ops1 = doc1.setTextInRange(ZP, ZP, 'hoge')
console.log(1, doc1.getText())
console.log(2, doc2.getText())
doc2.integrateOperations(ops1)
console.log(2, doc2.getText())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment