Skip to content

Commit

Permalink
set handle value (#33827)
Browse files Browse the repository at this point in the history
`handle` is passed to `self.cancelAnimationFrame`, but it was never declared nor set to anything.
  • Loading branch information
hotsphink authored May 30, 2024
1 parent 232e561 commit 26f776d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,20 @@ When receiving the `"start"` message, the worker starts the animation, moving th
```js
let ctx;
let pos = 0;
let handle;

function draw(dt) {
ctx.clearRect(0, 0, 100, 100);
ctx.fillRect(pos, 0, 10, 10);
pos += 10 * dt;
self.requestAnimationFrame(draw);
handle = self.requestAnimationFrame(draw);
}

self.addEventListener("message", (e) => {
if (e.data.type === "start") {
const transferredCanvas = e.data.canvas;
ctx = transferredCanvas.getContext("2d");
self.requestAnimationFrame(draw);
handle = self.requestAnimationFrame(draw);
}
if (e.data.type === "stop") {
self.cancelAnimationFrame(handle);
Expand Down

0 comments on commit 26f776d

Please sign in to comment.