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(); const prevText = pad.text();
if (Changeset.oldLen(rebasedChangeset) !== prevText.length) { if (Changeset.unpack(rebasedChangeset).oldLen !== prevText.length) {
throw new Error( throw new Error(
`Can't apply changeset ${rebasedChangeset} with oldLen ` + `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); 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. * 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 * @param {string} cs - String representation of the Changeset
* @returns {number} oldLen property * @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. * 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 * @param {string} cs - String representation of the Changeset
* @returns {number} newLen property * @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. * Parses a string of serialized changeset operations.

View File

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

View File

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