Giter Club home page Giter Club logo

docs's Introduction

Standard operational transform types

We have a lovely buffet of operational transform types. Each type has many fine features, including thorough testing, browser support and documentation. Each type has its own project in this github organization.

These types have been finely aged in ShareJS's type labs, and now they're ready to enter the world and be used by everyone. We are rather proud of them.

Each type defines a set of standard methods for programatic use. You should be able to define a type using the spec then plug it directly into ShareJS (or other compatible collaborative editing systems) and use it immediately. The type defines how operations and documents are stored and manipulated, while a system like sharejs can decide where the data should be stored on disk, network protocols and all that jazz.

Available OT types

This repository contained three OT types. They were split to separate repositories:

This is the type you should use for normal plain-text editing. It can tranform operation with complexity N against operation with complexity M in O(N+M) time. This makes it much faster than ot-text-tp2 implementation.

This implementation features Transform Property 2 which makes it a good suit for peer-to-peer communication. Unfortunately the extra (unnecessary) complexity kills v8's optimizer and as a result ot-text-tp2 goes about 20x slower than the ot-text type. If you're using client-server library like ShareJS, you don't need TP2 property, so you should use simpler ot-text implementation,

This implementation is capable of transforming not only text but also JSON structures. It supports arbitrary inserts, deletes, and reparenting through the tree of a JSON object.

This is an OT implementation for collaboratively editing rich text documents. It was designed alongside QuillJS for editing those documents.

Javascript Spec

Each OT type exposes a single object with the following properties. Note that only name, create, apply and transform are strictly required, though most types should also include url and compose.

There is a simple example of a working type in example.js. For a more thorough example, take a look at the text type.

If you're publishing your library in npm (and you should!), the module should expose an object with a .type property (containing your type). So for example, require('ot-text').type.name contains the text type's name.

Standard properties

  • name: A user-readable name for the type. This is not guaranteed to be unique.
  • uri: (Optional, will be required soon) A canonical location for this type. The spec for the OT type should be at this address. Remember kids, Tim Berners-Lee says cool URLs don't change.
  • create([initialData]) -> snapshot: A function to create the initial document snapshot. Create may accept initial snapshot data as its only argument. Either the return value must be a valid target for JSON.stringify or you must specify serialize and deserialize functions (described below).
  • apply(snapshot, op) -> snapshot': Apply an operation to a document snapshot. Returns the changed snapshot. For performance, old document must not be used after this function call, so apply may reuse and return the current snapshot object.
  • transform(op1, op2, side) -> op1': Transform op1 by op2. Return the new op1. Side is either 'left' or 'right'. It exists to break ties, for example if two operations insert at the same position in a string. Both op1 and op2 must not be modified by transform. Transform must conform to Transform Property 1. That is, apply(apply(snapshot, op1), transform(op2, op1, 'left')) == apply(apply(snapshot, op2), transform(op1, op2, 'right')).
  • compose(op1, op2) -> op: (optional) Compose op1 and op2 to produce a new operation. The new operation must subsume the behaviour of op1 and op2. Specifically, apply(apply(snapshot, op1), op2) == apply(snapshot, compose(op1, op2)). Note: transforming by a composed operation is NOT guaranteed to produce the same result as transforming by each operation in order. This function is optional, but unless you have a good reason to do otherwise, you should provide a compose function for your type.

Optional properties

  • invertWithDoc(op, doc) -> op': (optional, RECOMMENDED) Invert the given operation using context from the document to which it can be applied. This method should generally be added to every type as a way to create undo operations. Formally given apply(snapshot, op) is valid, this creates an operation such that apply(apply(snapshot, op), invert(op, snapshot)) == snapshot. If invert(op) exists, invertWithDoc(op, _) == invert(op). ๐Ÿ’ฃ NOTE: The document passed to invertWithDoc should be the document state before the operation is applied. Not after the operation has been applied.
  • invert(op) -> op': (optional) Invert the given operation. The original operation must not be edited in the process. If supplied, apply(apply(snapshot, op), invert(op)) == snapshot.
  • normalize(op) -> op': (optional) Normalize an operation, converting it to a canonical representation. normalize(normalize(op)) == normalize(op).
  • transformCursor(cursor, op, isOwnOp) -> cursor': (optional) transform the specified cursor by the provided operation, so that the cursor moves forward or backward as content is added or removed before (or at) the cursor position. isOwnOp defines how the cursor should be transformed against content inserted at the cursor position. If isOwnOp is true, the cursor is moved after the content inserted at the original cursor position. If isOwnOp is false, the cursor remains before the content inserted at the original cursor position.
  • serialize(snapshot) -> data: (optional) convert the document snapshot data into a form that may be passed to JSON.stringify. If you have a serialize function, you must have a deserialize function.
  • deserialize(data) -> snapshot: (optional) convert data generated by serialize back into its internal snapshot format. deserialize(serialize(snapshot)) == snapshot. If you have a deserialize function, you must have a serialize function.

