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

View file

@ -7,7 +7,7 @@ const backgroundLogic = {
"about:blank"
]),
async getExtensionInfo() {
const getExtensionInfo = async () => {
const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath);
const extensionInfo = await response.json();
@ -25,7 +25,7 @@ const backgroundLogic = {
return false;
},
async deleteContainer(userContextId, removed = false) {
const deleteContainer = async (userContextId, removed = false) => {
await this._closeTabs(userContextId);
if (!removed) {
await browser.contextualIdentities.remove(this.cookieStoreId(userContextId));
@ -34,7 +34,7 @@ const backgroundLogic = {
return {done: true, userContextId};
},
async createOrUpdateContainer(options) {
const createOrUpdateContainer = async (options) => {
let donePromise;
if (options.userContextId !== "new") {
donePromise = browser.contextualIdentities.update(
@ -50,7 +50,7 @@ const backgroundLogic = {
});
},
async openNewTab(options) {
const openNewTab = async (options) => {
let url = options.url || undefined;
const userContextId = ("userContextId" in options) ? options.userContextId : 0;
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"];
this.checkArgs(requiredArguments, options, "getTabs");
const { cookieStoreId, windowId } = options;
@ -112,7 +112,7 @@ const backgroundLogic = {
return list.concat(containerState.hiddenTabs);
},
async moveTabsToWindow(options) {
const moveTabsToWindow = async (options) => {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "moveTabsToWindow");
const { cookieStoreId, windowId } = options;
@ -179,7 +179,7 @@ const backgroundLogic = {
return await identityState.storageArea.set(cookieStoreId, containerState);
},
async _closeTabs(userContextId, windowId = false) {
const _closeTabs = async (userContextId, windowId = false) => {
const cookieStoreId = this.cookieStoreId(userContextId);
let tabs;
/* 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);
},
async queryIdentitiesState(windowId) {
const queryIdentitiesState = async (windowId) => {
const identities = await browser.contextualIdentities.query({});
const identitiesOutput = {};
const identitiesPromise = identities.map(async function (identity) {
@ -217,7 +217,7 @@ const backgroundLogic = {
return identitiesOutput;
},
async sortTabs() {
const sortTabs = async () => {
const windows = await browser.windows.getAll();
for (let windowObj of windows) { // eslint-disable-line prefer-const
// 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});
let pos = 0;
@ -266,7 +266,7 @@ const backgroundLogic = {
});
},
async hideTabs(options) {
const hideTabs = async (options) => {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "hideTabs");
const { cookieStoreId, windowId } = options;
@ -278,7 +278,7 @@ const backgroundLogic = {
return containerState;
},
async showTabs(options) {
const showTabs = async (options) => {
if (!("cookieStoreId" in options)) {
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 badge = {
async init() {
const init = async () => {
const currentWindow = await browser.windows.getCurrent();
this.displayBrowserActionBadge(currentWindow.incognito);
},
@ -10,7 +10,7 @@ const badge = {
browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" });
},
async displayBrowserActionBadge() {
const displayBrowserActionBadge = async () => {
const extensionInfo = await backgroundLogic.getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []});

View file

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

View file

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

View file

@ -1,4 +1,4 @@
async function load() {
const load = async () => {
const searchParams = new URL(window.location).searchParams;
const redirectUrl = decodeURIComponent(searchParams.get("url"));
const cookieStoreId = searchParams.get("cookieStoreId");
@ -59,7 +59,7 @@ function getCurrentTab() {
});
}
async function denySubmit(redirectUrl) {
const denySubmit = async (redirectUrl) =>{
const tab = await getCurrentTab();
await browser.runtime.sendMessage({
method: "exemptContainerAssignment",
@ -71,7 +71,7 @@ async function denySubmit(redirectUrl) {
load();
async function openInContainer(redirectUrl, cookieStoreId) {
const openInContainer = async (redirectUrl, cookieStoreId) => {
const tab = await getCurrentTab();
await browser.tabs.create({
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) => {
setTimeout(resolve, delay);
});
}
async function doAnimation(element, property, value) {
const doAnimation = async (element, property, value) => {
return new Promise((resolve) => {
const handler = () => {
resolve();
@ -17,7 +17,7 @@ async function doAnimation(element, property, value) {
});
}
async function addMessage(message) {
const addMessage = async (message) => {
const divElement = document.createElement("div");
divElement.classList.add("container-notification");
// 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("");
}
async function getExtensionInfo() {
const getExtensionInfo = async () => {
const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath);
const extensionInfo = await response.json();
@ -76,7 +76,7 @@ const Logic = {
_panels: {},
_onboardingVariation: null,
async init() {
const init = async () => {
// Remove browserAction "upgraded" badge when opening panel
this.clearBrowserActionBadge();
@ -122,7 +122,7 @@ const Logic = {
},
async showAchievementOrContainersListPanel() {
const showAchievementOrContainersListPanel = async () => {
// Do we need to show an achievement panel?
let showAchievements = false;
const achievementsStorage = await browser.storage.local.get({achievements: []});
@ -141,7 +141,7 @@ const Logic = {
// In case the user wants to click multiple actions,
// they have to click the "Done" button to stop the panel
// from showing
async setAchievementDone(achievementName) {
const setAchievementDone = async (achievementName) => {
const achievementsStorage = await browser.storage.local.get({achievements: []});
const achievements = achievementsStorage.achievements;
achievements.forEach((achievement, index, achievementsArray) => {
@ -159,7 +159,7 @@ const Logic = {
});
},
async clearBrowserActionBadge() {
const clearBrowserActionBadge = async () => {
const extensionInfo = await getExtensionInfo();
const storage = await browser.storage.local.get({browserActionBadgesClicked: []});
browser.browserAction.setBadgeBackgroundColor({color: ""});
@ -172,7 +172,7 @@ const Logic = {
});
},
async identity(cookieStoreId) {
const identity = async (cookieStoreId) => {
const defaultContainer = {
name: "Default",
cookieStoreId,
@ -204,7 +204,7 @@ const Logic = {
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});
if (activeTabs.length > 0) {
return activeTabs[0];
@ -212,7 +212,7 @@ const Logic = {
return false;
},
async numTabs() {
const numTabs = async () => {
const activeTabs = await browser.tabs.query({windowId: browser.windows.WINDOW_ID_CURRENT});
return activeTabs.length;
},
@ -233,7 +233,7 @@ const Logic = {
moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling);
},
async refreshIdentities() {
const refreshIdentities = async () => {
const [identities, state] = await Promise.all([
browser.contextualIdentities.query({}),
browser.runtime.sendMessage({
@ -262,7 +262,7 @@ const Logic = {
}
},
async showPanel(panel, currentIdentity = null) {
const showPanel = async (panel, currentIdentity = null) => {
// Invalid panel... ?!?
if (!(panel in this._panels)) {
throw new Error("Something really bad happened. Unknown panel: " + panel);
@ -501,7 +501,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
panelSelector: "#container-panel",
// This method is called when the object is registered.
async initialize() {
const initialize = async () => {
Logic.addEnterHandler(document.querySelector("#container-add-link"), () => {
Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() });
});
@ -589,7 +589,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
assignmentCheckboxElement.disabled = disabled;
},
async prepareCurrentTabHeader() {
const prepareCurrentTabHeader = async () => {
const currentTab = await Logic.currentTab();
const currentTabElement = document.getElementById("current-tab");
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.
async prepare() {
const prepare = async () => {
const fragment = document.createDocumentFragment();
this.prepareCurrentTabHeader();
@ -699,7 +699,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
panelSelector: "#container-info-panel",
// This method is called when the object is registered.
async initialize() {
const initialize = async () => {
Logic.addEnterHandler(document.querySelector("#close-container-info-panel"), () => {
Logic.showPreviousPanel();
});
@ -747,7 +747,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
},
// This method is called when the panel is shown.
async prepare() {
const prepare = async () => {
const identity = Logic.currentIdentity();
// 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);
try {
await browser.runtime.sendMessage({
@ -1006,7 +1006,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
},
// This method is called when the panel is shown.
async prepare() {
const prepare = () => {
const identity = Logic.currentIdentity();
const userContextId = Logic.currentUserContextId();