Skip to content

Commit

Permalink
Rename mkRepeatCommand TODO complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSnail authored and philc committed Jan 4, 2025
1 parent 8d23c6f commit 9557cff
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,12 @@ function moveTab({ count, tab, registryEntry }) {
});
}

// TODO(philc): Rename to createRepeatCommand.
const mkRepeatCommand = (command) => (function (request) {
const createRepeatCommand = (command) => (function (request) {
request.count--;
if (request.count >= 0) {
// TODO(philc): I think we can remove this return statement, and all returns
// from commands built using mkRepeatCommand.
return command(request, (request) => (mkRepeatCommand(command))(request));
// from commands built using createRepeatCommand.
return command(request, (request) => (createRepeatCommand(command))(request));
}
});

Expand Down Expand Up @@ -216,7 +215,7 @@ const BackgroundCommands = {
// Create a new tab. Also, with:
// map X createTab http://www.bbc.com/news
// create a new tab with the given URL.
createTab: mkRepeatCommand(async function (request, callback) {
createTab: createRepeatCommand(async function (request, callback) {
if (request.urls == null) {
if (request.url) {
// If the request contains a URL, then use it.
Expand Down Expand Up @@ -273,7 +272,7 @@ const BackgroundCommands = {
}
}),

duplicateTab: mkRepeatCommand((request, callback) => {
duplicateTab: createRepeatCommand((request, callback) => {
return chrome.tabs.duplicate(
request.tabId,
(tab) => callback(Object.assign(request, { tab, tabId: tab.id })),
Expand Down Expand Up @@ -311,7 +310,7 @@ const BackgroundCommands = {
chrome.tabs.remove(tab.id);
});
},
restoreTab: mkRepeatCommand((request, callback) =>
restoreTab: createRepeatCommand((request, callback) =>
chrome.sessions.restore(null, callback(request))
),
async togglePinTab({ count, tab }) {
Expand Down Expand Up @@ -593,7 +592,7 @@ const sendRequestHandlers = {
getCurrentTabUrl({ tab }) {
return tab.url;
},
openUrlInNewTab: mkRepeatCommand((request, callback) =>
openUrlInNewTab: createRepeatCommand((request, callback) =>
TabOperations.openUrlInNewTab(request, callback)
),
openUrlInNewWindow(request) {
Expand Down

0 comments on commit 9557cff

Please sign in to comment.