Try add configurable threshold for events throttling (#147)

This commit is contained in:
mpstv
2026-04-01 12:00:00 +08:00
committed by yz-yu
parent 9f1f31fb85
commit 84de337040
3 changed files with 7 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ function record(options: recordOptions = {}): listenerHandler | undefined {
inlineStylesheet = true, inlineStylesheet = true,
maskAllInputs = false, maskAllInputs = false,
hooks, hooks,
mousemoveWait = 50
} = options; } = options;
// runtime checks for user options // runtime checks for user options
if (!emit) { if (!emit) {
@@ -181,6 +182,7 @@ function record(options: recordOptions = {}): listenerHandler | undefined {
ignoreClass, ignoreClass,
maskAllInputs, maskAllInputs,
inlineStylesheet, inlineStylesheet,
mousemoveWait
}, },
hooks, hooks,
), ),

View File

@@ -279,7 +279,7 @@ function initMutationObserver(
return observer; return observer;
} }
function initMoveObserver(cb: mousemoveCallBack): listenerHandler { function initMoveObserver(cb: mousemoveCallBack, mousemoveWait: number): listenerHandler {
let positions: mousePosition[] = []; let positions: mousePosition[] = [];
let timeBaseline: number | null; let timeBaseline: number | null;
const wrappedCb = throttle((isTouch: boolean) => { const wrappedCb = throttle((isTouch: boolean) => {
@@ -311,7 +311,7 @@ function initMoveObserver(cb: mousemoveCallBack): listenerHandler {
}); });
wrappedCb(isTouchEvent(evt)); wrappedCb(isTouchEvent(evt));
}, },
50, mousemoveWait,
{ {
trailing: false, trailing: false,
}, },
@@ -570,7 +570,7 @@ export default function initObservers(
o.inlineStylesheet, o.inlineStylesheet,
o.maskAllInputs, o.maskAllInputs,
); );
const mousemoveHandler = initMoveObserver(o.mousemoveCb); const mousemoveHandler = initMoveObserver(o.mousemoveCb, o.mousemoveWait);
const mouseInteractionHandler = initMouseInteractionObserver( const mouseInteractionHandler = initMouseInteractionObserver(
o.mouseInteractionCb, o.mouseInteractionCb,
o.blockClass, o.blockClass,

View File

@@ -120,6 +120,7 @@ export type recordOptions = {
maskAllInputs?: boolean; maskAllInputs?: boolean;
inlineStylesheet?: boolean; inlineStylesheet?: boolean;
hooks?: hooksParam; hooks?: hooksParam;
mousemoveWait?: number;
}; };
export type observerParam = { export type observerParam = {
@@ -133,6 +134,7 @@ export type observerParam = {
ignoreClass: string; ignoreClass: string;
maskAllInputs: boolean; maskAllInputs: boolean;
inlineStylesheet: boolean; inlineStylesheet: boolean;
mousemoveWait: number;
}; };
export type hooksParam = { export type hooksParam = {