make handleSave optional arguments into an object
This commit is contained in:
parent
e00832aeb5
commit
d325bd9638
|
@ -107,7 +107,7 @@ const styleMan = (() => {
|
||||||
if (ready.then) await ready;
|
if (ready.then) await ready;
|
||||||
style = mergeWithMapped(style);
|
style = mergeWithMapped(style);
|
||||||
style.updateDate = Date.now();
|
style.updateDate = Date.now();
|
||||||
return handleSave(await saveStyle(style), 'editSave');
|
return handleSave(await saveStyle(style), {reason: 'editSave'});
|
||||||
},
|
},
|
||||||
|
|
||||||
/** @returns {Promise<?StyleObj>} */
|
/** @returns {Promise<?StyleObj>} */
|
||||||
|
@ -223,7 +223,7 @@ const styleMan = (() => {
|
||||||
const events = await db.exec('putMany', items);
|
const events = await db.exec('putMany', items);
|
||||||
return Promise.all(items.map((item, i) => {
|
return Promise.all(items.map((item, i) => {
|
||||||
afterSave(item, events[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;
|
if (url) style.url = style.installationUrl = url;
|
||||||
style.originalDigest = await calcStyleDigest(style);
|
style.originalDigest = await calcStyleDigest(style);
|
||||||
// FIXME: update updateDate? what about usercss config?
|
// FIXME: update updateDate? what about usercss config?
|
||||||
return handleSave(await saveStyle(style), reason);
|
return handleSave(await saveStyle(style), {reason});
|
||||||
},
|
},
|
||||||
|
|
||||||
/** @returns {Promise<?StyleObj>} */
|
/** @returns {Promise<?StyleObj>} */
|
||||||
|
@ -264,7 +264,7 @@ const styleMan = (() => {
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
doc.id = await db.exec('put', doc);
|
doc.id = await db.exec('put', doc);
|
||||||
uuidIndex.set(doc._id, doc.id);
|
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) {
|
async toggle(id, enabled) {
|
||||||
if (ready.then) await ready;
|
if (ready.then) await ready;
|
||||||
const style = Object.assign({}, id2style(id), {enabled});
|
const style = Object.assign({}, id2style(id), {enabled});
|
||||||
handleSave(await saveStyle(style), 'toggle', false);
|
handleSave(await saveStyle(style), {reason: 'toggle', codeIsUpdated: false});
|
||||||
return id;
|
return id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ const styleMan = (() => {
|
||||||
case 'revoke':
|
case 'revoke':
|
||||||
await tokenMan.revokeToken('userstylesworld', style.id);
|
await tokenMan.revokeToken('userstylesworld', style.id);
|
||||||
style._usw = {};
|
style._usw = {};
|
||||||
handleSave(await saveStyle(style), 'success-revoke', true, true);
|
handleSave(await saveStyle(style), {reason: 'success-revoke', codeIsUpdated: true});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'publish':
|
case 'publish':
|
||||||
|
@ -392,7 +392,7 @@ const styleMan = (() => {
|
||||||
delete someStyle.tmpSourceCode;
|
delete someStyle.tmpSourceCode;
|
||||||
delete someStyle.metadata;
|
delete someStyle.metadata;
|
||||||
}
|
}
|
||||||
handleSave(await saveStyle(someStyle), null, null, false);
|
handleSave(await saveStyle(someStyle), {broadcast: false});
|
||||||
}
|
}
|
||||||
style._usw = {
|
style._usw = {
|
||||||
token: await tokenMan.getToken('userstylesworld', true, style.id),
|
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))) {
|
for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
|
||||||
style._usw[k] = v;
|
style._usw[k] = v;
|
||||||
}
|
}
|
||||||
handleSave(await saveStyle(style), 'success-publishing', true, true);
|
handleSave(await saveStyle(style), {reason: 'success-publishing', codeIsUpdated: true});
|
||||||
}
|
}
|
||||||
uploadStyle(style);
|
uploadStyle(style);
|
||||||
break;
|
break;
|
||||||
|
@ -420,7 +420,7 @@ const styleMan = (() => {
|
||||||
throw new Error('The rule already exists');
|
throw new Error('The rule already exists');
|
||||||
}
|
}
|
||||||
style[type] = list.concat([rule]);
|
style[type] = list.concat([rule]);
|
||||||
return handleSave(await saveStyle(style), 'styleSettings');
|
return handleSave(await saveStyle(style), {reason: 'styleSettings'});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeIncludeExclude(type, id, rule) {
|
async function removeIncludeExclude(type, id, rule) {
|
||||||
|
@ -431,7 +431,7 @@ const styleMan = (() => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
style[type] = list.filter(r => r !== rule);
|
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) {
|
function broadcastStyleUpdated(style, reason, method = 'styleUpdated', codeIsUpdated = true) {
|
||||||
|
@ -497,7 +497,7 @@ const styleMan = (() => {
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSave(style, reason, codeIsUpdated, broadcast = true) {
|
function handleSave(style, {reason, codeIsUpdated, broadcast = true}) {
|
||||||
const data = id2data(style.id);
|
const data = id2data(style.id);
|
||||||
const method = data ? 'styleUpdated' : 'styleAdded';
|
const method = data ? 'styleUpdated' : 'styleAdded';
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user