Skip to content

Commit aa549e3

Browse files
committed
refactor: refactor
1 parent 6b19a31 commit aa549e3

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/js/app.js

-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { initWebservices } from "./utils/globals";
1111
import {
1212
selectedElements,
1313
copiedElements,
14-
deletedElements,
1514
currentElements,
1615
currentDataElements
1716
} from "./store/modules/utils";
@@ -65,9 +64,6 @@ export let app;
6564
copiedElements() {
6665
return copiedElements(this.elementsData);
6766
},
68-
deletedElements() {
69-
return deletedElements(this.elementsData);
70-
},
7167
movedElements() {
7268
return this.currentElements.map(({ boxId, position }) => {
7369
return { boxId, position };

src/js/store/plugins/ElementPlugin.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { addLinkFromLink, addElement } from "../../elements/addElement";
2-
import { deleteLinkById } from "../../elements/deleteElement";
2+
import {
3+
deleteLinkById,
4+
deleteElementByBoxId
5+
} from "../../elements/deleteElement";
36

47
const ElementPlugin = store => {
58
store.subscribe(({ type, payload }) => {
@@ -15,6 +18,12 @@ const ElementPlugin = store => {
1518
}
1619
break;
1720
}
21+
case "Interface/DELETE_ELEMENTS": {
22+
for (const el of payload.elements) {
23+
deleteElementByBoxId(el.boxId);
24+
}
25+
break;
26+
}
1827
case "Interface/ADD_LINK": {
1928
addLinkFromLink(payload.link);
2029
break;

src/js/store/plugins/UndoRedoHistory.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ class UndoRedoHistory {
7979
}
8080
}
8181

82+
// @TODO keep track of actual transaction and optimize update loops
8283
reportChanges(prevState, nextState) {
8384
const { elements: prevElements, links: prevLinks } = prevState.Interface;
8485
const { elements: nextElements, links: nextLinks } = nextState.Interface;
8586

87+
// watch elements and add them if they dont exist in the graph
8688
for (const el of Graph.getNewElements(nextElements)) {
8789
addElement(el);
8890
}
@@ -95,9 +97,6 @@ class UndoRedoHistory {
9597

9698
/**
9799
* watch links
98-
* on direct operation, nothing changes (mechanic operation)
99-
* on start, add parsed links
100-
* apply changes on undo-redo
101100
*/
102101
for (const l of Graph.getNewLinks(nextLinks)) {
103102
addLinkFromLink(l);
@@ -114,25 +113,18 @@ class UndoRedoHistory {
114113

115114
/**
116115
* watch parameters of elements
117-
* on direct changes, nothing changes (mechanic operation)
118-
* only apply changes on undo-redo
119116
*/
120-
// check params diff
121-
const paramsDifference = findDifferenceBy(
117+
for (const box of findDifferenceBy(
122118
nextElements,
123119
prevElements,
124120
"defaultParams"
125-
);
126-
127-
for (const box of paramsDifference) {
121+
)) {
128122
setSelectValueInElement(box);
129123
setInputValueInElement(box);
130124
}
131125

132126
/**
133127
* watch moved elements
134-
* on direct move operation, nothing changes (mechanic operation)
135-
* only apply changes on undo-redo
136128
*/
137129
const moveDifference = findDifferenceBy(
138130
nextElements,
@@ -142,9 +134,7 @@ class UndoRedoHistory {
142134
moveElements(moveDifference);
143135

144136
/**
145-
* watch moved elements
146-
* on direct resize operation, nothing changes (mechanic operation)
147-
* only apply changes on undo-redo
137+
* watch resized elements
148138
*/
149139
const resizeDifference = findDifferenceBy(
150140
nextElements,

src/js/utils/utils.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,15 @@ export const findDifferenceBy = (a, b, param) => {
253253

254254
/**
255255
* compare arr and newArr and return deleted elements (which do not exist in newArr)
256+
* or the ones newly marked as deleted
256257
* @param {array} arr
257258
* @param {array} newArr
258259
*/
259260
export const getDeletedElements = (arr, newArr) => {
260-
return arr.filter(el => !newArr.find(v => v.boxId == el.boxId));
261+
return arr.filter(el => {
262+
const newEl = newArr.find(v => v.boxId == el.boxId);
263+
return !newEl || newEl.deleted;
264+
});
261265
};
262266

263267
/**

0 commit comments

Comments
 (0)