Skip to content

Commit 47b9540

Browse files
authored
Minor cleanups to src/library_sdl.js. NFC (#22874)
- Use for-of loop - Put each case statement on its own line
1 parent bf9f334 commit 47b9540

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/library_sdl.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,16 @@ var LibrarySDL = {
553553
receiveEvent(event) {
554554
function unpressAllPressedKeys() {
555555
// Un-press all pressed keys: TODO
556-
for (var code in SDL.keyboardMap) {
556+
for (var keyCode of SDL.keyboardMap) {
557557
SDL.events.push({
558558
type: 'keyup',
559-
keyCode: SDL.keyboardMap[code]
559+
keyCode,
560560
});
561561
}
562562
};
563563
switch (event.type) {
564-
case 'touchstart': case 'touchmove': {
564+
case 'touchstart':
565+
case 'touchmove': {
565566
event.preventDefault();
566567

567568
var touches = [];
@@ -637,7 +638,9 @@ var LibrarySDL = {
637638
};
638639
break;
639640
}
640-
case 'DOMMouseScroll': case 'mousewheel': case 'wheel':
641+
case 'DOMMouseScroll':
642+
case 'mousewheel':
643+
case 'wheel':
641644
// Flip the wheel direction to translate from browser wheel direction
642645
// (+:down) to SDL direction (+:up)
643646
var delta = -Browser.getMouseWheelDelta(event);
@@ -684,7 +687,11 @@ var LibrarySDL = {
684687
}
685688
}
686689
// fall through
687-
case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup':
690+
case 'keydown':
691+
case 'keyup':
692+
case 'keypress':
693+
case 'mousedown':
694+
case 'mouseup':
688695
// If we preventDefault on keydown events, the subsequent keypress events
689696
// won't fire. However, it's fine (and in some cases necessary) to
690697
// preventDefault for keys that don't generate a character. Otherwise,
@@ -834,11 +841,14 @@ var LibrarySDL = {
834841
event.handled = true;
835842

836843
switch (event.type) {
837-
case 'touchstart': case 'touchend': case 'touchmove': {
844+
case 'touchstart':
845+
case 'touchend':
846+
case 'touchmove': {
838847
Browser.calculateMouseEvent(event);
839848
break;
840849
}
841-
case 'keydown': case 'keyup': {
850+
case 'keydown':
851+
case 'keyup': {
842852
var down = event.type === 'keydown';
843853
var code = SDL.lookupKeyCodeForEvent(event);
844854
#if !SAFE_HEAP
@@ -863,7 +873,8 @@ var LibrarySDL = {
863873

864874
break;
865875
}
866-
case 'mousedown': case 'mouseup':
876+
case 'mousedown':
877+
case 'mouseup':
867878
if (event.type == 'mousedown') {
868879
// SDL_BUTTON(x) is defined as (1 << ((x)-1)). SDL buttons are 1-3,
869880
// and DOM buttons are 0-2, so this means that the below formula is
@@ -1478,11 +1489,7 @@ var LibrarySDL = {
14781489
SDL.addedResizeListener = true;
14791490
Browser.resizeListeners.push((w, h) => {
14801491
if (!SDL.settingVideoMode) {
1481-
SDL.receiveEvent({
1482-
type: 'resize',
1483-
w,
1484-
h
1485-
});
1492+
SDL.receiveEvent({ type: 'resize', w, h });
14861493
}
14871494
});
14881495
}

0 commit comments

Comments
 (0)