mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 00:16:15 -04:00
Changeset: Turn opAssembler()
into a real class
This commit is contained in:
parent
748d661495
commit
9ea424c8f9
1 changed files with 22 additions and 27 deletions
|
@ -293,12 +293,28 @@ const copyOp = (op1, op2 = new Op()) => Object.assign(op2, op1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes a sequence of Ops.
|
* Serializes a sequence of Ops.
|
||||||
*
|
|
||||||
* @typedef {object} OpAssembler
|
|
||||||
* @property {Function} append -
|
|
||||||
* @property {Function} clear -
|
|
||||||
* @property {Function} toString -
|
|
||||||
*/
|
*/
|
||||||
|
class OpAssembler {
|
||||||
|
constructor() {
|
||||||
|
this.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this._serialized = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Op} op - Operation to add. Ownership remains with the caller.
|
||||||
|
*/
|
||||||
|
append(op) {
|
||||||
|
assert(op instanceof Op, 'argument must be an instance of Op');
|
||||||
|
this._serialized += op.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return this._serialized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Efficiently merges consecutive operations that are mergeable, ignores no-ops, and drops final
|
* Efficiently merges consecutive operations that are mergeable, ignores no-ops, and drops final
|
||||||
|
@ -586,28 +602,7 @@ exports.mergingOpAssembler = () => {
|
||||||
/**
|
/**
|
||||||
* @returns {OpAssembler}
|
* @returns {OpAssembler}
|
||||||
*/
|
*/
|
||||||
exports.opAssembler = () => {
|
exports.opAssembler = () => new OpAssembler();
|
||||||
let serialized = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Op} op - Operation to add. Ownership remains with the caller.
|
|
||||||
*/
|
|
||||||
const append = (op) => {
|
|
||||||
assert(op instanceof Op, 'argument must be an instance of Op');
|
|
||||||
serialized += op.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
const toString = () => serialized;
|
|
||||||
|
|
||||||
const clear = () => {
|
|
||||||
serialized = '';
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
append,
|
|
||||||
toString,
|
|
||||||
clear,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom made String Iterator
|
* A custom made String Iterator
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue