Skip to content

Commit 1cb45dd

Browse files
wbccbwumail
authored andcommitted
fix(core): refresh the value of model when mouse down(#1370)
1 parent 8368622 commit 1cb45dd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/core/src/util/drag.ts

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class StepDrag {
110110
setStep(step: number) {
111111
this.step = step;
112112
}
113+
setModel(model: IBaseModel) {
114+
this.model = model;
115+
}
113116
handleMouseDown = (e: MouseEvent) => {
114117
if (e.button !== LEFT_MOUSE_BUTTON_CODE) return;
115118
if (this.isStopPropagation) e.stopPropagation();

packages/core/src/view/node/BaseNode.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ export default abstract class BaseNode extends Component<IProps, IState> {
324324
this.startTime = new Date().getTime();
325325
const { editConfigModel } = graphModel;
326326
if (editConfigModel.adjustNodePosition && model.draggable) {
327+
// https://github.com/didi/LogicFlow/issues/1370
328+
// 当使用撤销功能:LogicFlow.undo()时,会重新初始化所有model数据,即LogicFlow.undo()时会新构建一个model对象
329+
// 但是this.stepDrag并不会重新创建
330+
// 导致this.stepDrag持有的model并没有重新赋值,因为之前的做法是构造函数中传入一个model对象
331+
// 在StepDrag.ts中只有handleMouseDown、handleMouseMove、handleMouseUp使用到this.model
332+
// 因此在handleMouseDown()进行setModel重新将this.props.model的值设置进去,刷新this.model.getData()
333+
this.stepDrag && this.stepDrag.setModel(model);
327334
this.stepDrag && this.stepDrag.handleMouseDown(ev);
328335
}
329336
};

0 commit comments

Comments
 (0)