Changeset: Deprecate `oldLen()` and `newLen()` functions

rhansen-changeset
Richard Hansen 2021-10-19 04:36:13 -04:00
parent b718d88157
commit 60f2a059ec
4 changed files with 18 additions and 9 deletions

View File

@ -628,10 +628,10 @@ const handleUserChanges = async (socket, message) => {
const prevText = pad.text();
if (Changeset.oldLen(rebasedChangeset) !== prevText.length) {
if (Changeset.unpack(rebasedChangeset).oldLen !== prevText.length) {
throw new Error(
`Can't apply changeset ${rebasedChangeset} with oldLen ` +
`${Changeset.oldLen(rebasedChangeset)} to document of length ${prevText.length}`);
`${Changeset.unpack(rebasedChangeset).oldLen} to document of length ${prevText.length}`);
}
const newRev = await pad.appendRevision(rebasedChangeset, thisSession.author);

View File

@ -286,18 +286,28 @@ class Changeset {
/**
* Returns the required length of the text before changeset can be applied.
*
* @deprecated Use `Changeset.unpack(cs).oldLen` instead.
* @param {string} cs - String representation of the Changeset
* @returns {number} oldLen property
*/
exports.oldLen = (cs) => Changeset.unpack(cs).oldLen;
exports.oldLen = (cs) => {
padutils.warnDeprecated(
'Changeset.oldLen(cs) is deprecated; use Changeset.unpack(cs).oldLen instead');
return Changeset.unpack(cs).oldLen;
};
/**
* Returns the length of the text after changeset is applied.
*
* @deprecated Use `Changeset.unpack(cs).newLen` instead.
* @param {string} cs - String representation of the Changeset
* @returns {number} newLen property
*/
exports.newLen = (cs) => Changeset.unpack(cs).newLen;
exports.newLen = (cs) => {
padutils.warnDeprecated(
'Changeset.newLen(cs) is deprecated; use Changeset.unpack(cs).newLen instead');
return Changeset.unpack(cs).newLen;
};
/**
* Parses a string of serialized changeset operations.

View File

@ -1447,11 +1447,10 @@ function Ace2Inner(editorInfo, cssManagers) {
};
const doRepApplyChangeset = (changes, insertsAfterSelection) => {
Changeset.unpack(changes).validate();
const cs = Changeset.unpack(changes).validate();
if (Changeset.oldLen(changes) !== rep.alltext.length) {
const errMsg = `${Changeset.oldLen(changes)}/${rep.alltext.length}`;
throw new Error(`doRepApplyChangeset length mismatch: ${errMsg}`);
if (cs.oldLen !== rep.alltext.length) {
throw new Error(`doRepApplyChangeset length mismatch: ${cs.oldLen}/${rep.alltext.length}`);
}
const editEvent = currentCallStack.editEvent;

View File

@ -167,7 +167,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
let cs = null;
if (toSubmit) {
submittedChangeset = toSubmit;
userChangeset = Changeset.identity(Changeset.newLen(toSubmit));
userChangeset = Changeset.identity(Changeset.unpack(toSubmit).newLen);
cs = toSubmit;
}