Changeset: Add new Builder.prototype.build() method

This commit is contained in:
Richard Hansen 2021-10-19 03:49:39 -04:00
parent a1c4382386
commit 29da9815ae

View file

@ -1988,14 +1988,26 @@ class Builder {
return this; return this;
} }
toString() { /**
* @returns {Changeset}
*/
build() {
/** @type {number} */ /** @type {number} */
let lengthChange; let lengthChange;
const serializedOps = exports.serializeOps((function* () { const serializedOps = exports.serializeOps((function* () {
lengthChange = yield* exports.canonicalizeOps(this._ops, true); lengthChange = yield* exports.canonicalizeOps(this._ops, true);
}).call(this)); }).call(this));
const newLen = this._oldLen + lengthChange; return {
return exports.pack(this._oldLen, newLen, serializedOps, this._charBank.toString()); oldLen: this._oldLen,
newLen: this._oldLen + lengthChange,
ops: serializedOps,
charBank: this._charBank.toString(),
};
}
toString() {
const {oldLen, newLen, ops, charBank} = this.build();
return exports.pack(oldLen, newLen, ops, charBank);
} }
} }
exports.Builder = Builder; exports.Builder = Builder;