Skip to content

Commit ddd79e3

Browse files
authored
tutorial: remove unneccessary performance.now() call inside raf (#5513)
1 parent e750b72 commit ddd79e3

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

site/content/tutorial/06-bindings/12-bind-this/app-a/App.svelte

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
66
onMount(() => {
77
const ctx = canvas.getContext('2d');
8-
let frame;
8+
let frame = requestAnimationFrame(loop);
99
10-
(function loop() {
10+
function loop(t) {
1111
frame = requestAnimationFrame(loop);
1212
1313
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
@@ -17,8 +17,6 @@
1717
const x = i % canvas.width;
1818
const y = i / canvas.height >>> 0;
1919
20-
const t = window.performance.now();
21-
2220
const r = 64 + (128 * x / canvas.width) + (64 * Math.sin(t / 1000));
2321
const g = 64 + (128 * y / canvas.height) + (64 * Math.cos(t / 1000));
2422
const b = 128;
@@ -30,7 +28,7 @@
3028
}
3129
3230
ctx.putImageData(imageData, 0, 0);
33-
}());
31+
}
3432
3533
return () => {
3634
cancelAnimationFrame(frame);

site/content/tutorial/06-bindings/12-bind-this/app-b/App.svelte

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
66
onMount(() => {
77
const ctx = canvas.getContext('2d');
8-
let frame;
8+
let frame = requestAnimationFrame(loop);
99
10-
(function loop() {
10+
function loop(t) {
1111
frame = requestAnimationFrame(loop);
1212
1313
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
@@ -17,8 +17,6 @@
1717
const x = i % canvas.width;
1818
const y = i / canvas.height >>> 0;
1919
20-
const t = window.performance.now();
21-
2220
const r = 64 + (128 * x / canvas.width) + (64 * Math.sin(t / 1000));
2321
const g = 64 + (128 * y / canvas.height) + (64 * Math.cos(t / 1000));
2422
const b = 128;
@@ -30,7 +28,7 @@
3028
}
3129
3230
ctx.putImageData(imageData, 0, 0);
33-
}());
31+
}
3432
3533
return () => {
3634
cancelAnimationFrame(frame);

0 commit comments

Comments
 (0)