Skip to content

Commit d33bb25

Browse files
committed
Fix debounce issue wclr#188
1 parent f0c3e7e commit d33bb25

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/bin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type DevOptions = {
115115
clear: boolean
116116
cls: boolean
117117
'ignore-watch': string
118+
debounce: string
118119
'all-deps': boolean
119120
'deps-level': string
120121
'compile-timeout': string

src/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,17 @@ export const runDev = (
228228
}
229229
}
230230

231+
let debounceTimeout: ReturnType<typeof setTimeout>
232+
const defaultDebounce: string = (opts.debounce === '') ? '1000' : opts.debounce
233+
const debounceTime: number = parseInt(defaultDebounce, 10) || 0
231234
function restart(file: string, isManualRestart?: boolean) {
235+
clearTimeout(debounceTimeout)
236+
debounceTimeout = setTimeout(() => {
237+
restartAfterDebounce(file, isManualRestart)
238+
}, debounceTime)
239+
}
240+
241+
function restartAfterDebounce(file: string, isManualRestart?: boolean) {
232242
if (file === compiler.tsConfigPath) {
233243
notify('Reinitializing TS compilation', '')
234244
compiler.init()

0 commit comments

Comments
 (0)