]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add typings for throttled and debounce (#8689) v3.0.0-rc.2
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 21 Mar 2021 15:50:28 +0000 (17:50 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Mar 2021 15:50:28 +0000 (11:50 -0400)
* Add typings for throttled and debounce
* Review feedback
* args for fn too
* one more

types/helpers/helpers.extras.d.ts

index 5979b86b4fe89903ec001710d850a1303fc505b1..d3ddc784e62e36b9c07dae4b0bcfc3fb95acf521 100644 (file)
@@ -4,3 +4,20 @@ export function fontString(pixelSize: number, fontStyle: string, fontFamily: str
  * Request animation polyfill
  */
 export function requestAnimFrame(cb: () => void): void;
+
+/**
+ * Throttles calling `fn` once per animation frame
+ * Latest argments are used on the actual call
+ * @param {function} fn
+ * @param {*} thisArg
+ * @param {function} [updateFn]
+ */
+export function throttled(fn: (...args: any[]) => void, thisArg: any, updateFn?: (...args: any[]) => any[]): (...args: any[]) => void;
+
+/**
+ * Debounces calling `fn` for `delay` ms
+ * @param {function} fn - Function to call. No arguments are passed.
+ * @param {number} delay - Delay in ms. 0 = immediate invocation.
+ * @returns {function}
+ */
+export function debounce(fn: () => void, delay: number): () => number;