Skip to content

Commit

Permalink
Changeset: Add new Builder.prototype.build() method
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Oct 19, 2021
1 parent fa1dac7 commit 6d7a54e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/node/utils/padDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,7 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
}
}

const packed = builder.toString();
Changeset.unpack(packed).validate();
return packed;
return builder.build().validate().toString();
};

// export the constructor
Expand Down
15 changes: 10 additions & 5 deletions src/static/js/Changeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,13 +1970,20 @@ exports.Builder = class {
return this;
}

toString() {
/**
* @returns {Changeset}
*/
build() {
let lengthChange;
const serializedOps = exports.serializeOps((function* () {
lengthChange = yield* exports.canonicalizeOps(this._ops, true);
}).call(this));
const newLen = this._oldLen + lengthChange;
return new Changeset(this._oldLen, newLen, serializedOps, this._charBank).toString();
return new Changeset(this._oldLen, newLen, serializedOps, this._charBank);
}

toString() {
return this.build().toString();
}
};

Expand Down Expand Up @@ -2195,9 +2202,7 @@ exports.inverse = (cs, lines, alines, pool) => {
}
}

const packed = builder.toString();
Changeset.unpack(packed).validate();
return packed;
return builder.build().validate().toString();
};

// %CLIENT FILE ENDS HERE%
Expand Down

0 comments on commit 6d7a54e

Please sign in to comment.