Change: kill style.reason

This commit is contained in:
eight 2018-10-14 01:09:22 +08:00
parent fc53bed3de
commit 7d005f3eaa
7 changed files with 13 additions and 24 deletions

View File

@ -182,7 +182,6 @@
json.id = style.id;
json.updateDate = Date.now();
// json.reason = 'update';
// keep current state
delete json.enabled;
@ -197,7 +196,6 @@
const newStyle = Object.assign({}, style, json);
if (styleSectionsEqual(json, style, {checkSource: true})) {
// update digest even if save === false as there might be just a space added etc.
// json.reason = 'update-digest';
return styleManager.installStyle(newStyle)
.then(saved => {
style.originalDigest = saved.originalDigest;

View File

@ -52,19 +52,14 @@
}
function assignVars(style) {
if (style.reason === 'config' && style.id) {
return style;
}
return find(style)
.then(dup => {
if (dup) {
style.id = dup.id;
if (style.reason !== 'config') {
// preserve style.vars during update
return usercss.assignVars(style, dup)
.then(() => style);
}
}
return style;
});
}

View File

@ -321,11 +321,13 @@ function preinit() {
function onRuntimeMessage(request) {
switch (request.method) {
case 'styleUpdated':
if (editor.getStyleId() === request.style.id &&
request.reason !== 'editPreview' &&
request.reason !== 'editSave' &&
request.reason !== 'config') {
Promise.resolve(request.codeIsUpdated === false ?
if (
editor.getStyleId() === request.style.id &&
!['editPreview', 'editPreviewEnd', 'editSave', 'config']
.includes(request.reason)
) {
Promise.resolve(
request.codeIsUpdated === false ?
request.style : API.getStyle(request.style.id)
)
.then(newStyle => {

View File

@ -88,7 +88,6 @@
API.installUsercss({
id: (installed || installedDup).id,
reason: 'update',
sourceCode
}).then(style => {
updateMeta(style);

View File

@ -125,7 +125,6 @@ function configDialog(style) {
}
style = style.sections ? Object.assign({}, style) : style;
style.enabled = true;
style.reason = 'config';
style.sourceCode = null;
style.sections = null;
const styleVars = style.usercssData.vars;

View File

@ -419,7 +419,6 @@ Object.assign(handleEvent, {
event.preventDefault();
const json = entry.updatedCode;
json.id = entry.styleId;
// json.reason = 'update';
API[json.usercssData ? 'installUsercss' : 'installStyle'](json);
},
@ -519,10 +518,7 @@ Object.assign(handleEvent, {
function handleUpdate(style, {reason, method} = {}) {
if (reason === 'editPreview') return;
// the style was toggled and refreshAllTabs() sent a mini-notification,
// but we've already processed 'styleUpdated' sent directly from notifyAllTabs()
// if (!style.sections) return;
if (reason === 'editPreview' || reason === 'editPreviewEnd') return;
let entry;
let oldEntry = $(ENTRY_ID_PREFIX + style.id);
if (oldEntry && method === 'styleUpdated') {

View File

@ -52,7 +52,7 @@ function onRuntimeMessage(msg) {
case 'styleAdded':
case 'styleUpdated':
case 'exclusionsUpdated':
if (msg.reason === 'editPreview') return;
if (msg.reason === 'editPreview' || msg.reason === 'editPreviewEnd') return;
handleUpdate(msg.style);
break;
case 'styleDeleted':