Skip to content

Commit 5eaa4bf

Browse files
committed
fixed up usePoll to use new options
1 parent 07376a3 commit 5eaa4bf

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

packages/vue3/src/usePoll.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
import { ReloadOptions, VoidFunction } from '@inertiajs/core'
1+
import { PollOptions, ReloadOptions } from '@inertiajs/core'
22
import { router } from '@inertiajs/vue3'
33
import { onMounted, onUnmounted } from 'vue'
44

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+
} {
618
let stopFunc: VoidFunction
719

8-
let stop = () => {
20+
options.startOnMount ??= true
21+
22+
const stop = () => {
923
if (stopFunc) {
1024
stopFunc()
1125
}
1226
}
1327

14-
let start = () => {
28+
const start = () => {
1529
stop()
16-
stopFunc = router.poll(interval, options)
30+
stopFunc = router.poll(interval, requestOptions, options)
1731
}
1832

1933
onMounted(() => {
20-
if (startOnMount) {
34+
if (options.startOnMount) {
2135
start()
2236
}
2337
})

0 commit comments

Comments
 (0)