Skip to content

Commit 5762c9a

Browse files
authored
Update 7guis-timer
1 parent bc2d30c commit 5762c9a

File tree

1 file changed

+7
-5
lines changed
  • documentation/examples/20-7guis/04-7guis-timer

1 file changed

+7
-5
lines changed

documentation/examples/20-7guis/04-7guis-timer/App.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<!-- https://eugenkiss.github.io/7guis/tasks#timer -->
22

33
<script>
4-
import { onDestroy } from 'svelte';
4+
import { onMount } from 'svelte';
55
66
let elapsed = 0;
77
let duration = 5000;
88
99
let last_time = window.performance.now();
1010
let frame;
1111
12-
(function update() {
12+
const update = () => {
1313
frame = requestAnimationFrame(update);
1414
1515
const time = window.performance.now();
1616
elapsed += Math.min(time - last_time, duration - elapsed);
1717
1818
last_time = time;
19-
})();
19+
};
2020
21-
onDestroy(() => {
22-
cancelAnimationFrame(frame);
21+
onMount(() => {
22+
update()
23+
24+
return () => cancelAnimationFrame(frame)
2325
});
2426
</script>
2527

0 commit comments

Comments
 (0)