Skip to content

Commit b486934

Browse files
committed
Changeset: Migrate from opAssembler() to serializeOps()
1 parent d58e3b8 commit b486934

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* The `newOp()` function is deprecated; use the new `Op` class instead.
3636
* The `opIterator()` function is deprecated; use the new `OpIter` class
3737
instead.
38+
* The `opAssembler()` function is deprecated; use the new `serializeOps()`
39+
function instead.
3840

3941
### Notable enhancements
4042

src/node/utils/padDiff.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ PadDiff.prototype._extendChangesetWithAuthor = (changeset, author, apool) => {
209209
// unpack
210210
const unpacked = Changeset.unpack(changeset);
211211

212-
const assem = Changeset.opAssembler();
212+
const ops = [];
213213

214214
// create deleted attribs
215215
const authorAttrib = apool.putAttrib(['author', author || '']);
@@ -224,13 +224,12 @@ PadDiff.prototype._extendChangesetWithAuthor = (changeset, author, apool) => {
224224
// this is operator changes only attributes, let's mark which author did that
225225
operator.attribs += `*${Changeset.numToString(authorAttrib)}`;
226226
}
227-
228-
// append the new operator to our assembler
229-
assem.append(operator);
227+
ops.push(operator);
230228
}
231229

232230
// return the modified changeset
233-
return Changeset.pack(unpacked.oldLen, unpacked.newLen, assem.toString(), unpacked.charBank);
231+
return Changeset.pack(
232+
unpacked.oldLen, unpacked.newLen, Changeset.serializeOps(ops), unpacked.charBank);
234233
};
235234

236235
// this method is 80% like Changeset.inverse. I just changed so instead of reverting,

src/static/js/Changeset.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,16 @@ const copyOp = (op1, op2 = new exports.Op()) => Object.assign(op2, op1);
318318
* @param {Iterable.<Op>} ops - Iterable of operations to serialize.
319319
* @returns {string} A string containing the encoded op data (example: '|5=2p=v*4*5+1').
320320
*/
321-
const serializeOps = (ops) => {
321+
exports.serializeOps = (ops) => {
322322
let res = '';
323323
for (const op of ops) res += op.toString();
324324
return res;
325325
};
326326

327327
/**
328328
* Serializes a sequence of Ops.
329+
*
330+
* @deprecated Use `serializeOps` instead.
329331
*/
330332
class OpAssembler {
331333
constructor() {
@@ -415,7 +417,7 @@ class MergingOpAssembler {
415417
}
416418

417419
_serialize(finalize) {
418-
this._serialized = serializeOps(squashOps(this._ops, finalize));
420+
this._serialized = exports.serializeOps(squashOps(this._ops, finalize));
419421
}
420422

421423
clear() {
@@ -509,7 +511,7 @@ class SmartOpAssembler {
509511
}
510512

511513
_serialize(finalize) {
512-
this._serialized = serializeOps((function* () {
514+
this._serialized = exports.serializeOps((function* () {
513515
this._lengthChange = yield* canonicalizeOps(this._ops, finalize);
514516
}).call(this));
515517
}
@@ -622,9 +624,13 @@ exports.smartOpAssembler = () => new SmartOpAssembler();
622624
exports.mergingOpAssembler = () => new MergingOpAssembler();
623625

624626
/**
627+
* @deprecated Use `serializeOps` instead.
625628
* @returns {OpAssembler}
626629
*/
627-
exports.opAssembler = () => new OpAssembler();
630+
exports.opAssembler = () => {
631+
warnDeprecated('Changeset.opAssembler() is deprecated; use Changeset.serializeOps() instead');
632+
return new OpAssembler();
633+
};
628634

629635
/**
630636
* A custom made String Iterator

src/tests/frontend/specs/easysync.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ const randInt = (maxValue) => Math.floor(Math.random() * maxValue);
3131
describe('easysync', function () {
3232
it('throughIterator', async function () {
3333
const x = '-c*3*4+6|3=az*asdf0*1*2*3+1=1-1+1*0+1=1-1+1|c=c-1';
34-
const assem = Changeset.opAssembler();
35-
for (const op of new Changeset.OpIter(x)) assem.append(op);
36-
expect(assem.toString()).to.equal(x);
34+
expect(Changeset.serializeOps(new Changeset.OpIter(x))).to.equal(x);
3735
});
3836

3937
it('throughSmartAssembler', async function () {

0 commit comments

Comments
 (0)