11<template >
2- <table class =" table is-fullwidth" >
3- <thead >
4- <tr >
5- <th >Prop</th >
6- <th >Description</th >
7- <th >Value</th >
8- </tr >
9- </thead >
10- <tbody >
11- <tr >
12- <td >callbackCounter</td >
13- <td >Raf callback counter</td >
14- <td >
15- <span >{{ callbackCounter }}</span >
16- </td >
17- </tr >
18- <tr >
19- <td >animDuration</td >
20- <td >Raf callback counter</td >
21- <td >
22- <span >{{ animDuration }}s</span >
23- </td >
24- </tr >
25- <tr >
26- <td colspan =" 2" >
27- <button class =" button is-primary" @click =" start" v-if =" !isRunning" >
28- Resume animation
29- </button >
30- <button class =" button is-danger" @click =" stop" v-else >
31- Stop animation
32- </button >
33- <br />
34- <br />
35- <br />
36- <input type =" number" min =" 1" max =" 121" v-model =" fpsRef" />
37- </td >
38- </tr >
39- </tbody >
40- </table >
2+ <div >
3+ <table class =" table is-fullwidth" >
4+ <thead >
5+ <tr >
6+ <th >Prop</th >
7+ <th >Description</th >
8+ <th >Value</th >
9+ </tr >
10+ </thead >
11+ <tbody >
12+ <tr >
13+ <td >callbackCounter</td >
14+ <td >
15+ Counter showing how many times the callback was called within the
16+ Raf loop
17+ </td >
18+ <td >
19+ <span >{{ callbackCounter }}</span >
20+ </td >
21+ </tr >
22+ <tr >
23+ <td >timeElapsed</td >
24+ <td >Total time elapsed</td >
25+ <td >
26+ <span >{{ timeElapsed }}ms</span >
27+ </td >
28+ </tr >
29+ </tbody >
30+ </table >
31+ <div class =" form" >
32+ <div class =" field" >
33+ <label class =" label" >Frames per second (fps)</label >
34+ <div class =" control" >
35+ <input class =" input" type =" number" min =" 1" max =" 121" v-model =" fps" />
36+ </div >
37+ </div >
38+ <div class =" field" >
39+ <button
40+ class =" button is-primary"
41+ @click ="
42+ start()
43+ init()
44+ "
45+ v-if =" !isRunning"
46+ >
47+ {{ isInit ? 'Resume timer' : 'Start timer' }}
48+ </button >
49+ <button class =" button is-danger" @click =" stop" v-else >
50+ Stop timer
51+ </button >
52+ </div >
53+ </div >
54+ </div >
4155</template >
4256
4357<script lang="ts">
@@ -48,16 +62,37 @@ import { useRafFn } from '../../../vue-use-kit'
4862export default Vue .extend ({
4963 name: ' UseRafFnDemo' ,
5064 setup() {
51- const animDuration = ref (0 )
65+ const isInit = ref (false )
66+ const timeElapsed = ref (0 )
5267 const callbackCounter = ref (0 )
53- const fpsRef = ref (120 )
68+ const fps = ref (120 )
5469 const animHandler = (t : number ) => {
5570 callbackCounter .value = callbackCounter .value + 1
56- animDuration .value = Math .ceil (t )
71+ timeElapsed .value = Math .ceil (t )
5772 }
5873
59- const { isRunning, start, stop } = useRafFn (animHandler , fpsRef , false )
60- return { isRunning , start , stop , callbackCounter , animDuration , fpsRef }
74+ const init = () => {
75+ isInit .value = true
76+ }
77+
78+ const { isRunning, start, stop } = useRafFn (animHandler , fps , false )
79+
80+ return {
81+ init ,
82+ isInit ,
83+ isRunning ,
84+ start ,
85+ stop ,
86+ callbackCounter ,
87+ timeElapsed ,
88+ fps
89+ }
6190 }
6291})
6392 </script >
93+
94+ <style >
95+ .form {
96+ max-width : 400px ;
97+ }
98+ </style >
0 commit comments