UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

50 lines (46 loc) 1.99 kB
/* This file is part of MUTE-structs. Copyright (C) 2017 Matthieu Nicolas, Victorien Elvinger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ import { isInt32 } from "../../int32"; import { TextOperation } from "../textoperation"; /** * Represents a sequence operation (insert). */ export class TextInsert extends TextOperation { /** * @constructor * @param {number} offset - the insertion position in the sequence. * @param {string} content - the content to be inserted in the sequence. * @param {number} author - the author of the operation. */ constructor(index, content, author) { console.assert(isInt32(index), "index ∈ int32"); console.assert(isInt32(author), "author ∈ int32"); super(index, author); this.content = content; } equals(other) { return this.index === other.index && this.content === other.content; } /** * Apply the current insert operation to a LogootSplit document. * @param {LogootSDocument} doc - the LogootSplit document on which the insertion wil be performed. * @return {LogootSAdd} the logootsplit insertion that is related to the insertion that has been performed. */ applyTo(doc) { return doc.insertLocal(this.index, this.content); } } //# sourceMappingURL=textinsert.js.map