fix(plugin): use rxjs throttle

This commit is contained in:
austaras 2022-08-08 14:41:26 +08:00 committed by Austaras
parent 07e6e9fe98
commit fdeae3d432

View File

@ -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)
);
}