From fe6e662dade26dfa9080adcc16f25ce5b129b49f Mon Sep 17 00:00:00 2001 From: Folyd Date: Wed, 14 Oct 2020 21:27:38 +0800 Subject: [PATCH] Make action name more explicit --- extension/main.js | 9 +++++---- extension/script/docs-rs.js | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/extension/main.js b/extension/main.js index f3f3567..aa3ce99 100644 --- a/extension/main.js +++ b/extension/main.js @@ -266,7 +266,7 @@ chrome.runtime.setUninstallURL( chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { switch (message.action) { - // Stable:* action is exclusive to nightly docs event + // Stable:* action is exclusive to stable docs event case "stable:add" : { IndexManager.setStdStableIndex(message.searchIndex); // New stdSearcher instance after docs updated @@ -282,18 +282,19 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { sendResponse(true); break; } - case "check": { + // Crate:* action is exclusive to crate event + case "crate:check": { let crates = CrateDocSearchManager.getCrates(); sendResponse(crates[message.crateName]); break; } - case "add": { + case "crate:add": { CrateDocSearchManager.addCrate(message.crateName, message.crateVersion, message.searchIndex); crateDocSearchManager.initAllCrateSearcher(); sendResponse(true); break; } - case "remove": { + case "crate:remove": { CrateDocSearchManager.removeCrate(message.crateName); crateDocSearchManager.initAllCrateSearcher(); sendResponse(true); diff --git a/extension/script/docs-rs.js b/extension/script/docs-rs.js index b2dce0a..a37b71f 100644 --- a/extension/script/docs-rs.js +++ b/extension/script/docs-rs.js @@ -8,7 +8,7 @@ document.addEventListener("DOMContentLoaded", async () => { let childrenNumber = ul.children.length; if (childrenNumber >= 3) { await insertFeatureFlagsElement(childrenNumber); - chrome.runtime.sendMessage({crateName, action: "check"}, crate => { + chrome.runtime.sendMessage({crateName, action: "crate:check"}, crate => { if (crate) { currentCrateVersion = crate.version; } @@ -67,7 +67,7 @@ function insertAddToExtensionElement() { li.onclick = () => { // Toggle search index added state if (state === "latest") { - chrome.runtime.sendMessage({crateName, action: "remove"}, response => { + chrome.runtime.sendMessage({crateName, action: "crate:remove"}, response => { currentCrateVersion = undefined; insertAddToExtensionElement(); }); @@ -106,7 +106,7 @@ window.addEventListener("message", function(event) { if (event.source === window && event.data && event.data.direction === "rust-search-extension") { - chrome.runtime.sendMessage({action: "add", ...event.data.message}, + chrome.runtime.sendMessage({action: "crate:add", ...event.data.message}, (response) => { console.log(response); }