lint: changesettracker.js arrow funcs

This commit is contained in:
John McLear 2021-02-17 16:28:33 +00:00
parent d4b6cbc897
commit f5f4e3a6d1

View file

@ -1,3 +1,5 @@
'use strict';
/** /**
* This code is mostly from the old Etherpad. Please help us to comment this code. * This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it. * This helps other people to understand this code better and helps them to improve it.
@ -23,7 +25,7 @@
const AttributePool = require('./AttributePool'); const AttributePool = require('./AttributePool');
const Changeset = require('./Changeset'); const Changeset = require('./Changeset');
function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) { const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
// latest official text from server // latest official text from server
let baseAText = Changeset.makeAText('\n'); let baseAText = Changeset.makeAText('\n');
// changes applied to baseText that have been submitted // changes applied to baseText that have been submitted
@ -42,7 +44,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
let changeCallbackTimeout = null; let changeCallbackTimeout = null;
function setChangeCallbackTimeout() { const setChangeCallbackTimeout = () => {
// can call this multiple times per call-stack, because // can call this multiple times per call-stack, because
// we only schedule a call to changeCallback if it exists // we only schedule a call to changeCallback if it exists
// and if there isn't a timeout already scheduled. // and if there isn't a timeout already scheduled.
@ -55,17 +57,15 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
} }
}, 0); }, 0);
} }
} };
let self; let self;
return self = { return self = {
isTracking() { isTracking: () => tracking,
return tracking; setBaseText: (text) => {
},
setBaseText(text) {
self.setBaseAttributedText(Changeset.makeAText(text), null); self.setBaseAttributedText(Changeset.makeAText(text), null);
}, },
setBaseAttributedText(atext, apoolJsonObj) { setBaseAttributedText: (atext, apoolJsonObj) => {
aceCallbacksProvider.withCallbacks('setBaseText', (callbacks) => { aceCallbacksProvider.withCallbacks('setBaseText', (callbacks) => {
tracking = true; tracking = true;
baseAText = Changeset.cloneAText(atext); baseAText = Changeset.cloneAText(atext);
@ -83,7 +83,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
} }
}); });
}, },
composeUserChangeset(c) { composeUserChangeset: (c) => {
if (!tracking) return; if (!tracking) return;
if (applyingNonUserChanges) return; if (applyingNonUserChanges) return;
if (Changeset.isIdentity(c)) return; if (Changeset.isIdentity(c)) return;
@ -91,7 +91,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
setChangeCallbackTimeout(); setChangeCallbackTimeout();
}, },
applyChangesToBase(c, optAuthor, apoolJsonObj) { applyChangesToBase: (c, optAuthor, apoolJsonObj) => {
if (!tracking) return; if (!tracking) return;
aceCallbacksProvider.withCallbacks('applyChangesToBase', (callbacks) => { aceCallbacksProvider.withCallbacks('applyChangesToBase', (callbacks) => {
@ -123,7 +123,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
} }
}); });
}, },
prepareUserChangeset() { prepareUserChangeset: () => {
// If there are user changes to submit, 'changeset' will be the // If there are user changes to submit, 'changeset' will be the
// changeset, else it will be null. // changeset, else it will be null.
let toSubmit; let toSubmit;
@ -201,7 +201,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
}; };
return data; return data;
}, },
applyPreparedChangesetToBase() { applyPreparedChangesetToBase: () => {
if (!submittedChangeset) { if (!submittedChangeset) {
// violation of protocol; use prepareUserChangeset first // violation of protocol; use prepareUserChangeset first
throw new Error('applySubmittedChangesToBase: no submitted changes to apply'); throw new Error('applySubmittedChangesToBase: no submitted changes to apply');
@ -210,13 +210,11 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) {
baseAText = Changeset.applyToAText(submittedChangeset, baseAText, apool); baseAText = Changeset.applyToAText(submittedChangeset, baseAText, apool);
submittedChangeset = null; submittedChangeset = null;
}, },
setUserChangeNotificationCallback(callback) { setUserChangeNotificationCallback: (callback) => {
changeCallback = callback; changeCallback = callback;
}, },
hasUncommittedChanges() { hasUncommittedChanges: () => !!(submittedChangeset || (!Changeset.isIdentity(userChangeset))),
return !!(submittedChangeset || (!Changeset.isIdentity(userChangeset)));
},
}; };
} };
exports.makeChangesetTracker = makeChangesetTracker; exports.makeChangesetTracker = makeChangesetTracker;