From f5da135e81db4cf5e84b6f7f0056630ff050b131 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 19 Apr 2017 19:03:00 +0300 Subject: [PATCH] invalidateCache: minor refactor & fix deletedId case --- storage.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/storage.js b/storage.js index 4fc861cc..f2f2d8e4 100644 --- a/storage.js +++ b/storage.js @@ -432,32 +432,31 @@ function compileStyleRegExps({style, compileAll}) { 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) { return; } + const id = added ? added.id : updated ? updated.id : deletedId; + const cached = cachedStyles.byId.get(id); if (updated) { - const cached = cachedStyles.byId.get(updated.id); if (cached) { Object.assign(cached, updated); + cachedStyles.filters.clear(); + return; + } else { + added = updated; } - cachedStyles.filters.clear(); - return; } if (added) { - cachedStyles.list.push(added); - cachedStyles.byId.set(added.id, added); - cachedStyles.filters.clear(); + if (!cached) { + cachedStyles.list.push(added); + cachedStyles.byId.set(added.id, added); + cachedStyles.filters.clear(); + } return; } - if (deletedId != undefined) { - const deletedStyle = (cachedStyles.byId.get(deletedId) || {}).style; - if (deletedStyle) { - const cachedIndex = cachedStyles.list.indexOf(deletedStyle); + if (deletedId !== undefined) { + if (cached) { + const cachedIndex = cachedStyles.list.indexOf(cached); cachedStyles.list.splice(cachedIndex, 1); cachedStyles.byId.delete(deletedId); cachedStyles.filters.clear();