Skip to content

Commit 0b19734

Browse files
committed
* dnd: fix duplicated cleanup and onChange old-state in vanilla components
- Draggable: guard `_clean()` against repeated invocation by tracking `_needClean` state, avoiding redundant class/attribute resets - Moveable: pass the previous state (not the new one) as `oldState` to `onChange`, and drop the unused `_raf` field
1 parent 65f7115 commit 0b19734

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

lib/dnd/src/vanilla/draggable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Draggable extends Component<DraggableOptions> {
3030
protected _$targets?: Cash;
3131

3232
/** 标记是否需要执行清理。Whether cleanup is pending. */
33-
protected declare _needClean: boolean;
33+
protected _needClean = true;
3434

3535
/** 拖拽事件监听容器的 Cash 包装。Cash-wrapped drag event container. */
3636
protected declare _$dragContainer: Cash;
@@ -303,7 +303,10 @@ export class Draggable extends Component<DraggableOptions> {
303303
* Clean up drag/drop state: remove all drag-related CSS classes and droppable attributes, reset internal state.
304304
*/
305305
protected _clean() {
306-
this._needClean = true;
306+
if (this._needClean === false) {
307+
return;
308+
}
309+
this._needClean = false;
307310

308311
const {draggingClass, droppableClass, droppingClass, hasDraggingClass} = this.options;
309312
if (hasDraggingClass) {

lib/dnd/src/vanilla/moveable.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export class Moveable extends Component<MoveableOptions> {
2626
/** 当前移动状态,未在移动时为 undefined。The current move state; undefined when idle. */
2727
protected _state?: MoveableState;
2828

29-
/** requestAnimationFrame 标识符。requestAnimationFrame handle. */
30-
protected declare _raf: number;
31-
3229
/** 获取当前移动状态。Get the current move state. */
3330
get state() {
3431
return this._state;
@@ -193,14 +190,15 @@ export class Moveable extends Component<MoveableOptions> {
193190
}
194191

195192
const {deltaX, deltaY, event} = this._state!;
193+
const oldState = this._state!;
196194
this._state = {
197-
...this._state!,
195+
...oldState,
198196
deltaX: deltaX + targetDx,
199197
deltaY: deltaY + targetDy,
200198
};
201199

202200
this.options.onMove?.call(this, event, this._state);
203-
this.options.onChange?.call(this, this._state, this._state, event);
201+
this.options.onChange?.call(this, this._state, oldState, event);
204202
}
205203

206204
/**

0 commit comments

Comments
 (0)