update
This commit is contained in:
21
ts/dettle/throttle.ts
Normal file
21
ts/dettle/throttle.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
/* IMPORT */
|
||||
|
||||
import debounce from './debounce.js';
|
||||
import type {FN, Throttled} from './types.js';
|
||||
|
||||
/* MAIN */
|
||||
|
||||
const throttle = <Args extends unknown[]> ( fn: FN<Args, unknown>, wait: number = 1, options?: { leading?: boolean, trailing?: boolean } ): Throttled<Args> => {
|
||||
|
||||
return debounce ( fn, wait, {
|
||||
maxWait: wait,
|
||||
leading: options?.leading ?? true,
|
||||
trailing: options?.trailing ?? true
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/* EXPORT */
|
||||
|
||||
export default throttle;
|
||||
Reference in New Issue
Block a user