refactor: replace .forEach() with for-of (#39691)

* refactor: replace `.forEach()` with `for-of`

* refactor docs/fiddles/features/web-hid/renderer.js
This commit is contained in:
Milan Burda 2023-08-31 16:36:43 +02:00 committed by GitHub
parent 7858921a1f
commit 0b0707145b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 144 additions and 132 deletions

View file

@ -1,19 +1,10 @@
async function testIt () {
const grantedDevices = await navigator.hid.getDevices()
let grantedDeviceList = ''
grantedDevices.forEach(device => {
grantedDeviceList += `<hr>${device.productName}</hr>`
})
document.getElementById('granted-devices').innerHTML = grantedDeviceList
const grantedDevices2 = await navigator.hid.requestDevice({
filters: []
})
function formatDevices (devices) {
return devices.map(device => device.productName).join('<hr>')
}
grantedDeviceList = ''
grantedDevices2.forEach(device => {
grantedDeviceList += `<hr>${device.productName}</hr>`
})
document.getElementById('granted-devices2').innerHTML = grantedDeviceList
async function testIt () {
document.getElementById('granted-devices').innerHTML = formatDevices(await navigator.hid.getDevices())
document.getElementById('granted-devices2').innerHTML = formatDevices(await navigator.hid.requestDevice({ filters: [] }))
}
document.getElementById('clickme').addEventListener('click', testIt)

View file

@ -7,9 +7,9 @@ async function testIt () {
const grantedDevices = await navigator.usb.getDevices()
let grantedDeviceList = ''
if (grantedDevices.length > 0) {
grantedDevices.forEach(device => {
for (const device of grantedDevices) {
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
})
}
} else {
grantedDeviceList = noDevicesFoundMsg
}

View file

@ -68,9 +68,9 @@ const template = [
// on reload, start fresh and close any old
// open secondary windows
if (focusedWindow.id === 1) {
BrowserWindow.getAllWindows().forEach(win => {
for (const win of BrowserWindow.getAllWindows()) {
if (win.id > 1) win.close()
})
}
}
focusedWindow.reload()
}
@ -209,15 +209,15 @@ function findReopenMenuItem () {
if (!menu) return
let reopenMenuItem
menu.items.forEach(item => {
for (const item of menu.items) {
if (item.submenu) {
item.submenu.items.forEach(item => {
if (item.key === 'reopenMenuItem') {
reopenMenuItem = item
for (const subitem of item.submenu.items) {
if (subitem.key === 'reopenMenuItem') {
reopenMenuItem = subitem
}
})
}
}
})
}
return reopenMenuItem
}

View file

@ -167,11 +167,11 @@ const supportBinaries = await msiCreator.create()
// 🆕 Step 2a: optionally sign support binaries if you
// sign you binaries as part of of your packaging script
supportBinaries.forEach(async (binary) => {
for (const binary of supportBinaries) {
// Binaries are the new stub executable and optionally
// the Squirrel auto updater.
await signFile(binary)
})
}
// Step 3: Compile the template to a .msi file
await msiCreator.compile()

View file

@ -46,7 +46,7 @@ inAppPurchase.on('transactions-updated', (event, transactions) => {
}
// Check each transaction.
transactions.forEach((transaction) => {
for (const transaction of transactions) {
const payment = transaction.payment
switch (transaction.transactionState) {
@ -95,7 +95,7 @@ inAppPurchase.on('transactions-updated', (event, transactions) => {
default:
break
}
})
}
})
// Check if the user is allowed to make in-app purchase.
@ -112,9 +112,9 @@ inAppPurchase.getProducts(PRODUCT_IDS).then(products => {
}
// Display the name and price of each product.
products.forEach(product => {
for (const product of products) {
console.log(`The price of ${product.localizedTitle} is ${product.formattedPrice}.`)
})
}
// Ask the user which product they want to purchase.
const selectedProduct = products[0]