Make action name more explicit

This commit is contained in:
Folyd 2020-10-14 21:27:38 +08:00
parent 6216ecb9bd
commit fe6e662dad
2 changed files with 8 additions and 7 deletions

View file

@ -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);

View file

@ -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);
}