Comparing version 1.0.1 to 1.1.0
@@ -22,4 +22,6 @@ /** | ||
, queue = require('queue') | ||
, EventEmitter = require('events').EventEmitter | ||
function Document(adapter, ottype) { | ||
EventEmitter.apply(this) | ||
this.adapter = adapter | ||
@@ -43,2 +45,4 @@ this.ottype = ottype | ||
Document.prototype = Object.create(EventEmitter.prototype, { constructor: { value: Document }}) | ||
/** | ||
@@ -115,3 +119,3 @@ * Creates a new document | ||
this.history.latest(function(er, latest) { | ||
if(er) return link.emit('error', er) // XXX: send this error to the document | ||
if(er) return this.emit('error', er) | ||
var content = (this.ottype.serialize)? this.ottype.serialize(this.content) : this.content | ||
@@ -138,3 +142,3 @@ link.send('init', {contents: content, edit: latest.edit.pack()}) | ||
this.history.latest(function(er, latest) { | ||
if(er) return link.emit('error', er) // XXX: send this error to the document | ||
if(er) return this.emit('error', er) | ||
var content = (this.ottype.serialize)? this.ottype.serialize(this.content) : this.content | ||
@@ -235,3 +239,3 @@ link.send('init', {contents: content, edit: latest.edit.pack()}) | ||
this.history.remembers(edit.id, function(er, remembers) { | ||
if(er) return fromLink.emit('error',er) // XXX: Send this error to the document | ||
if(er) return this.emit('error',er) | ||
@@ -269,3 +273,3 @@ if (remembers) { | ||
if(er) { | ||
fromLink && fromLink.emit('editError', er) // XXX: send this erro to the document | ||
this.emit('error', er) | ||
return cb(er) | ||
@@ -275,2 +279,3 @@ } | ||
this.distributeEdit(edit, fromLink) | ||
this.emit('edit', edit) | ||
cb(null, edit) | ||
@@ -277,0 +282,0 @@ }.bind(this)) |
@@ -126,1 +126,2 @@ /** | ||
} | ||
module.exports.randString = randString |
@@ -31,5 +31,3 @@ /** | ||
History.prototype.createDocument = function(snapshot, cb) { | ||
snapshot.id = snapshot.edit.id | ||
snapshot.edit = snapshot.edit.pack() | ||
this.document.adapter.createDocument(snapshot, function(er) { | ||
this.document.adapter.createDocument({id: snapshot.edit.id, changes: JSON.stringify(snapshot.edit.changeset), contents: snapshot.contents}, function(er) { | ||
if(er) return cb(er) | ||
@@ -65,2 +63,3 @@ cb() | ||
if(latest && latest.edit.id != snapshot.edit.parent) cb && cb(new Error('This edit\'s parent is not the latest edit in history: '+JSON.stringify(snapshot))) | ||
if(!snapshot.edit.id) snapshot.edit.id = Edit.randString() | ||
this.document.adapter.storeSnapshot({id: snapshot.edit.id, changes: JSON.stringify(snapshot.edit.changeset), parent: snapshot.edit.parent, contents: snapshot.contents}, function(er) { | ||
@@ -67,0 +66,0 @@ cb && cb(er) |
@@ -99,4 +99,4 @@ /** | ||
Link.prototype._write = function(buf, enc, cb) { | ||
console.log('<- _write:', buf.toString(enc)) | ||
var args = JSON.parse(buf.toString(enc)) | ||
console.log('<- _write:', buf.toString()) | ||
var args = JSON.parse(buf.toString()) | ||
@@ -103,0 +103,0 @@ this.authorize(args, args[args.length-1], function(er, authorized) { |
{ | ||
"name": "gulf", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "transport-agnostic operational transformation control layer", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73541
928