Skip to content

Commit fa1dac7

Browse files
committed
Changeset: Move changeset logic to a new Changeset class
1 parent 653449f commit fa1dac7

File tree

6 files changed

+174
-117
lines changed

6 files changed

+174
-117
lines changed

src/node/handler/PadMessageHandler.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ const handleUserChanges = async (socket, message) => {
574574
// create the changeset
575575
try {
576576
try {
577-
// Verify that the changeset has valid syntax and is in canonical form
578-
Changeset.checkRep(changeset);
577+
const cs = Changeset.unpack(changeset).validate();
579578

580579
// Verify that the attribute indexes used in the changeset are all
581580
// defined in the accompanying attribute pool.
@@ -586,7 +585,7 @@ const handleUserChanges = async (socket, message) => {
586585
});
587586

588587
// Validate all added 'author' attribs to be the same value as the current user
589-
for (const op of new Changeset.OpIter(Changeset.unpack(changeset).ops)) {
588+
for (const op of new Changeset.OpIter(cs.ops)) {
590589
// + can add text with attribs
591590
// = can change or add attribs
592591
// - can have attribs, but they are discarded and don't show up in the attribs -

src/node/utils/padDiff.js

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

459-
return Changeset.checkRep(builder.toString());
459+
const packed = builder.toString();
460+
Changeset.unpack(packed).validate();
461+
return packed;
460462
};
461463

462464
// export the constructor

0 commit comments

Comments
 (0)