File tree 1 file changed +20
-6
lines changed
1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change 1
- import { ReloadOptions , VoidFunction } from '@inertiajs/core'
1
+ import { PollOptions , ReloadOptions } from '@inertiajs/core'
2
2
import { router } from '@inertiajs/vue3'
3
3
import { onMounted , onUnmounted } from 'vue'
4
4
5
- export default function usePoll ( interval : number , options : ReloadOptions , startOnMount = true ) : VoidFunction {
5
+ export default function usePoll (
6
+ interval : number ,
7
+ requestOptions : ReloadOptions = { } ,
8
+ options : PollOptions & {
9
+ startOnMount ?: boolean
10
+ } = {
11
+ keepAlive : false ,
12
+ startOnMount : true ,
13
+ } ,
14
+ ) : {
15
+ stop : VoidFunction
16
+ start : VoidFunction
17
+ } {
6
18
let stopFunc : VoidFunction
7
19
8
- let stop = ( ) => {
20
+ options . startOnMount ??= true
21
+
22
+ const stop = ( ) => {
9
23
if ( stopFunc ) {
10
24
stopFunc ( )
11
25
}
12
26
}
13
27
14
- let start = ( ) => {
28
+ const start = ( ) => {
15
29
stop ( )
16
- stopFunc = router . poll ( interval , options )
30
+ stopFunc = router . poll ( interval , requestOptions , options )
17
31
}
18
32
19
33
onMounted ( ( ) => {
20
- if ( startOnMount ) {
34
+ if ( options . startOnMount ) {
21
35
start ( )
22
36
}
23
37
} )
You can’t perform that action at this time.
0 commit comments