fix: 修复throttle引起的问题

This commit is contained in:
parisma 2022-03-31 15:11:38 +08:00 committed by jia000
parent feb9ac9a81
commit 148d4547b0

View File

@ -85,6 +85,13 @@ export default class StageMask extends Rule {
private mode: Mode = Mode.ABSOLUTE; private mode: Mode = Mode.ABSOLUTE;
private pageResizeObserver: ResizeObserver | null = null; private pageResizeObserver: ResizeObserver | null = null;
private wrapperResizeObserver: ResizeObserver | null = null; private wrapperResizeObserver: ResizeObserver | null = null;
/**
*
* @param event
*/
private highlightHandler = throttle((event: MouseEvent): void => {
this.emit('highlight', event);
}, throttleTime);
constructor(config: StageMaskConfig) { constructor(config: StageMaskConfig) {
const wrapper = createWrapper(); const wrapper = createWrapper();
@ -96,7 +103,7 @@ export default class StageMask extends Rule {
this.content.addEventListener('mousedown', this.mouseDownHandler); this.content.addEventListener('mousedown', this.mouseDownHandler);
this.wrapper.appendChild(this.content); this.wrapper.appendChild(this.content);
this.content.addEventListener('wheel', this.mouseWheelHandler); this.content.addEventListener('wheel', this.mouseWheelHandler);
this.content.addEventListener('mousemove', throttle(this.highlightHandler, throttleTime)); this.content.addEventListener('mousemove', this.highlightHandler);
} }
public setMode(mode: Mode) { public setMode(mode: Mode) {
@ -228,7 +235,7 @@ export default class StageMask extends Rule {
private mouseUpHandler = (): void => { private mouseUpHandler = (): void => {
globalThis.document.removeEventListener('mouseup', this.mouseUpHandler); globalThis.document.removeEventListener('mouseup', this.mouseUpHandler);
this.content.addEventListener('mousemove', throttle(this.highlightHandler, throttleTime)); this.content.addEventListener('mousemove', this.highlightHandler);
this.emit('select'); this.emit('select');
}; };
@ -271,12 +278,4 @@ export default class StageMask extends Rule {
this.emit('scroll', event); this.emit('scroll', event);
}; };
/**
*
* @param event
*/
private highlightHandler = (event: MouseEvent): void => {
this.emit('highlight', event);
};
} }