Skip to content

Commit

Permalink
Changeset: Move changeset logic to a new Changeset class
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Nov 9, 2021
1 parent e81979e commit e58fb0b
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 125 deletions.
5 changes: 2 additions & 3 deletions src/node/handler/PadMessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,7 @@ const handleUserChanges = async (socket, message) => {
// create the changeset
try {
try {
// Verify that the changeset has valid syntax and is in canonical form
Changeset.checkRep(changeset);
const cs = Changeset.unpack(changeset).validate();

// Verify that the attribute indexes used in the changeset are all
// defined in the accompanying attribute pool.
Expand All @@ -584,7 +583,7 @@ const handleUserChanges = async (socket, message) => {
});

// Validate all added 'author' attribs to be the same value as the current user
for (const op of Changeset.deserializeOps(Changeset.unpack(changeset).ops)) {
for (const op of Changeset.deserializeOps(cs.ops)) {
// + can add text with attribs
// = can change or add attribs
// - can have attribs, but they are discarded and don't show up in the attribs -
Expand Down
2 changes: 1 addition & 1 deletion src/node/utils/padDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
}
}

return Changeset.checkRep(builder.toString());
return builder.build().validate().toString();
};

// export the constructor
Expand Down
Loading

0 comments on commit e58fb0b

Please sign in to comment.