Skip to content

Commit 60f2a05

Browse files
committed
Changeset: Deprecate oldLen() and newLen() functions
1 parent b718d88 commit 60f2a05

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/node/handler/PadMessageHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,10 @@ const handleUserChanges = async (socket, message) => {
628628

629629
const prevText = pad.text();
630630

631-
if (Changeset.oldLen(rebasedChangeset) !== prevText.length) {
631+
if (Changeset.unpack(rebasedChangeset).oldLen !== prevText.length) {
632632
throw new Error(
633633
`Can't apply changeset ${rebasedChangeset} with oldLen ` +
634-
`${Changeset.oldLen(rebasedChangeset)} to document of length ${prevText.length}`);
634+
`${Changeset.unpack(rebasedChangeset).oldLen} to document of length ${prevText.length}`);
635635
}
636636

637637
const newRev = await pad.appendRevision(rebasedChangeset, thisSession.author);

src/static/js/Changeset.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,28 @@ class Changeset {
286286
/**
287287
* Returns the required length of the text before changeset can be applied.
288288
*
289+
* @deprecated Use `Changeset.unpack(cs).oldLen` instead.
289290
* @param {string} cs - String representation of the Changeset
290291
* @returns {number} oldLen property
291292
*/
292-
exports.oldLen = (cs) => Changeset.unpack(cs).oldLen;
293+
exports.oldLen = (cs) => {
294+
padutils.warnDeprecated(
295+
'Changeset.oldLen(cs) is deprecated; use Changeset.unpack(cs).oldLen instead');
296+
return Changeset.unpack(cs).oldLen;
297+
};
293298

294299
/**
295300
* Returns the length of the text after changeset is applied.
296301
*
302+
* @deprecated Use `Changeset.unpack(cs).newLen` instead.
297303
* @param {string} cs - String representation of the Changeset
298304
* @returns {number} newLen property
299305
*/
300-
exports.newLen = (cs) => Changeset.unpack(cs).newLen;
306+
exports.newLen = (cs) => {
307+
padutils.warnDeprecated(
308+
'Changeset.newLen(cs) is deprecated; use Changeset.unpack(cs).newLen instead');
309+
return Changeset.unpack(cs).newLen;
310+
};
301311

302312
/**
303313
* Parses a string of serialized changeset operations.

src/static/js/ace2_inner.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,11 +1447,10 @@ function Ace2Inner(editorInfo, cssManagers) {
14471447
};
14481448

14491449
const doRepApplyChangeset = (changes, insertsAfterSelection) => {
1450-
Changeset.unpack(changes).validate();
1450+
const cs = Changeset.unpack(changes).validate();
14511451

1452-
if (Changeset.oldLen(changes) !== rep.alltext.length) {
1453-
const errMsg = `${Changeset.oldLen(changes)}/${rep.alltext.length}`;
1454-
throw new Error(`doRepApplyChangeset length mismatch: ${errMsg}`);
1452+
if (cs.oldLen !== rep.alltext.length) {
1453+
throw new Error(`doRepApplyChangeset length mismatch: ${cs.oldLen}/${rep.alltext.length}`);
14551454
}
14561455

14571456
const editEvent = currentCallStack.editEvent;

src/static/js/changesettracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
167167
let cs = null;
168168
if (toSubmit) {
169169
submittedChangeset = toSubmit;
170-
userChangeset = Changeset.identity(Changeset.newLen(toSubmit));
170+
userChangeset = Changeset.identity(Changeset.unpack(toSubmit).newLen);
171171

172172
cs = toSubmit;
173173
}

0 commit comments

Comments
 (0)