UNPKG

logootsropes-crdt

Version:

Provides several data structures to represent a text in a ropes-like structure and manipulating it

52 lines (44 loc) 1.03 kB
var Utils = require('utils-crdt'); var IdentifierInterval = require('./identifierinterval'); /** * */ /** * */ var LogootSBlock = function(id, list) { this.id = id || null; this.nbElement = list || 0; this.mine = false; }; /** * */ LogootSBlock.prototype.addBlock = function(pos, length) { this.nbElement += length; this.id.begin = Math.min(this.id.begin, pos); this.id.end = Math.max(this.id.end, pos + length - 1); }; /** * */ LogootSBlock.prototype.delBlock = function(begin, end, nbElement) { this.nbElement -= nbElement; }; /** * */ LogootSBlock.prototype.copy = function() { return new LogootSBlock(this.id.copy(), this.nbElement); }; LogootSBlock.prototype.copyFromJSON = function (block) { var base = Utils.copy(block.id.base); this.id = new IdentifierInterval(base, block.begin, block.end); }; /** * */ LogootSBlock.prototype.toString = function() { return '{' + this.nbElement + ',' + this.id.toString() + ', ' + (this.mine ? 'mine' : 'its') + '}'; }; module.exports = LogootSBlock;