Do I need serialize and deserialize? Maybe JSON.stringify is sufficiently customizable..?

TP2 Properties

If your OT type supports transform property 2, set the tp2 property to true and define a prune function.

Transform property 2 is an additional requirement on your transform function. Specifically, transform(op3, compose(op1, transform(op2, op1)) == transform(op3, compose(op2, transform(op1, op2)).

  • tp2: (optional) Boolean property. Make this truthy to declare that the type has tp2 support. Types with TP2 support must define prune.
  • prune(op, otherOp): The inverse of transform. Formally, apply(snapshot, op1) == apply(snapshot, prune(transform(op1, op2), op2)). Usually, prune will simply be the inverse of transform and prune(transform(op1, op2), op2) == op1.

CRDTs

Technically, CRDT types are a subset of OT types. Which is to say, they are OT types that don't need a transform function. As a result, anything that can handle these OT types should also be able to consume CRDTs. But I haven't tested it. If anyone wants to work with me to add CRDT support here, email me.


License

All code contributed to this repository is licensed under the standard MIT license:

Copyright 2011 ottypes library contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following condition:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

docs's People

Contributors

curran avatar devongovett avatar gkubisa avatar josephg avatar mdaines avatar megaserg avatar nateps avatar nornagon avatar sheerun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docs's Issues

Can you please update the ottypes npm package?

Just published the json0 ottype update (thanks!). But I don't think the change is propagated into Share through the ottypes npm package anymore. Looks like it was split into the dependencies so not sure how the ottype package itself is getting built these days.

New npm release

The latest version of ShareJS needs canOpAffectPath which is not included in 1.0.1 on npm.

Description of transformCursor does not match the implementation

As I see, only https://github.com/ottypes/json0 and https://github.com/ottypes/rich-text implement transformCursor and both use the isOwnOp param to decide whether an "insert" action at the cursor position should push the cursor forward or not. However, the docs say "If isOwnOp is true, this function should return the final editing position of the provided operation.", which does not match the current implementations.

IMHO, the implemented behaviour makes more sense (consistent with transform - the last param is for breaking ties rather than completely changing the behaviour of the function), so the docs should be updated.

See also:

Has this repository been splitted?

I see that master version of ShareJS is using this repository as dependency, yet it contains no code.

Could you explain in README that it has been split to separate repositories, and which ones?

Possible to register additional types without including them in this module?

Is it possible to add additional OT types to share.js/livedb etc. without modifying this module? I want to add a rich text type, for example, but don't want to work off a fork of ottypes.

If it's not already possible, then I think that would be a good feature to have, making this much more extendible.

Presence for OT Types

Presence, meaning for example where others' cursors are, is an essential feature of real time collaborative systems. Without it, the experience of real time collaboration suffers greatly. When it comes to implementing presence, one of the tricky bits is transforming presence by ops. Since various OT types will transform presence in different ways, it makes sense to have each OT type define its own presence data structure and transformation algorithm.

This work has been underway for some time now, but I wanted to make this issue to discuss the core of the work - namely, whether or not this feature stands a chance at becoming an "official" part of the OT implementation recommendataion/docs within the ottypes organization. This would be an improvement over the current situation, where the feature is implemented and maintained solely in a fork or multiple divergent forks.

This PR Add presence-related properties #27 introduces the following new methods:

  • createPresence([initialData]) -> presence: (optional) Creates a valid presence from some initialData. Presence represents a user and may contain details like user ID, cursor position in a text OT type, etc.
  • transformPresence(presence, op, isOwnOp) -> presence': (optional) Transforms the presence by the op to create a new presence' which is adjusted in some way for the effects of the op. For example, a cursor position may be pushed forward, if the op inserts some text at the beginning of a text document. isOwnOp determines if the operation comes from the owner of the presence, or from another user.
  • comparePresence(presence1, presence2) -> boolean: (optional) Compares presence1 to presence2 and returns true, if they are equal, otherwise returns false.

I personally am only totally convinced that we need transformPresence(presence, op). The experience of actually implementing the feature may prove the need for the others.

Related reading:

With this issue I'd like to open a discussion about high level questions around presence, like:

  • Does it make sense (is it really necessary) to add presence awareness to OT types?
  • Is presence a feature that the ottypes body of work should support?
  • If this standardization gets sorted out in ottypes, can mainline ShareDB be made to support it?

/cc @josephg @nateps @ericyhwang @gkubisa @mdaines @houshuang @jhchen

Please, explain the build process

I am ok with reading makefiles, but there obviously are two of them to run manually, in ottypes and then in sharejs.
So, please create a short manual of how to build the JS for client.

Examples

Please provide examples either in examples/ or in README.md. Thanks!

Bump version please

I am getting this error:
Object # has no method 'canOpAffectPath'

the object is json0 type. I think it is because the version on npm doesn't have the update with the method.

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.