lint: changesettracker.js var > const/let and other easy fixes

pull/4832/head^2
John McLear 2021-02-17 16:31:56 +00:00
parent 3635cb6ca6
commit f86578ffc3
1 changed files with 13 additions and 9 deletions

View File

@ -48,11 +48,13 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
// 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.
if (changeCallback && changeCallbackTimeout === null) { if (changeCallback && changeCallbackTimeout == null) {
changeCallbackTimeout = scheduler.setTimeout(() => { changeCallbackTimeout = scheduler.setTimeout(() => {
try { try {
changeCallback(); changeCallback();
} catch (pseudoError) {} finally { } catch (pseudoError) {
// as empty as my soul
} finally {
changeCallbackTimeout = null; changeCallbackTimeout = null;
} }
}, 0); }, 0);
@ -150,28 +152,30 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
// We need to replace all author attribs with thisSession.author, // We need to replace all author attribs with thisSession.author,
// in case they copy/pasted or otherwise inserted other peoples changes // in case they copy/pasted or otherwise inserted other peoples changes
if (apool.numToAttrib) { if (apool.numToAttrib) {
let authorAttr;
for (const attr in apool.numToAttrib) { for (const attr in apool.numToAttrib) {
if (apool.numToAttrib[attr][0] == 'author' && apool.numToAttrib[attr][1] == authorId) { if (apool.numToAttrib[attr][0] === 'author' &&
var authorAttr = Number(attr).toString(36); apool.numToAttrib[attr][1] === authorId) {
authorAttr = Number(attr).toString(36);
} }
} }
// Replace all added 'author' attribs with the value of the current user // Replace all added 'author' attribs with the value of the current user
var cs = Changeset.unpack(userChangeset); const cs = Changeset.unpack(userChangeset);
const iterator = Changeset.opIterator(cs.ops); const iterator = Changeset.opIterator(cs.ops);
let op; let op;
const assem = Changeset.mergingOpAssembler(); const assem = Changeset.mergingOpAssembler();
while (iterator.hasNext()) { while (iterator.hasNext()) {
op = iterator.next(); op = iterator.next();
if (op.opcode == '+') { if (op.opcode === '+') {
var newAttrs = ''; let newAttrs = '';
op.attribs.split('*').forEach((attrNum) => { op.attribs.split('*').forEach((attrNum) => {
if (!attrNum) return; if (!attrNum) return;
const attr = apool.getAttrib(parseInt(attrNum, 36)); const attr = apool.getAttrib(parseInt(attrNum, 36));
if (!attr) return; if (!attr) return;
if ('author' == attr[0]) { if ('author' === attr[0]) {
// replace that author with the current one // replace that author with the current one
newAttrs += `*${authorAttr}`; newAttrs += `*${authorAttr}`;
} else { newAttrs += `*${attrNum}`; } // overtake all other attribs as is } else { newAttrs += `*${attrNum}`; } // overtake all other attribs as is
@ -188,7 +192,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
else toSubmit = userChangeset; else toSubmit = userChangeset;
} }
var cs = null; let cs = null;
if (toSubmit) { if (toSubmit) {
submittedChangeset = toSubmit; submittedChangeset = toSubmit;
userChangeset = Changeset.identity(Changeset.newLen(toSubmit)); userChangeset = Changeset.identity(Changeset.newLen(toSubmit));