invalidateCache: minor refactor & fix deletedId case
This commit is contained in:
parent
fe3f5121e5
commit
f5da135e81
29
storage.js
29
storage.js
|
@ -432,32 +432,31 @@ function compileStyleRegExps({style, compileAll}) {
|
||||||
|
|
||||||
|
|
||||||
function invalidateCache({added, updated, deletedId} = {}) {
|
function invalidateCache({added, updated, deletedId} = {}) {
|
||||||
// prevent double-add on echoed invalidation
|
|
||||||
const cached = added && cachedStyles.byId.get(added.id);
|
|
||||||
if (cached) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!cachedStyles.list) {
|
if (!cachedStyles.list) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const id = added ? added.id : updated ? updated.id : deletedId;
|
||||||
|
const cached = cachedStyles.byId.get(id);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
const cached = cachedStyles.byId.get(updated.id);
|
|
||||||
if (cached) {
|
if (cached) {
|
||||||
Object.assign(cached, updated);
|
Object.assign(cached, updated);
|
||||||
|
cachedStyles.filters.clear();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
added = updated;
|
||||||
}
|
}
|
||||||
cachedStyles.filters.clear();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (added) {
|
if (added) {
|
||||||
cachedStyles.list.push(added);
|
if (!cached) {
|
||||||
cachedStyles.byId.set(added.id, added);
|
cachedStyles.list.push(added);
|
||||||
cachedStyles.filters.clear();
|
cachedStyles.byId.set(added.id, added);
|
||||||
|
cachedStyles.filters.clear();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (deletedId != undefined) {
|
if (deletedId !== undefined) {
|
||||||
const deletedStyle = (cachedStyles.byId.get(deletedId) || {}).style;
|
if (cached) {
|
||||||
if (deletedStyle) {
|
const cachedIndex = cachedStyles.list.indexOf(cached);
|
||||||
const cachedIndex = cachedStyles.list.indexOf(deletedStyle);
|
|
||||||
cachedStyles.list.splice(cachedIndex, 1);
|
cachedStyles.list.splice(cachedIndex, 1);
|
||||||
cachedStyles.byId.delete(deletedId);
|
cachedStyles.byId.delete(deletedId);
|
||||||
cachedStyles.filters.clear();
|
cachedStyles.filters.clear();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user