Skip to content

Commit 6a83881

Browse files
committed
Changeset: Turn stringAssembler() into a real class
1 parent 363cd22 commit 6a83881

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/static/js/Changeset.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -730,23 +730,20 @@ exports.stringIterator = (str) => {
730730

731731
/**
732732
* A custom made StringBuffer
733-
*
734-
* @typedef {object} StringAssembler
735-
* @property {Function} append -
736-
* @property {Function} toString -
737733
*/
734+
class StringAssembler {
735+
constructor() { this._str = ''; }
736+
/**
737+
* @param {string} x -
738+
*/
739+
append(x) { this._str += String(x); }
740+
toString() { return this._str; }
741+
}
738742

739743
/**
740744
* @returns {StringAssembler}
741745
*/
742-
exports.stringAssembler = () => ({
743-
_str: '',
744-
/**
745-
* @param {string} x -
746-
*/
747-
append(x) { this._str += String(x); },
748-
toString() { return this._str; },
749-
});
746+
exports.stringAssembler = () => new StringAssembler();
750747

751748
/**
752749
* @typedef {object} StringArrayLike
@@ -1175,7 +1172,7 @@ exports.applyToText = (cs, str) => {
11751172
assert(str.length === unpacked.oldLen, `mismatched apply: ${str.length} / ${unpacked.oldLen}`);
11761173
const bankIter = exports.stringIterator(unpacked.charBank);
11771174
const strIter = exports.stringIterator(str);
1178-
const assem = exports.stringAssembler();
1175+
const assem = new StringAssembler();
11791176
for (const op of exports.deserializeOps(unpacked.ops)) {
11801177
switch (op.opcode) {
11811178
case '+':
@@ -1494,7 +1491,7 @@ exports.compose = (cs1, cs2, pool) => {
14941491
const len3 = unpacked2.newLen;
14951492
const bankIter1 = exports.stringIterator(unpacked1.charBank);
14961493
const bankIter2 = exports.stringIterator(unpacked2.charBank);
1497-
const bankAssem = exports.stringAssembler();
1494+
const bankAssem = new StringAssembler();
14981495

14991496
const newOps = applyZip(unpacked1.ops, unpacked2.ops, (op1, op2) => {
15001497
const op1code = op1.opcode;
@@ -1942,7 +1939,7 @@ class Builder {
19421939
constructor(oldLen) {
19431940
this._oldLen = oldLen;
19441941
this._ops = [];
1945-
this._charBank = exports.stringAssembler();
1942+
this._charBank = new StringAssembler();
19461943
}
19471944

19481945
/**
@@ -2203,7 +2200,7 @@ exports.inverse = (cs, lines, alines, pool) => {
22032200

22042201
const nextText = (numChars) => {
22052202
let len = 0;
2206-
const assem = exports.stringAssembler();
2203+
const assem = new StringAssembler();
22072204
const firstString = linesGet(curLine).substring(curChar);
22082205
len += firstString.length;
22092206
assem.append(firstString);
@@ -2429,7 +2426,7 @@ const followAttributes = (att1, att2, pool) => {
24292426
return '';
24302427
});
24312428
// we've only removed attributes, so they're already sorted
2432-
const buf = exports.stringAssembler();
2429+
const buf = new StringAssembler();
24332430
for (const att of atts) {
24342431
buf.append('*');
24352432
buf.append(exports.numToString(pool.putAttrib(att)));

0 commit comments

Comments
 (0)