File tree 2 files changed +19
-4
lines changed
packages/shared/useTimeout
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { describe , expect , it } from 'vitest'
2
+ import { ref } from 'vue-demi'
2
3
import { useTimeout } from '.'
3
4
4
5
describe ( 'useTimeout' , ( ) => {
@@ -13,4 +14,18 @@ describe('useTimeout', () => {
13
14
expect ( ready . value ) . toEqual ( false )
14
15
setTimeout ( ( ) => expect ( ready . value ) . toEqual ( true ) , 10 )
15
16
} )
17
+
18
+ it ( 'works with ref target' , ( ) => {
19
+ const interval = ref ( 10 )
20
+ const ready = useTimeout ( interval )
21
+ expect ( ready . value ) . toEqual ( false )
22
+ setTimeout ( ( ) => expect ( ready . value ) . toEqual ( true ) , 10 )
23
+ } )
24
+
25
+ it ( 'works with controls and ref target' , ( ) => {
26
+ const interval = ref ( 10 )
27
+ const { ready } = useTimeout ( interval , { controls : true } )
28
+ expect ( ready . value ) . toEqual ( false )
29
+ setTimeout ( ( ) => expect ( ready . value ) . toEqual ( true ) , 10 )
30
+ } )
16
31
} )
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type { ComputedRef } from 'vue-demi'
2
2
import { computed } from 'vue-demi'
3
3
import type { UseTimeoutFnOptions } from '../useTimeoutFn'
4
4
import { useTimeoutFn } from '../useTimeoutFn'
5
- import type { Fn , Stoppable } from '../utils'
5
+ import type { Fn , MaybeRefOrGetter , Stoppable } from '../utils'
6
6
import { noop } from '../utils'
7
7
8
8
export interface UseTimeoutOptions < Controls extends boolean > extends UseTimeoutFnOptions {
@@ -25,9 +25,9 @@ export interface UseTimeoutOptions<Controls extends boolean> extends UseTimeoutF
25
25
* @param interval
26
26
* @param options
27
27
*/
28
- export function useTimeout ( interval ?: number , options ?: UseTimeoutOptions < false > ) : ComputedRef < boolean >
29
- export function useTimeout ( interval : number , options : UseTimeoutOptions < true > ) : { ready : ComputedRef < boolean > } & Stoppable
30
- export function useTimeout ( interval = 1000 , options : UseTimeoutOptions < boolean > = { } ) {
28
+ export function useTimeout ( interval ?: MaybeRefOrGetter < number > , options ?: UseTimeoutOptions < false > ) : ComputedRef < boolean >
29
+ export function useTimeout ( interval : MaybeRefOrGetter < number > , options : UseTimeoutOptions < true > ) : { ready : ComputedRef < boolean > } & Stoppable
30
+ export function useTimeout ( interval : MaybeRefOrGetter < number > = 1000 , options : UseTimeoutOptions < boolean > = { } ) {
31
31
const {
32
32
controls : exposeControls = false ,
33
33
callback,
You can’t perform that action at this time.
0 commit comments