diff --git a/packages/vscode-extension/src/common/utils.ts b/packages/vscode-extension/src/common/utils.ts index 56f325206..b23f38234 100644 --- a/packages/vscode-extension/src/common/utils.ts +++ b/packages/vscode-extension/src/common/utils.ts @@ -27,25 +27,3 @@ export function throttle any>( recentArgs = args; } as T; } - -export function throttleWithTrailing any>( - func: T, - limitMs: number -): (...args: Parameters) => void { - let timeout: NodeJS.Timeout | null = null; - let recentArgs: any; - - return function (...args: Parameters) { - recentArgs = args; - - if (!timeout) { - timeout = setTimeout(() => { - timeout = null; - if (recentArgs) { - func(...recentArgs); - recentArgs = null; - } - }, limitMs); - } - }; -} diff --git a/packages/vscode-extension/src/webview/views/DeviceLocationView.tsx b/packages/vscode-extension/src/webview/views/DeviceLocationView.tsx index de0de2a45..41be8ed1a 100644 --- a/packages/vscode-extension/src/webview/views/DeviceLocationView.tsx +++ b/packages/vscode-extension/src/webview/views/DeviceLocationView.tsx @@ -4,8 +4,8 @@ import "./DeviceLocationView.css"; import Label from "../components/shared/Label"; import * as Switch from "@radix-ui/react-switch"; import CoordinateParser from "coordinate-parser"; -import { throttleWithTrailing } from "../../common/utils"; import Tooltip from "../components/shared/Tooltip"; +import { throttle } from "../../common/utils"; const CoordinateInfo = () => { return ( @@ -43,10 +43,7 @@ export function DeviceLocationView() { const { project, deviceSettings } = useProject(); const inputRef = useRef(null); - const updateProjectSettingWithThrottle = throttleWithTrailing( - project.updateDeviceSettings, - THROTTLE_LIMIT - ); + const updateProjectSettingWithThrottle = throttle(project.updateDeviceSettings, THROTTLE_LIMIT); const [isCoordinateValid, setIsCoordinateValid] = useState(true);