Divec has uploaded a new change for review. https://gerrit.wikimedia.org/r/305564
Change subject: WIP: collab-service ...................................................................... WIP: collab-service Change-Id: I068447d8155b0732c08d642357dab07cfca5aa2a --- A collab/Collab.js A collab/package.json A collab/server.js M src/dm/ve.dm.Change.js 4 files changed, 81 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/64/305564/1 diff --git a/collab/Collab.js b/collab/Collab.js new file mode 100644 index 0000000..75e071b --- /dev/null +++ b/collab/Collab.js @@ -0,0 +1,33 @@ +var ve = { dm: {} }; +require( '../src/dm/ve.dm.Change' )( ve ); + +Collab = function () { + this.transactionsForDoc = new Map(); +}; + +Collab.prototype.applyChange = function ( doc, author, remote ) { + var txs, local, resolved; + + if ( remote.clear ) { + this.transactionsForDoc = new Map(); + } + remote = new ve.dm.Change( remote.start, remote.transactions ); + + if ( !this.transactionsForDoc.has( doc ) ) { + this.transactionsForDoc.set( doc, [] ); + } + transactions = this.transactionsForDoc.get( doc ); + + if ( remote.start > transactions.length ) { + throw new Error( 'Remote start ' + remote.start + ' is beyond committed history' ); + } + local = new ve.dm.Change( remote.start, transactions.slice( remote.start ) ); + resolved = remote.rebaseOnto( local ); + if ( resolved ) { + Array.prototype.push.apply( transactions, resolved.transactions ); + console.log( JSON.stringify( transactions ) ); + } + return { reverted: !resolved, parallel: local }; +}; + +module.exports = Collab; diff --git a/collab/package.json b/collab/package.json new file mode 100644 index 0000000..b71ffcd --- /dev/null +++ b/collab/package.json @@ -0,0 +1,15 @@ +{ + "name": "ve-collab", + "description": "Collab server for VisualEditor", + "version": "0.0.1", + "dependencies": { + "express": "4.x" + }, + "devDependencies": {}, + "scripts": { + "start": "node server.js" + }, + "repository": { + "type": "git" + } +} diff --git a/collab/server.js b/collab/server.js new file mode 100644 index 0000000..e8f6c05 --- /dev/null +++ b/collab/server.js @@ -0,0 +1,21 @@ +var port = 8081, + express = require( 'express' ), + bodyParser = require( 'body-parser' ), + app = express(), + Collab = require( './Collab' ); + +collab = new Collab(); +app.use( express.static( __dirname + '/..' ) ); +app.use( bodyParser.json() ); +app.post( '/applyChange', function ( req, res ) { + var response; + try { + response = collab.applyChange( req.body.doc, req.body.author, req.body.change ); + } catch ( error ) { + response = { error: error.toString() }; + } + res.setHeader( 'Content-Type', 'application/json' ); + res.end( JSON.stringify( response ) ); +} ); +app.listen( port ); +console.log( 'Listening on ' + port ); diff --git a/src/dm/ve.dm.Change.js b/src/dm/ve.dm.Change.js index 3339e74..448bc19 100644 --- a/src/dm/ve.dm.Change.js +++ b/src/dm/ve.dm.Change.js @@ -1,3 +1,13 @@ +( function ( createClass ) { + if ( typeof window !== 'undefined' ) { + // Browser. new ve.dm.Change(...) + createClass( window.ve ); + } else { + // Node. ve={dm:{}}; require( 've.dm.Change' )( ve ); new ve.dm.Change(...) + module.exports = createClass; + } +} ( function ( ve ) { + /*! * VisualEditor DataModel Change class. * @@ -134,3 +144,5 @@ ve.dm.Change.prototype.serialize = function () { return { start: this.start, transactions: this.transactions }; }; + +} ) ); -- To view, visit https://gerrit.wikimedia.org/r/305564 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I068447d8155b0732c08d642357dab07cfca5aa2a Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Divec <da...@troi.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits