Refactor async arrow functions

This commit is contained in:
paarmita 2018-09-28 00:35:04 +05:30
parent 3d1dcd33d1
commit 58d9d23146
8 changed files with 50 additions and 50 deletions

View file

@ -69,12 +69,12 @@ const assignManager = {
return this.area.remove([siteStoreKey]); return this.area.remove([siteStoreKey]);
}, },
async deleteContainer(userContextId) { const deleteContainer = async (userContextId) => {
const sitesByContainer = await this.getByContainer(userContextId); const sitesByContainer = await this.getByContainer(userContextId);
this.area.remove(Object.keys(sitesByContainer)); this.area.remove(Object.keys(sitesByContainer));
}, },
async getByContainer(userContextId) { const getByContainer = async (userContextId) => {
const sites = {}; const sites = {};
const siteConfigs = await this.area.get(); const siteConfigs = await this.area.get();
Object.keys(siteConfigs).forEach((key) => { Object.keys(siteConfigs).forEach((key) => {
@ -107,14 +107,14 @@ const assignManager = {
}, },
// We return here so the confirm page can load the tab when exempted // We return here so the confirm page can load the tab when exempted
async _exemptTab(m) { const _exemptTab = async (m) => {
const pageUrl = m.pageUrl; const pageUrl = m.pageUrl;
this.storageArea.setExempted(pageUrl, m.tabId); this.storageArea.setExempted(pageUrl, m.tabId);
return true; return true;
}, },
// Before a request is handled by the browser we decide if we should route through a different container // Before a request is handled by the browser we decide if we should route through a different container
async onBeforeRequest(options) { const onBeforeRequest = async (options) => {
if (options.frameId !== 0 || options.tabId === -1) { if (options.frameId !== 0 || options.tabId === -1) {
return {}; return {};
} }
@ -240,7 +240,7 @@ const assignManager = {
}, },
async _onClickedHandler(info, tab) { const _onClickedHandler = async (info, tab) => {
const userContextId = this.getUserContextIdFromCookieStore(tab); const userContextId = this.getUserContextIdFromCookieStore(tab);
// Mapping ${URL(info.pageUrl).hostname} to ${userContextId} // Mapping ${URL(info.pageUrl).hostname} to ${userContextId}
let remove; let remove;
@ -295,7 +295,7 @@ const assignManager = {
return true; return true;
}, },
async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) { const _setOrRemoveAssignment = async (tabId, pageUrl, userContextId, remove) => {
let actionName; let actionName;
// https://github.com/mozilla/testpilot-containers/issues/626 // https://github.com/mozilla/testpilot-containers/issues/626
@ -334,7 +334,7 @@ const assignManager = {
this.calculateContextMenu(tab); this.calculateContextMenu(tab);
}, },
async _getAssignment(tab) { const _getAssignment = async (tab) => {
const cookieStore = this.getUserContextIdFromCookieStore(tab); const cookieStore = this.getUserContextIdFromCookieStore(tab);
// Ensure we have a cookieStore to assign to // Ensure we have a cookieStore to assign to
if (cookieStore if (cookieStore
@ -361,7 +361,7 @@ const assignManager = {
browser.contextMenus.remove(this.MENU_MOVE_ID); browser.contextMenus.remove(this.MENU_MOVE_ID);
}, },
async calculateContextMenu(tab) { const calculateContextMenu = async (tab) => {
this.removeContextMenu(); this.removeContextMenu();
const siteSettings = await this._getAssignment(tab); const siteSettings = await this._getAssignment(tab);
// Return early and not add an item if we have false // Return early and not add an item if we have false

View file

@ -7,7 +7,7 @@ const backgroundLogic = {
"about:blank" "about:blank"
]), ]),
async getExtensionInfo() { const getExtensionInfo = async () => {
const manifestPath = browser.extension.getURL("manifest.json"); const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath); const response = await fetch(manifestPath);
const extensionInfo = await response.json(); const extensionInfo = await response.json();
@ -25,7 +25,7 @@ const backgroundLogic = {
return false; return false;
}, },
async deleteContainer(userContextId, removed = false) { const deleteContainer = async (userContextId, removed = false) => {
await this._closeTabs(userContextId); await this._closeTabs(userContextId);
if (!removed) { if (!removed) {
await browser.contextualIdentities.remove(this.cookieStoreId(userContextId)); await browser.contextualIdentities.remove(this.cookieStoreId(userContextId));
@ -34,7 +34,7 @@ const backgroundLogic = {
return {done: true, userContextId}; return {done: true, userContextId};
}, },
async createOrUpdateContainer(options) { const createOrUpdateContainer = async (options) => {
let donePromise; let donePromise;
if (options.userContextId !== "new") { if (options.userContextId !== "new") {
donePromise = browser.contextualIdentities.update( donePromise = browser.contextualIdentities.update(
@ -50,7 +50,7 @@ const backgroundLogic = {
}); });
}, },
async openNewTab(options) { const openNewTab = async (options) => {
let url = options.url || undefined; let url = options.url || undefined;
const userContextId = ("userContextId" in options) ? options.userContextId : 0; const userContextId = ("userContextId" in options) ? options.userContextId : 0;
const active = ("nofocus" in options) ? options.nofocus : true; const active = ("nofocus" in options) ? options.nofocus : true;
@ -94,7 +94,7 @@ const backgroundLogic = {
}); });
}, },
async getTabs(options) { const getTabs = async (options) => {
const requiredArguments = ["cookieStoreId", "windowId"]; const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "getTabs"); this.checkArgs(requiredArguments, options, "getTabs");
const { cookieStoreId, windowId } = options; const { cookieStoreId, windowId } = options;
@ -112,7 +112,7 @@ const backgroundLogic = {
return list.concat(containerState.hiddenTabs); return list.concat(containerState.hiddenTabs);
}, },
async moveTabsToWindow(options) { const moveTabsToWindow = async (options) => {
const requiredArguments = ["cookieStoreId", "windowId"]; const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "moveTabsToWindow"); this.checkArgs(requiredArguments, options, "moveTabsToWindow");
const { cookieStoreId, windowId } = options; const { cookieStoreId, windowId } = options;
@ -179,7 +179,7 @@ const backgroundLogic = {
return await identityState.storageArea.set(cookieStoreId, containerState); return await identityState.storageArea.set(cookieStoreId, containerState);
}, },
async _closeTabs(userContextId, windowId = false) { const _closeTabs = async (userContextId, windowId = false) => {
const cookieStoreId = this.cookieStoreId(userContextId); const cookieStoreId = this.cookieStoreId(userContextId);
let tabs; let tabs;
/* if we have no windowId we are going to close all this container (used for deleting) */ /* if we have no windowId we are going to close all this container (used for deleting) */
@ -197,7 +197,7 @@ const backgroundLogic = {
return browser.tabs.remove(tabIds); return browser.tabs.remove(tabIds);
}, },
async queryIdentitiesState(windowId) { const queryIdentitiesState = async (windowId) => {
const identities = await browser.contextualIdentities.query({}); const identities = await browser.contextualIdentities.query({});
const identitiesOutput = {}; const identitiesOutput = {};
const identitiesPromise = identities.map(async function (identity) { const identitiesPromise = identities.map(async function (identity) {
@ -217,7 +217,7 @@ const backgroundLogic = {
return identitiesOutput; return identitiesOutput;
}, },
async sortTabs() { const sortTabs = async () => {
const windows = await browser.windows.getAll(); const windows = await browser.windows.getAll();
for (let windowObj of windows) { // eslint-disable-line prefer-const for (let windowObj of windows) { // eslint-disable-line prefer-const
// First the pinned tabs, then the normal ones. // First the pinned tabs, then the normal ones.
@ -226,7 +226,7 @@ const backgroundLogic = {
} }
}, },
async _sortTabsInternal(windowObj, pinnedTabs) { const _sortTabsInternal = async (windowObj, pinnedTabs) => {
const tabs = await browser.tabs.query({windowId: windowObj.id}); const tabs = await browser.tabs.query({windowId: windowObj.id});
let pos = 0; let pos = 0;
@ -266,7 +266,7 @@ const backgroundLogic = {
}); });
}, },
async hideTabs(options) { const hideTabs = async (options) => {
const requiredArguments = ["cookieStoreId", "windowId"]; const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "hideTabs"); this.checkArgs(requiredArguments, options, "hideTabs");
const { cookieStoreId, windowId } = options; const { cookieStoreId, windowId } = options;
@ -278,7 +278,7 @@ const backgroundLogic = {
return containerState; return containerState;
}, },
async showTabs(options) { const showTabs = async (options) => {
if (!("cookieStoreId" in options)) { if (!("cookieStoreId" in options)) {
return Promise.reject("showTabs must be called with cookieStoreId argument."); return Promise.reject("showTabs must be called with cookieStoreId argument.");
} }

View file

@ -1,6 +1,6 @@
const MAJOR_VERSIONS = ["2.3.0", "2.4.0"]; const MAJOR_VERSIONS = ["2.3.0", "2.4.0"];
const badge = { const badge = {
async init() { const init = async () => {
const currentWindow = await browser.windows.getCurrent(); const currentWindow = await browser.windows.getCurrent();
this.displayBrowserActionBadge(currentWindow.incognito); this.displayBrowserActionBadge(currentWindow.incognito);
}, },
@ -10,7 +10,7 @@ const badge = {
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" }); browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
}, },
async displayBrowserActionBadge() { const displayBrowserActionBadge = async () => {
const extensionInfo = await backgroundLogic.getExtensionInfo(); const extensionInfo = await backgroundLogic.getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []}); const storage = await browser.storage.local.get({browserActionBadgesClicked: []});

View file

@ -7,7 +7,7 @@ const identityState = {
return `${storagePrefix}${cookieStoreId}`; return `${storagePrefix}${cookieStoreId}`;
}, },
async get(cookieStoreId) { const get = async (cookieStoreId) => {
const storeKey = this.getContainerStoreKey(cookieStoreId); const storeKey = this.getContainerStoreKey(cookieStoreId);
const storageResponse = await this.area.get([storeKey]); const storageResponse = await this.area.get([storeKey]);
if (storageResponse && storeKey in storageResponse) { if (storageResponse && storeKey in storageResponse) {
@ -36,7 +36,7 @@ const identityState = {
return Object.assign({}, tab); return Object.assign({}, tab);
}, },
async storeHidden(cookieStoreId, windowId) { const storeHidden = async (cookieStoreId, windowId) => {
const containerState = await this.storageArea.get(cookieStoreId); const containerState = await this.storageArea.get(cookieStoreId);
const tabsByContainer = await browser.tabs.query({cookieStoreId, windowId}); const tabsByContainer = await browser.tabs.query({cookieStoreId, windowId});
tabsByContainer.forEach((tab) => { tabsByContainer.forEach((tab) => {

View file

@ -164,7 +164,7 @@ const messageHandler = {
}); });
}, },
async incrementCountOfContainerTabsOpened() { const incrementCountOfContainerTabsOpened = async () => {
const key = "containerTabsOpened"; const key = "containerTabsOpened";
const count = await browser.storage.local.get({[key]: 0}); const count = await browser.storage.local.get({[key]: 0});
const countOfContainerTabsOpened = ++count[key]; const countOfContainerTabsOpened = ++count[key];
@ -182,7 +182,7 @@ const messageHandler = {
} }
}, },
async unhideContainer(cookieStoreId) { const unhideContainer = async (cookieStoreId) => {
if (!this.unhideQueue.includes(cookieStoreId)) { if (!this.unhideQueue.includes(cookieStoreId)) {
this.unhideQueue.push(cookieStoreId); this.unhideQueue.push(cookieStoreId);
// Unhide all hidden tabs // Unhide all hidden tabs
@ -193,7 +193,7 @@ const messageHandler = {
} }
}, },
async onFocusChangedCallback(windowId) { const onFocusChangedCallback = async (windowId) => {
assignManager.removeContextMenu(); assignManager.removeContextMenu();
// browserAction loses background color in new windows ... // browserAction loses background color in new windows ...
// https://bugzil.la/1314674 // https://bugzil.la/1314674

View file

@ -1,4 +1,4 @@
async function load() { const load = async () => {
const searchParams = new URL(window.location).searchParams; const searchParams = new URL(window.location).searchParams;
const redirectUrl = decodeURIComponent(searchParams.get("url")); const redirectUrl = decodeURIComponent(searchParams.get("url"));
const cookieStoreId = searchParams.get("cookieStoreId"); const cookieStoreId = searchParams.get("cookieStoreId");
@ -59,7 +59,7 @@ function getCurrentTab() {
}); });
} }
async function denySubmit(redirectUrl) { const denySubmit = async (redirectUrl) =>{
const tab = await getCurrentTab(); const tab = await getCurrentTab();
await browser.runtime.sendMessage({ await browser.runtime.sendMessage({
method: "exemptContainerAssignment", method: "exemptContainerAssignment",
@ -71,7 +71,7 @@ async function denySubmit(redirectUrl) {
load(); load();
async function openInContainer(redirectUrl, cookieStoreId) { const openInContainer = async (redirectUrl, cookieStoreId) => {
const tab = await getCurrentTab(); const tab = await getCurrentTab();
await browser.tabs.create({ await browser.tabs.create({
index: tab[0].index + 1, index: tab[0].index + 1,

View file

@ -1,10 +1,10 @@
async function delayAnimation(delay = 350) { const delayAnimation = async (delay = 350) => {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, delay); setTimeout(resolve, delay);
}); });
} }
async function doAnimation(element, property, value) { const doAnimation = async (element, property, value) => {
return new Promise((resolve) => { return new Promise((resolve) => {
const handler = () => { const handler = () => {
resolve(); resolve();
@ -17,7 +17,7 @@ async function doAnimation(element, property, value) {
}); });
} }
async function addMessage(message) { const addMessage = async (message) => {
const divElement = document.createElement("div"); const divElement = document.createElement("div");
divElement.classList.add("container-notification"); divElement.classList.add("container-notification");
// Ideally we would use https://bugzilla.mozilla.org/show_bug.cgi?id=1340930 when this is available // Ideally we would use https://bugzilla.mozilla.org/show_bug.cgi?id=1340930 when this is available

View file

@ -60,7 +60,7 @@ function escaped(strings, ...values) {
return result.join(""); return result.join("");
} }
async function getExtensionInfo() { const getExtensionInfo = async () => {
const manifestPath = browser.extension.getURL("manifest.json"); const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath); const response = await fetch(manifestPath);
const extensionInfo = await response.json(); const extensionInfo = await response.json();
@ -76,7 +76,7 @@ const Logic = {
_panels: {}, _panels: {},
_onboardingVariation: null, _onboardingVariation: null,
async init() { const init = async () => {
// Remove browserAction "upgraded" badge when opening panel // Remove browserAction "upgraded" badge when opening panel
this.clearBrowserActionBadge(); this.clearBrowserActionBadge();
@ -122,7 +122,7 @@ const Logic = {
}, },
async showAchievementOrContainersListPanel() { const showAchievementOrContainersListPanel = async () => {
// Do we need to show an achievement panel? // Do we need to show an achievement panel?
let showAchievements = false; let showAchievements = false;
const achievementsStorage = await browser.storage.local.get({achievements: []}); const achievementsStorage = await browser.storage.local.get({achievements: []});
@ -141,7 +141,7 @@ const Logic = {
// In case the user wants to click multiple actions, // In case the user wants to click multiple actions,
// they have to click the "Done" button to stop the panel // they have to click the "Done" button to stop the panel
// from showing // from showing
async setAchievementDone(achievementName) { const setAchievementDone = async (achievementName) => {
const achievementsStorage = await browser.storage.local.get({achievements: []}); const achievementsStorage = await browser.storage.local.get({achievements: []});
const achievements = achievementsStorage.achievements; const achievements = achievementsStorage.achievements;
achievements.forEach((achievement, index, achievementsArray) => { achievements.forEach((achievement, index, achievementsArray) => {
@ -159,7 +159,7 @@ const Logic = {
}); });
}, },
async clearBrowserActionBadge() { const clearBrowserActionBadge = async () => {
const extensionInfo = await getExtensionInfo(); const extensionInfo = await getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []}); const storage = await browser.storage.local.get({browserActionBadgesClicked: []});
browser.browserAction.setBadgeBackgroundColor({color: ""}); browser.browserAction.setBadgeBackgroundColor({color: ""});
@ -172,7 +172,7 @@ const Logic = {
}); });
}, },
async identity(cookieStoreId) { const identity = async (cookieStoreId) => {
const defaultContainer = { const defaultContainer = {
name: "Default", name: "Default",
cookieStoreId, cookieStoreId,
@ -204,7 +204,7 @@ const Logic = {
return (userContextId !== cookieStoreId) ? Number(userContextId) : false; return (userContextId !== cookieStoreId) ? Number(userContextId) : false;
}, },
async currentTab() { const currentTab = async () => {
const activeTabs = await browser.tabs.query({active: true, windowId: browser.windows.WINDOW_ID_CURRENT}); const activeTabs = await browser.tabs.query({active: true, windowId: browser.windows.WINDOW_ID_CURRENT});
if (activeTabs.length > 0) { if (activeTabs.length > 0) {
return activeTabs[0]; return activeTabs[0];
@ -212,7 +212,7 @@ const Logic = {
return false; return false;
}, },
async numTabs() { const numTabs = async () => {
const activeTabs = await browser.tabs.query({windowId: browser.windows.WINDOW_ID_CURRENT}); const activeTabs = await browser.tabs.query({windowId: browser.windows.WINDOW_ID_CURRENT});
return activeTabs.length; return activeTabs.length;
}, },
@ -233,7 +233,7 @@ const Logic = {
moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling); moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling);
}, },
async refreshIdentities() { const refreshIdentities = async () => {
const [identities, state] = await Promise.all([ const [identities, state] = await Promise.all([
browser.contextualIdentities.query({}), browser.contextualIdentities.query({}),
browser.runtime.sendMessage({ browser.runtime.sendMessage({
@ -262,7 +262,7 @@ const Logic = {
} }
}, },
async showPanel(panel, currentIdentity = null) { const showPanel = async (panel, currentIdentity = null) => {
// Invalid panel... ?!? // Invalid panel... ?!?
if (!(panel in this._panels)) { if (!(panel in this._panels)) {
throw new Error("Something really bad happened. Unknown panel: " + panel); throw new Error("Something really bad happened. Unknown panel: " + panel);
@ -501,7 +501,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
panelSelector: "#container-panel", panelSelector: "#container-panel",
// This method is called when the object is registered. // This method is called when the object is registered.
async initialize() { const initialize = async () => {
Logic.addEnterHandler(document.querySelector("#container-add-link"), () => { Logic.addEnterHandler(document.querySelector("#container-add-link"), () => {
Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() }); Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() });
}); });
@ -589,7 +589,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
assignmentCheckboxElement.disabled = disabled; assignmentCheckboxElement.disabled = disabled;
}, },
async prepareCurrentTabHeader() { const prepareCurrentTabHeader = async () => {
const currentTab = await Logic.currentTab(); const currentTab = await Logic.currentTab();
const currentTabElement = document.getElementById("current-tab"); const currentTabElement = document.getElementById("current-tab");
const assignmentCheckboxElement = document.getElementById("container-page-assigned"); const assignmentCheckboxElement = document.getElementById("container-page-assigned");
@ -616,7 +616,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
}, },
// This method is called when the panel is shown. // This method is called when the panel is shown.
async prepare() { const prepare = async () => {
const fragment = document.createDocumentFragment(); const fragment = document.createDocumentFragment();
this.prepareCurrentTabHeader(); this.prepareCurrentTabHeader();
@ -699,7 +699,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
panelSelector: "#container-info-panel", panelSelector: "#container-info-panel",
// This method is called when the object is registered. // This method is called when the object is registered.
async initialize() { const initialize = async () => {
Logic.addEnterHandler(document.querySelector("#close-container-info-panel"), () => { Logic.addEnterHandler(document.querySelector("#close-container-info-panel"), () => {
Logic.showPreviousPanel(); Logic.showPreviousPanel();
}); });
@ -747,7 +747,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
}, },
// This method is called when the panel is shown. // This method is called when the panel is shown.
async prepare() { const prepare = async () => {
const identity = Logic.currentIdentity(); const identity = Logic.currentIdentity();
// Populating the panel: name and icon // Populating the panel: name and icon
@ -911,7 +911,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
}, },
async _submitForm() { const _submitForm = async () => {
const formValues = new FormData(this._editForm); const formValues = new FormData(this._editForm);
try { try {
await browser.runtime.sendMessage({ await browser.runtime.sendMessage({
@ -1006,7 +1006,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
}, },
// This method is called when the panel is shown. // This method is called when the panel is shown.
async prepare() { const prepare = () => {
const identity = Logic.currentIdentity(); const identity = Logic.currentIdentity();
const userContextId = Logic.currentUserContextId(); const userContextId = Logic.currentUserContextId();