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 Oct 19, 2021
1 parent 653449f commit fa1dac7
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 117 deletions.
5 changes: 2 additions & 3 deletions src/node/handler/PadMessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,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 @@ -586,7 +585,7 @@ const handleUserChanges = async (socket, message) => {
});

// Validate all added 'author' attribs to be the same value as the current user
for (const op of new Changeset.OpIter(Changeset.unpack(changeset).ops)) {
for (const op of new Changeset.OpIter(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
4 changes: 3 additions & 1 deletion src/node/utils/padDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
}
}

return Changeset.checkRep(builder.toString());
const packed = builder.toString();
Changeset.unpack(packed).validate();
return packed;
};

// export the constructor
Expand Down
Loading

0 comments on commit fa1dac7

Please sign in to comment.