hotfix throttle function args

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent ee5554c890
commit 21e90a0c7d
3 changed files with 4 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "rrweb",
"version": "0.7.20",
"version": "0.7.21",
"description": "record and replay the web",
"scripts": {
"test": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.test.ts",

View File

@@ -53,13 +53,14 @@ export function throttle<T>(
let timeout: number | null = null;
let previous = 0;
// tslint:disable-next-line: only-arrow-functions
return function(args: T) {
return function(arg: T) {
let now = Date.now();
if (!previous && options.leading === false) {
previous = now;
}
let remaining = wait - (now - previous);
let context = this;
let args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
window.clearTimeout(timeout);

2
typings/utils.d.ts vendored
View File

@@ -2,7 +2,7 @@ import { Mirror, throttleOptions, listenerHandler, hookResetter, blockClass } fr
import { INode } from 'rrweb-snapshot';
export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler;
export declare const mirror: Mirror;
export declare function throttle<T>(func: (arg: T) => void, wait: number, options?: throttleOptions): (args: T) => void;
export declare function throttle<T>(func: (arg: T) => void, wait: number, options?: throttleOptions): () => void;
export declare function hookSetter<T>(target: T, key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean): hookResetter;
export declare function getWindowHeight(): number;
export declare function getWindowWidth(): number;