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;
}
toString() {
/**
* @returns {Changeset}
*/
build() {
/** @type {number} */
let lengthChange;
const serializedOps = exports.serializeOps((function* () {
lengthChange = yield* exports.canonicalizeOps(this._ops, true);
}).call(this));
const newLen = this._oldLen + lengthChange;
return exports.pack(this._oldLen, newLen, serializedOps, this._charBank.toString());
return {
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;