Replace forEach() with for()

This commit is contained in:
redphx 2024-10-22 10:42:09 +07:00
parent 01502363ab
commit 6cfff0274d
7 changed files with 25 additions and 16 deletions

View File

@ -73,7 +73,8 @@ export class ControllerShortcut {
const pressed: boolean[] = [];
let otherButtonPressed = false;
gamepad.buttons.forEach((button, index) => {
const entries = gamepad.buttons.entries();
for (const [index, button] of entries) {
// Only add the newly pressed button to the array (holding doesn't count)
if (button.pressed && index !== GamepadKey.HOME) {
otherButtonPressed = true;
@ -84,7 +85,7 @@ export class ControllerShortcut {
setTimeout(() => ControllerShortcut.runAction(actions[index]!), 0);
}
}
});
};
ControllerShortcut.buttonsStatus[gamepadIndex] = pressed;
return otherButtonPressed;

View File

@ -130,6 +130,8 @@ export class GameBar {
// Reset all states
reset() {
this.actions.forEach(action => action.reset());
for (const action of this.actions) {
action.reset();
}
}
}

View File

@ -835,10 +835,10 @@ true` + text;
[UiSection.MOST_POPULAR]: GamePassCloudGallery.MOST_POPULAR,
};
PREF_HIDE_SECTIONS.forEach(section => {
for (const section of PREF_HIDE_SECTIONS) {
const galleryId = sections[section];
galleryId && siglIds.push(galleryId);
});
};
const checkSyntax = siglIds.map(item => `siglId === "${item}"`).join(' || ');

View File

@ -219,9 +219,10 @@ export class StreamBadges {
];
const $container = CE('div', {class: 'bx-badges'});
BADGES.forEach(item => {
for (const item of BADGES) {
if (!item) {
return;
continue;
}
let $badge: HTMLElement;
@ -232,7 +233,7 @@ export class StreamBadges {
}
$container.appendChild($badge);
});
};
this.$container = $container;
await this.start();

View File

@ -221,9 +221,10 @@ export class StreamUiHandler {
}
const observer = new MutationObserver(mutationList => {
mutationList.forEach(item => {
let item: MutationRecord;
for (item of mutationList) {
if (item.type !== 'childList') {
return;
continue;
}
item.addedNodes.forEach(async $node => {
@ -263,7 +264,7 @@ export class StreamUiHandler {
// Handle System Menu bar
StreamUiHandler.handleSystemMenu($elm);
});
});
};
});
observer.observe($screen, {subtree: true, childList: true});

View File

@ -177,8 +177,9 @@ export class NavigationDialogManager {
}
calculateSelectBoxes($root: HTMLElement) {
const $selects = $root.querySelectorAll('.bx-select:not([data-calculated]) select');
$selects.forEach($select => {
const selects = Array.from($root.querySelectorAll('.bx-select:not([data-calculated]) select'));
for (const $select of selects) {
const $parent = $select.parentElement! as HTMLElement;
// Don't apply to select.bx-full-width elements
@ -205,7 +206,7 @@ export class NavigationDialogManager {
// Set min-width
$label.style.minWidth = width + 'px';
$parent.dataset.calculated = 'true';
});
};
}
handleEvent(event: Event) {

View File

@ -121,9 +121,12 @@ export function createButton<T=HTMLButtonElement>(options: BxButton): T {
}
const style = (options.style || 0) as number;
style && ButtonStyleIndices.forEach((index: keyof typeof ButtonStyleClass) => {
if (style) {
let index: keyof typeof ButtonStyleClass;
for (index of ButtonStyleIndices) {
(style & index) && $btn.classList.add(ButtonStyleClass[index] as string);
});
}
}
options.classes && $btn.classList.add(...options.classes);