From fdeae3d43293e1e24df27ccf129c22377f273c5c Mon Sep 17 00:00:00 2001 From: austaras Date: Mon, 8 Aug 2022 14:41:26 +0800 Subject: [PATCH] fix(plugin): use rxjs throttle --- .../src/menu/left-menu/LeftMenuPlugin.tsx | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx b/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx index 113dec843d..4155307f74 100644 --- a/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx +++ b/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx @@ -1,12 +1,15 @@ -import { BlockDomInfo, HookType } from '@toeverything/framework/virgo'; +import { + BlockDomInfo, + HookType, + BlockDropPlacement, +} from '@toeverything/framework/virgo'; import { StrictMode } from 'react'; import { BasePlugin } from '../../base-plugin'; import { ignoreBlockTypes } from './menu-config'; import { LineInfoSubject, LeftMenuDraggable } from './LeftMenuDraggable'; import { PluginRenderRoot } from '../../utils'; -import { Subject } from 'rxjs'; -import { domToRect, last, Point, throttle } from '@toeverything/utils'; -import { BlockDropPlacement } from '@toeverything/framework/virgo'; +import { Subject, throttleTime } from 'rxjs'; +import { domToRect, last, Point } from '@toeverything/utils'; const DRAG_THROTTLE_DELAY = 150; export class LeftMenuPlugin extends BasePlugin { private _mousedown?: boolean; @@ -58,15 +61,10 @@ export class LeftMenuPlugin extends BasePlugin { this.hooks.get(HookType.ON_ROOTNODE_DROP).subscribe(this._onDrop) ); this.sub.add( - this.hooks.get(HookType.ON_ROOTNODE_DRAG_OVER).subscribe( - throttle( - this._handleRootNodeDragover.bind(this), - DRAG_THROTTLE_DELAY, - { - leading: true, - } - ) - ) + this.hooks + .get(HookType.ON_ROOTNODE_DRAG_OVER) + .pipe(throttleTime(DRAG_THROTTLE_DELAY)) + .subscribe(this._handleRootNodeDragover) ); }