From d325bd96384c86f61106c9fbe0a92d164c3f20b4 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 17 Jul 2021 01:21:23 +0200 Subject: [PATCH] make handleSave optional arguments into an object --- background/style-manager.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index 33e5f991..e473b079 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -107,7 +107,7 @@ const styleMan = (() => { if (ready.then) await ready; style = mergeWithMapped(style); style.updateDate = Date.now(); - return handleSave(await saveStyle(style), 'editSave'); + return handleSave(await saveStyle(style), {reason: 'editSave'}); }, /** @returns {Promise} */ @@ -223,7 +223,7 @@ const styleMan = (() => { const events = await db.exec('putMany', items); return Promise.all(items.map((item, i) => { afterSave(item, events[i]); - return handleSave(item, 'import'); + return handleSave(item, {reason: 'import'}); })); }, @@ -240,7 +240,7 @@ const styleMan = (() => { if (url) style.url = style.installationUrl = url; style.originalDigest = await calcStyleDigest(style); // FIXME: update updateDate? what about usercss config? - return handleSave(await saveStyle(style), reason); + return handleSave(await saveStyle(style), {reason}); }, /** @returns {Promise} */ @@ -264,7 +264,7 @@ const styleMan = (() => { if (diff < 0) { doc.id = await db.exec('put', doc); uuidIndex.set(doc._id, doc.id); - return handleSave(doc, 'sync'); + return handleSave(doc, {reason: 'sync'}); } }, @@ -272,7 +272,7 @@ const styleMan = (() => { async toggle(id, enabled) { if (ready.then) await ready; const style = Object.assign({}, id2style(id), {enabled}); - handleSave(await saveStyle(style), 'toggle', false); + handleSave(await saveStyle(style), {reason: 'toggle', codeIsUpdated: false}); return id; }, @@ -369,7 +369,7 @@ const styleMan = (() => { case 'revoke': await tokenMan.revokeToken('userstylesworld', style.id); style._usw = {}; - handleSave(await saveStyle(style), 'success-revoke', true, true); + handleSave(await saveStyle(style), {reason: 'success-revoke', codeIsUpdated: true}); break; case 'publish': @@ -392,7 +392,7 @@ const styleMan = (() => { delete someStyle.tmpSourceCode; delete someStyle.metadata; } - handleSave(await saveStyle(someStyle), null, null, false); + handleSave(await saveStyle(someStyle), {broadcast: false}); } style._usw = { token: await tokenMan.getToken('userstylesworld', true, style.id), @@ -404,7 +404,7 @@ const styleMan = (() => { for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) { style._usw[k] = v; } - handleSave(await saveStyle(style), 'success-publishing', true, true); + handleSave(await saveStyle(style), {reason: 'success-publishing', codeIsUpdated: true}); } uploadStyle(style); break; @@ -420,7 +420,7 @@ const styleMan = (() => { throw new Error('The rule already exists'); } style[type] = list.concat([rule]); - return handleSave(await saveStyle(style), 'styleSettings'); + return handleSave(await saveStyle(style), {reason: 'styleSettings'}); } async function removeIncludeExclude(type, id, rule) { @@ -431,7 +431,7 @@ const styleMan = (() => { return; } style[type] = list.filter(r => r !== rule); - return handleSave(await saveStyle(style), 'styleSettings'); + return handleSave(await saveStyle(style), {reason: 'styleSettings'}); } function broadcastStyleUpdated(style, reason, method = 'styleUpdated', codeIsUpdated = true) { @@ -497,7 +497,7 @@ const styleMan = (() => { return style; } - function handleSave(style, reason, codeIsUpdated, broadcast = true) { + function handleSave(style, {reason, codeIsUpdated, broadcast = true}) { const data = id2data(style.id); const method = data ? 'styleUpdated' : 'styleAdded'; if (!data) {