Coder Social home page Coder Social logo

simple-ot's Introduction

simple-ot

Build Status codecov

A simple operational transform library that uses the domain-agnostic GOTO control algorithm.

The implementation of the GOTO algorithm was written based on this paper.

This repository also contains an implementation of inclusion and exclusion transformation functions, for character-wise operations on plaintext documents, that can be used with the GOTO algorithm.

For an example application using this library, see cloudcode.

Install

yarn add simple-ot

or

npm install simple-ot --save

Example

import { charwise, OT } from './mod';
const {
  Delete,
  Insert,
  OperationType,
  deserialize,
  exclusionTransform,
  inclusionTransform,
  serialize,
} = charwise;
const id = /* some function that generates IDs that are unique across all sites (ex. uuid) */;

const siteID = 1;
// create the singleton OT object for this site
const ot = new OT(inclusionTransform, exclusionTransform, siteID);

const localInsert = new Insert('a', 0, id(), siteID, ot.history());

// local operations can be directly added to history
ot.addToHistory(localInsert);

// ... and then sent to other sites
const serializedLocal = serialize(localInsert);
sendToOtherSites(serializedLocal);


// ... some time later we receive an operation from another site

const remoteSerialized = {
  historyBuffer: [] as string[],
  id: 'EdSCYG6rxj',
  position: 1,
  siteID: 0,
  type: OperationType.DELETE,
};
const remoteDelete = deserialize(remoteSerialized);

// operations received from other sites need to be transformed before they
// can be applied at this site
const transformed = ot.goto(remoteDelete);

// now its safe to apply the operation and add it to history
applyOperation(transformed);
ot.addToHistory(transformed);

API

For the high-level, domain-agnostic control alogrithm see control.ts.

For the implementation of character-wise inclusion and exclusion transformation functions see charwise.ts.

simple-ot's People

Contributors

rclarey avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

simple-ot's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.