Skip to content

Commit

Permalink
feat(useTimeoutFn): 将 watch 设置为同步执行
Browse files Browse the repository at this point in the history
  • Loading branch information
lmhcoding committed Sep 29, 2020
1 parent a5aa835 commit 87a5635
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/useTimeoutFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ export function useTimeoutFn(fn: Function, delay = 1000, immediate = true, clear
const { start, ready, stop } = useTimeout(delay, immediate)
let stopEffect: WatchStopHandle | undefined
const startEffect = () => {
stopEffect = watch(ready, (hasReady) => {
hasReady && fn()
})
stopEffect = watch(
ready,
(hasReady) => {
hasReady && fn()
},
{ flush: 'sync' }
)
}
const _stop = () => {
clearEffectWhenStop && stopEffect!()
Expand Down

0 comments on commit 87a5635

Please sign in to comment.