Skip to content

Commit

Permalink
fix: fix repeated connect calls during drag and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
hcg1023 committed Mar 24, 2022
1 parent f2a7d22 commit 07b2e02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 12 additions & 1 deletion lib/hooks/connectDragRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ export function connectDragRef<ConnectorNode extends Connector, Options>(
) {
const scopedOptions = options
let prevWatchStop: ReturnType<typeof watch>
let prevNode: ConnectableElement | undefined
let prevOptions: Options | undefined
return (elementOrNode: ConnectableElement, options?: Options) => {
function callConnect() {
const nowOptions = scopedOptions || options
// Avoid repeatedly triggering the connect function when vue patch calls setRef due to data changes in the drag process
if (!isRef(elementOrNode)) {
if (prevNode === elementOrNode && prevOptions === nowOptions) {
return elementOrNode!
}
prevNode = elementOrNode
prevOptions = nowOptions
}
return fn(
elementOrNode,
// Because of the special nature of vue, when it calls setRef, it will pass in two parameters. Therefore, when we pass connect as a setRef function, we may receive a non-ideal options. For this reason, we assume that when there are options in the spec, The options passed in by Connect are no longer adopted to ensure that the options of spec always take precedence over the options of connect
scopedOptions || options
nowOptions
)
}

Expand Down
4 changes: 0 additions & 4 deletions lib/internals/TargetConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { MaybeRef } from '../types/utils'
export class TargetConnector implements Connector {
public hooks = wrapConnectorHooks({
dropTarget: (node: MaybeRef<any>, options: DropTargetOptions) => {
// Avoid dragging and dropping while Vue keeps calling connect Function
// if (this.dropTargetNode === node && node) {
// return
// }
this.clearDropTarget()
this.dropTargetOptions = options
if (isRef(node)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"lint-staged": {
"*.{js,js,ts,tsx,vue}": [
"prettier --write",
"vitest related"
"vitest related --run"
],
"*.{less,css}": [
"stylelint --fix"
Expand Down

0 comments on commit 07b2e02

Please sign in to comment.