Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulf

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulf - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/Document.js

19

component.json
{
"name": "telepath",
"repo": "marcelklehr/telepath",
"name": "gulf",
"repo": "marcelklehr/gulf",
"description": "OT managing library",
"version": "0.1.0",
"version": "0.2.0",
"dependencies": {
"share/ottypes": "*",
"marcelklehr/browser-stream": "*"

@@ -14,8 +13,8 @@ },

"index.js",
"Document.js",
"EditableDocument.js",
"Edit.js",
"Link.js",
"History.js"
"lib/Document.js",
"lib/EditableDocument.js",
"lib/Edit.js",
"lib/Link.js",
"lib/History.js"
]
}
}
module.exports = {
Link: require('./Link')
, Document: require('./Document')
, EditableDocument: require('./EditableDocument')
, Edit: require('./Edit')
, History: require('./History')
, ot: null
}
Link: require('./lib/Link')
, Document: require('./lib/Document')
, EditableDocument: require('./lib/EditableDocument')
, Edit: require('./lib/Edit')
, History: require('./lib/History')
}
{
"name": "gulf",
"version": "0.1.0",
"version": "0.2.0",
"description": "Sync anything!",
"repository": {
"type": "git",
"url": "https://github.com/marcelklehr/vibes.git"
"url": "https://github.com/marcelklehr/gulf.git"
},

@@ -14,9 +14,6 @@ "keywords": [

"diff",
"Forward Transformation",
"Backward Transformation",
"Inclusion Transformation",
"Exclusion Transformation",
"collaborative",
"collaborate",
"undo",
"text"
"text",
"shareJS"
],

@@ -23,0 +20,0 @@ "main": "./lib/index",

@@ -1,3 +0,3 @@

# Gulf [![Build Status](https://travis-ci.org/marcelklehr/vibes.png)](https://travis-ci.org/marcelklehr/vibes)
Link documents and they'll stay in sync. Anywhere in the world, in node.js and the browser!
# Gulf [![Build Status](https://travis-ci.org/marcelklehr/gulf.png)](https://travis-ci.org/marcelklehr/gulf)
The Gulf stream will sync your documents. Anywhere in the world, in node.js and the browser!

@@ -8,3 +8,3 @@ ## Show me!

/*
* ALICE
* Alice
*/

@@ -15,2 +15,5 @@ var gulf = require('gulf')

// Create a new master document
var doc = gulf.Document.create(textOT, 'abc')

@@ -20,7 +23,8 @@

// Set up a server
net.createServer(function(socket) {
// create a slave link for each socket
// ... and create a slave link for each socket that connects
var slave = doc.slaveLink()
// connect the client as a slave
// now, add the new client as a slave
// of alice's document

@@ -35,28 +39,26 @@ socket.pipe(slave).pipe(socket)

/*
* BOB
* Bob
*/
var vibes = require('vibes')
var gulf = require('gulf')
, net = require('net')
, textOT = require('ottypes').text
var doc = new vibes.Document(textOT)
doc.content // null
// Create a new slave document (empty by default)
var doc = new gulf.Document(textOT)
doc.content // null -- it's really empty.
// Connect to alice's server
net.connect(7453, function(socket) {
// create a link to a master for bob
// create a link to the master
var master = a.masterLink()
// connect bob's document with Alice's (Alice is master)
// connect bob's document to Alice's master document
socket.pipe(master).pipe(socket)
})
// now if we wait a bit...
setTimeout(function() {
doc.content // 'abc'
}, 100)
```
This is not a one-time thing. There are also `EditableDocument`s that stay in sync whilst you alter them.
And they'll stay in sync.

@@ -68,14 +70,14 @@ ## Usage

Now, how do I change this document if that `Document#content` property is untouchable? Well, thankfully there's also an EditableDocument.
Now, how do I change this document if `Document#content` is untouchable? Well, thankfully there's also EditableDocuments.
Editable documents can be updated via the `update(cs)` method. The `cs` stands for changeset. A changeset contains the changes to a document. (There are many ways you can create such a changeset, right now we use the simple method of imagination: *bling* -- there it is, see it?)
Ok, now we update our editable document and we notice that it keeps a record of all revisions -- it remembers every change we ever made. Nice.
Ok, now we update our editable document and we notice that it keeps a record of all revisions -- all documents remember every change ever done. Nice.
## Linking documents
Now, Alice and Bob each have a document. Actually it's "the same" document. At least it should be, oh -- wait: Bob has made some changes to his version, and Alice of course couldn't resist to write some introductory paragraph again.
Now, Alice and Bob each have a document, actually it's "the same" document. At least it should be, oh -- wait: Bob has made some changes to his version, and Alice of course couldn't resist to write some introductory paragraph again.
Now it's not the same document anymore -- but we could sync the two. We just need some kind of mediator that takes care of the syncing process to keep things sane (imagine, if David had changed his document, too!).
Now it's not the same document anymore -- but if we connect the two, they'll always be in sync, right? We just need some kind of mediator that takes care of the syncing process to keep things sane (imagine, if David had changed his document, too!).
This mediator thingy is also in possession of, surprise, a Document. It's not editable, though. Now, somehow Alice and Bob need to link their documents to that master document and send it the changes they made.
This mediator is also in possession of, surprise, a Document. It's doesn't need to be editable, though. Now, somehow Alice and Bob need to link their documents to that master document and send it the changes they make.

@@ -89,6 +91,6 @@ Well, Links we have. If Alice wants to connect to the master document, she creates a Link to it and attaches it to her document as a master link. The master document attaches Alice's link as a slave link.

## In javascript, please
Since we're in a globalized world we can't expect all documents to be on the same machine. That's why a Link is a simple DuplexStream. You may pipe it to a tcp socket or a websocket or some other stream. Of course that means that you need two instances of Link -- one for each document you want to connect.
Since we're in a globalized world we can't expect all documents to be on the same machine. That's why a Link is a simple DuplexStream. You may pipe it to a tcp socket or a websocket or some other stream. Of course that means that you need two instances of a Link -- one for each side of the connection.
```js
masterDoc = new vibes.Document(ot)
masterDoc = new gulf.Document(ot)

@@ -99,3 +101,3 @@ socket.pipe(masterDoc.slaveLink()).pipe(socket)

```js
slaveDoc = new vibes.Document(ot)
slaveDoc = new gulf.Document(ot)

@@ -110,3 +112,3 @@ socket.pipe(slaveDoc.masterLink()).pipe(socket)

```js
var document = new vibes.EditableDocument(ottype)
var document = new gulf.EditableDocument(ottype)

@@ -133,3 +135,3 @@ document._change = function(newcontent, cs) {

## Operational transform *bling*
Telepath expects you to provide an OT library that adhere's to [shareJs's OT type spec](https://github.com/share/ottypes#spec).
Gulf expects you to provide an OT library that adhere's to [shareJs's OT type spec](https://github.com/share/ottypes#spec).

@@ -140,13 +142,16 @@ You can use [shareJS's built in ottypes](https://github.com/share/ottypes) or [other](https://github.com/marcelklehr/changesets) [libraries](https://github.com/marcelklehr/dom-ot).

```js
var vibes = require('vibes')
var gulf = require('gulf')
, textOT = require('ottypes').text
var document = new vibes.Document(textOT)
var document = new gulf.Document(textOT)
```
## How does it work?
Telepath uses operational transformation, which is all about making edits fit. Node.js streams make sure linking documents is a pure joy.
## FAQ
Why can't it do peer-to-peer linking? Well, Peer-to-peer is a pain-in-the-ass scenario with operational transformation and not at all performant, but that's not my final word on tp2, I'm just too swamped to implement it properly right now, so I thought, let's leave it for later.
How does it work? Telepath uses operational transformation, which is all about making edits fit. Node.js streams make sure linking documents is a pure joy. Everything else is in teh codez.
Does it support peer-to-peer linking? No.
Why? Well, Peer-to-peer is a pain-in-the-ass scenario with operational transformation and not at all performant. If you have a peer-to-peer scenario electing a master might be easier.
## Tests?

@@ -157,8 +162,2 @@ ```

and
```
test.html
```
## Todo

@@ -165,0 +164,0 @@

/* global xdescribe, describe, it, xit */
var telepath
, expect = require('expect.js')
var gulf, expect
, ottype = require('ottypes').text
try {
telepath = require('telepath')
gulf = require('../')
expect = require('expect.js')
}catch(e) {
telepath = require('../')
gulf = require('gulf')
}
describe('telepath', function() {
describe('gulf', function() {
describe('Linking to new documents', function() {
var docA = telepath.Document.create(ottype, 'abc')
, docB = new telepath.Document(ottype)
var docA = gulf.Document.create(ottype, 'abc')
, docB = new gulf.Document(ottype)

@@ -34,4 +35,4 @@ var linkA = docA.slaveLink()

, cs = [3, 'd']
var docA = telepath.Document.create(ottype, initialContent)
, docB = new telepath.EditableDocument(ottype)
var docA = gulf.Document.create(ottype, initialContent)
, docB = new gulf.EditableDocument(ottype)

@@ -38,0 +39,0 @@ var content = ''

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc