( debouncer: number | 'blur' | Debouncer<TValue, TPathKind>, )
| 39 | } |
| 40 | |
| 41 | function normalizeDebouncer<TValue, TPathKind extends PathKind>( |
| 42 | debouncer: number | 'blur' | Debouncer<TValue, TPathKind>, |
| 43 | ) { |
| 44 | // If it's already a debounce function, return it as-is. |
| 45 | if (typeof debouncer === 'function') { |
| 46 | return debouncer; |
| 47 | } |
| 48 | // If it's 'blur', return a debouncer that never resolves. The field will still be updated when |
| 49 | // the control is blurred. |
| 50 | if (debouncer === 'blur') { |
| 51 | return debounceUntilBlur(); |
| 52 | } |
| 53 | // If it's a non-zero number, return a timer-based debouncer. |
| 54 | if (debouncer > 0) { |
| 55 | return debounceForDuration(debouncer); |
| 56 | } |
| 57 | // Otherwise it's 0, so we return a function that will synchronize the model without delay. |
| 58 | return immediate; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Creates a debouncer that will wait for the given duration before resolving. |
no test coverage detected