-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Typescriptification of tko.utils - pending compilation issues…
… in rollup
- Loading branch information
Showing
24 changed files
with
932 additions
and
777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
// | ||
// Asynchronous functionality | ||
// --- | ||
import { safeSetTimeout } from './error.js' | ||
import { safeSetTimeout } from './error'; | ||
|
||
export function throttle (callback, timeout) { | ||
var timeoutInstance | ||
return function (...args) { | ||
// tslint:disable-next-line:ban-types | ||
export function throttle(callback: Function, timeout: number) { | ||
let timeoutInstance: number|undefined; | ||
return (...args: any[]) => { | ||
if (!timeoutInstance) { | ||
timeoutInstance = safeSetTimeout(function () { | ||
timeoutInstance = undefined | ||
callback(...args) | ||
}, timeout) | ||
timeoutInstance = safeSetTimeout(() => { | ||
timeoutInstance = undefined; | ||
callback(...args); | ||
}, timeout); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export function debounce (callback, timeout) { | ||
var timeoutInstance | ||
return function (...args) { | ||
clearTimeout(timeoutInstance) | ||
timeoutInstance = safeSetTimeout(() => callback(...args), timeout) | ||
} | ||
// tslint:disable-next-line:ban-types | ||
export function debounce(callback: Function, timeout: number) { | ||
let timeoutInstance: number|undefined; | ||
return (...args: any[]) => { | ||
clearTimeout(timeoutInstance); | ||
timeoutInstance = safeSetTimeout(() => callback(...args), timeout); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.