/** * Copyright (c) 2021 GraphQL Contributors. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ /** * Provided a duration and a function, returns a new function which is called * `duration` milliseconds after the last call. */ export default function debounce any>(duration: number, fn: F) { let timeout: number | null; return function (this: any, ...args: Parameters) { if (timeout) { window.clearTimeout(timeout); } timeout = window.setTimeout(() => { timeout = null; fn.apply(this, args); }, duration); }; }