File tree Expand file tree Collapse file tree 3 files changed +5
-12
lines changed Expand file tree Collapse file tree 3 files changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ export function Game({
92
92
* MARK: Init
93
93
*/
94
94
95
- const keydownListener = $ . on ( document , 'keydown' , ( e ) => {
95
+ $ . on ( document , 'keydown' , ( e ) => {
96
96
if ( e . key === 'p' ) {
97
97
isPaused = ! isPaused ;
98
98
if ( isPaused ) $ . audio . pause ( ) ;
@@ -108,10 +108,7 @@ export function Game({
108
108
109
109
$ . audio . register ( data . gameSound ) ;
110
110
111
- el . $unmount = ( ) => {
112
- $ . audio . stop ( ) ;
113
- keydownListener ( ) ;
114
- } ;
111
+ el . $unmount = ( ) => $ . audio . stop ( ) ;
115
112
} }
116
113
</ Script >
117
114
</ div >
Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ export function SnakeGame() {
271
271
clearSegmentTimer ( ) ;
272
272
} ) ;
273
273
274
- const keyboardListener = $ . on ( document , 'keydown' , ( e ) => {
274
+ $ . on ( document , 'keydown' , ( e ) => {
275
275
if ( isPaused ) return ;
276
276
switch ( e . key ) {
277
277
case 'ArrowUp' :
@@ -288,7 +288,6 @@ export function SnakeGame() {
288
288
el . $unmount = ( ) => {
289
289
clearTimer ( ) ;
290
290
clearSegmentTimer ( ) ;
291
- keyboardListener ( ) ;
292
291
} ;
293
292
} }
294
293
</ Script >
Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ export function TetrisGame() {
237
237
238
238
el . $subscribe ( 'tetris:gameover' , ( ) => clearTimer ( ) ) ;
239
239
240
- const keydownhandler = $ . on ( document , 'keydown' , ( e ) => {
240
+ $ . on ( document , 'keydown' , ( e ) => {
241
241
if ( isPaused || ! tick ) return ;
242
242
let dir : TetrisGameEvents [ 'tetris:evt:move' ] | null = null ;
243
243
switch ( e . key ) {
@@ -260,10 +260,7 @@ export function TetrisGame() {
260
260
if ( dir ) el . $publish ( 'tetris:evt:move' , dir ) ;
261
261
} ) ;
262
262
263
- el . $unmount = ( ) => {
264
- keydownhandler ( ) ;
265
- clearTimer ( ) ;
266
- } ;
263
+ el . $unmount = ( ) => clearTimer ( ) ;
267
264
} }
268
265
</ Script >
269
266
</ Game >
You can’t perform that action at this time.
0 commit comments