@@ -42,7 +42,7 @@ <h1>OffscreenCanvas and worker threads</h1>
42
42
< div class ="canvases ">
43
43
< div >
44
44
< span class ="canvas-title "> Canvas A</ span >
45
- < canvas id ="canvas main " width ="200 " height ="200 "> </ canvas >
45
+ < canvas id ="main " width ="200 " height ="200 "> </ canvas >
46
46
< div >
47
47
< button id ="main-button " onclick ="slowMainThread() ">
48
48
Block main thread
@@ -51,7 +51,7 @@ <h1>OffscreenCanvas and worker threads</h1>
51
51
</ div >
52
52
< div >
53
53
< span class ="canvas-title "> Canvas B</ span >
54
- < canvas id ="canvas worker " width ="200 " height ="200 "> </ canvas >
54
+ < canvas id ="worker " width ="200 " height ="200 "> </ canvas >
55
55
56
56
< div >
57
57
< button id ="worker-button " onclick ="slowdownWorker() ">
@@ -83,18 +83,16 @@ <h1>OffscreenCanvas and worker threads</h1>
83
83
</ main >
84
84
85
85
< script >
86
- const requestAnimationFrame = window . requestAnimationFrame ;
87
-
88
- const canvasA = document . getElementById ( "canvas main" ) ;
89
- const canvasB = document . getElementById ( "canvas worker" ) ;
86
+ const canvasA = document . getElementById ( "main" ) ;
87
+ const canvasB = document . getElementById ( "worker" ) ;
90
88
91
89
const ctxA = canvasA . getContext ( "2d" ) ;
92
90
const canvasWidth = ctxA . width ;
93
91
const canvasHeight = ctxA . height ;
94
92
95
93
// Create a counter for Canvas A
96
94
let counter = 0 ;
97
- setInterval ( function ( ) {
95
+ setInterval ( ( ) => {
98
96
redrawCanvasA ( ) ;
99
97
counter ++ ;
100
98
} , 100 ) ;
@@ -109,7 +107,9 @@ <h1>OffscreenCanvas and worker threads</h1>
109
107
110
108
// This function creates heavy (blocking) work on a thread
111
109
function fibonacci ( num ) {
112
- if ( num <= 1 ) return 1 ;
110
+ if ( num <= 1 ) {
111
+ return 1 ;
112
+ }
113
113
return fibonacci ( num - 1 ) + fibonacci ( num - 2 ) ;
114
114
}
115
115
0 commit comments