Skip to content

Commit 2feb7ce

Browse files
authored
Merge pull request #131 from xinxin93/api
feat(core): add clearData funcion in Logicflow
2 parents c61e363 + 2a5b345 commit 2feb7ce

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

packages/core/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<button onClick="focusOn()">定位到五角星</button>
4646
<button id="undo" onClick="undo()" disabled>上一步</button>
4747
<button id="redo" onClick="redo()" disabled>下一步</button>
48+
<button id="clearData" onClick="clearData()">清空数据</button>
4849
</div>
4950
<div id="app"></div>
5051
<div id="debug"></div>
@@ -103,6 +104,9 @@
103104
window.redo = function redo() {
104105
lf.redo()
105106
}
107+
window.clearData = function clearData() {
108+
lf.clearData()
109+
}
106110
window.consolelog = function consolelog(msg) {
107111
console.log(msg)
108112
}

packages/core/src/LogicFlow.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ export default class LogicFlow {
635635
this.snaplineModel.clearSnapline();
636636
}
637637
}
638+
// 清空数据
639+
clearData() {
640+
this.graphModel.clearData();
641+
}
638642
/**
639643
* 获取边的model
640644
* @param edgeId 边的Id

packages/core/src/model/GraphModel.ts

+6
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,12 @@ class GraphModel {
599599
@action setTheme(style: Style) {
600600
this.theme = updateTheme({ ...this.theme, ...style });
601601
}
602+
// 清空数据
603+
@action
604+
clearData(): void {
605+
this.nodes = [];
606+
this.edges = [];
607+
}
602608
}
603609

604610
export { GraphModel };

0 commit comments

Comments
 (0)