UNPKG

@devexperts/dxcharts-lite

Version:
27 lines (26 loc) 964 B
/* * Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { uuid } from '../uuid.utils'; import { animationFrameThrottled } from './request-animation-frame-throttle.utils'; export function throttle(shouldPreventDefault, listener, isSuppressed) { let last; const animFrameId = uuid(); function fireLastEvent() { const event = last; last = void 0; if (event) { listener(event); } } return function (event) { const hasEvent = last; last = event; shouldPreventDefault && event.preventDefault(); if (!hasEvent && !(typeof isSuppressed === 'function' && isSuppressed())) { animationFrameThrottled(animFrameId, fireLastEvent); } }; }