Skip to content

Commit 6d7a54e

Browse files
committed
Changeset: Add new Builder.prototype.build() method
1 parent fa1dac7 commit 6d7a54e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/node/utils/padDiff.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,7 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
456456
}
457457
}
458458

459-
const packed = builder.toString();
460-
Changeset.unpack(packed).validate();
461-
return packed;
459+
return builder.build().validate().toString();
462460
};
463461

464462
// export the constructor

src/static/js/Changeset.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,13 +1970,20 @@ exports.Builder = class {
19701970
return this;
19711971
}
19721972

1973-
toString() {
1973+
/**
1974+
* @returns {Changeset}
1975+
*/
1976+
build() {
19741977
let lengthChange;
19751978
const serializedOps = exports.serializeOps((function* () {
19761979
lengthChange = yield* exports.canonicalizeOps(this._ops, true);
19771980
}).call(this));
19781981
const newLen = this._oldLen + lengthChange;
1979-
return new Changeset(this._oldLen, newLen, serializedOps, this._charBank).toString();
1982+
return new Changeset(this._oldLen, newLen, serializedOps, this._charBank);
1983+
}
1984+
1985+
toString() {
1986+
return this.build().toString();
19801987
}
19811988
};
19821989

@@ -2195,9 +2202,7 @@ exports.inverse = (cs, lines, alines, pool) => {
21952202
}
21962203
}
21972204

2198-
const packed = builder.toString();
2199-
Changeset.unpack(packed).validate();
2200-
return packed;
2205+
return builder.build().validate().toString();
22012206
};
22022207

22032208
// %CLIENT FILE ENDS HERE%

0 commit comments

Comments
 (0)